Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build this on macOS #45

Closed
abhi18av opened this issue Oct 11, 2018 · 9 comments
Closed

Unable to build this on macOS #45

abhi18av opened this issue Oct 11, 2018 · 9 comments
Assignees
Milestone

Comments

@abhi18av
Copy link

@gchatelet , I ran into an error while running this command on the macOS system


Abhinavs-MacBook-Pro:cpu_features eklavya$ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -H. -Bcmake_build
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/eklavya/projects/code/c-shared-lab/cpu_features/cmake_build


Abhinavs-MacBook-Pro:cpu_features eklavya$ cd cmake_build/


Abhinavs-MacBook-Pro:cmake_build eklavya$ make 
Scanning dependencies of target cpu_features
[  6%] Building C object CMakeFiles/cpu_features.dir/src/linux_features_aggregator.c.o
[ 13%] Building C object CMakeFiles/cpu_features.dir/src/cpuid_x86_clang_gcc.c.o
[ 20%] Building C object CMakeFiles/cpu_features.dir/src/cpuid_x86_msvc.c.o
[ 26%] Building C object CMakeFiles/cpu_features.dir/src/cpuinfo_aarch64.c.o
[ 33%] Building C object CMakeFiles/cpu_features.dir/src/cpuinfo_arm.c.o
[ 40%] Building C object CMakeFiles/cpu_features.dir/src/cpuinfo_mips.c.o
[ 46%] Building C object CMakeFiles/cpu_features.dir/src/cpuinfo_ppc.c.o
[ 53%] Building C object CMakeFiles/cpu_features.dir/src/cpuinfo_x86.c.o
[ 60%] Building C object CMakeFiles/cpu_features.dir/src/filesystem.c.o
[ 66%] Building C object CMakeFiles/cpu_features.dir/src/hwcaps.c.o
[ 73%] Building C object CMakeFiles/cpu_features.dir/src/stack_line_reader.c.o
[ 80%] Building C object CMakeFiles/cpu_features.dir/src/string_view.c.o
[ 86%] Linking C shared library libcpu_features.dylib
Undefined symbols for architecture x86_64:
  "_CpuFeatures_GetPlatformType", referenced from:
      _GetPPCPlatformStrings in cpuinfo_ppc.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libcpu_features.dylib] Error 1
make[1]: *** [CMakeFiles/cpu_features.dir/all] Error 2
make: *** [all] Error 2
@Mizux
Copy link
Collaborator

Mizux commented Oct 11, 2018

here

#if defined(__linux__)
#define CPU_FEATURES_OS_LINUX_OR_ANDROID
#endif
#if defined(__ANDROID__)
#define CPU_FEATURES_OS_ANDROID
#endif
#if (defined(_WIN64) || defined(_WIN32))
#define CPU_FEATURES_OS_WINDOWS
#endif

I would add

 #if defined(__APPLE__) 
 #define CPU_FEATURES_OS_APPLE 
 #endif 

or

 #if defined(__OSX__) 
 #define CPU_FEATURES_OS_OSX
 #endif 

then adapt accordingly

#if defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) && \
!defined(HWCAPS_ANDROID_MIPS_OR_ARM)
#define HWCAPS_REGULAR_LINUX
#endif
#if defined(HWCAPS_ANDROID_MIPS_OR_ARM) || defined(HWCAPS_REGULAR_LINUX)
#define HWCAPS_SUPPORTED
#endif

@Mizux
Copy link
Collaborator

Mizux commented Oct 11, 2018

FYI on my macbook pro

%clang -dM -E - </dev/null | grep -i "\(mach\|apple\)"
#define __APPLE_CC__ 6000
#define __APPLE__ 1
#define __MACH__ 1
#define __VERSION__ "4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)"
#define __apple_build_version__ 9020039

@gchatelet
Copy link
Collaborator

According to https://sourceforge.net/p/predef/wiki/OperatingSystems/ we should test for __APPLE__ && __MACH__

@Mizux
Copy link
Collaborator

Mizux commented Oct 11, 2018

@sl1200mk2
Copy link

Hi,
so how to get cpu_features to compile on macOS?
I'm facing the same issue as Mizux...

thank you
++

@Mizux
Copy link
Collaborator

Mizux commented Jan 4, 2019

@abhi18av @sl1200mk2
It seems you are using the /Library/Developer/CommandLineTools/usr/bin/cc which is the wrong active developer directory.
You should use instead this one /Applications/Xcode-9.4.1.app/Contents/Developer/usr/bin/gcc.

To change please run xcode-select --install

@gchatelet Travis-CI Mac workers seems "correctly" configured in this regard...
see: https://travis-ci.org/google/cpu_features/jobs/427262835#L140-L144

@Mizux
Copy link
Collaborator

Mizux commented Jan 4, 2019

@gchatelet I still think there is a bug since cpuinfo_ppc.c call CpuFeatures_GetPlatformType();

PPCPlatformStrings GetPPCPlatformStrings(void) {
PPCPlatformStrings strings = kEmptyPPCPlatformStrings;
FillProcCpuInfoData(&strings);
strings.type = CpuFeatures_GetPlatformType();
return strings;
}

unconditionally declared here:

PlatformType CpuFeatures_GetPlatformType(void);

But CpuFeatures_GetPlatformType() is undefined for !HWCAPS_SUPPORTED (cf block L177-L187)

cpu_features/src/hwcaps.c

Lines 164 to 187 in 7863534

PlatformType CpuFeatures_GetPlatformType(void) {
PlatformType type = kEmptyPlatformType;
char *platform = (char *)GetHardwareCapabilitiesFor(AT_PLATFORM);
char *base_platform = (char *)GetHardwareCapabilitiesFor(AT_BASE_PLATFORM);
if (platform != NULL)
CpuFeatures_StringView_CopyString(str(platform), type.platform,
sizeof(type.platform));
if (base_platform != NULL)
CpuFeatures_StringView_CopyString(str(base_platform), type.base_platform,
sizeof(type.base_platform));
return type;
}
#else // (defined(HWCAPS_SUPPORTED)
////////////////////////////////////////////////////////////////////////////////
// Implementation of GetHardwareCapabilities for unsupported platforms.
////////////////////////////////////////////////////////////////////////////////
const HardwareCapabilities kEmptyHardwareCapabilities;
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
return kEmptyHardwareCapabilities;
}
#endif

I think, we should add this to the #else (i.e. L178)

PlatformType kEmptyPlatformType;
PlatformType CpuFeatures_GetPlatformType(void) {
  return kEmptyPlatformType;
}

ps: I think kEmptyPlatformType should be const like kEmptyHardwareCapabilities

PlatformType kEmptyPlatformType;

const HardwareCapabilities kEmptyHardwareCapabilities;

@jculpon
Copy link

jculpon commented Jan 4, 2019

Not @google but I'd like to confirm that a clean CMake on macOS 10.14.2 with a GNU-based toolchain is building successfully, but I have not been able to get tests passing with llvm this morning. This may be unrelated to the issues that @gchatelet / @Mizux are having.

@gchatelet
Copy link
Collaborator

@Mizux the build is now fixed. I'm closing the issue.

@gchatelet gchatelet added this to the v0.3.0 milestone Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants