I am able to get the SHTOOLS C wrapper functions to compile on macOS, and to run the test suite. However, I need to manually alter the LIB string in examples/cpp/Makefile in order to find the gfortran library. This is hindering me to find a common solution so that the tests can be run in github actions and travis on both the macOS and linux platforms.
When using g++-10 (installed via homebrew), I need to manually add the search path -L /usr/local/Cellar/gcc/10.2.0/lib/gcc/10. This is strange to me, because if I force verbose output when linking, the output says explicitly that this path is in the linker's search path. If I don't add this search path manually, I get errors like this:
Library search paths:
/Users/lunokhod/SphericalHarmonics/shtools-git/lib
/usr/local/lib
/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0
/usr/local/Cellar/gcc/10.2.0/lib/gcc/10
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/lib
Framework search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/
Undefined symbols for architecture x86_64:
"__ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv", referenced from:
_main in test.o
If I use g++-9, I get slightly different, but very similar errors, like this:
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const", referenced from:
_main in test.o
In contrast, if I try to use Apple's clang, g++ or gcc (located in /usr/bin), I simply get an error that it can't find the gfortran library:
clang -v -o test test.o -L /Users/lunokhod/SphericalHarmonics/shtools-git/lib -lSHTOOLS -lgfortran -ldl -L/usr/local/lib -lfftw3 -lm -llapack -lblas
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 10.15.0 10.15.6 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o test -L/Users/lunokhod/SphericalHarmonics/shtools-git/lib -L/usr/local/lib -L/usr/local/lib test.o -lSHTOOLS -lgfortran -ldl -lfftw3 -lm -llapack -lblas -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.osx.a
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It is possible that there is something wrong with the homebrew g++ compiler, and I have opened a discussion here.
I am able to get the SHTOOLS C wrapper functions to compile on macOS, and to run the test suite. However, I need to manually alter the
LIBstring inexamples/cpp/Makefilein order to find thegfortranlibrary. This is hindering me to find a common solution so that the tests can be run in github actions and travis on both the macOS and linux platforms.When using
g++-10(installed via homebrew), I need to manually add the search path-L /usr/local/Cellar/gcc/10.2.0/lib/gcc/10. This is strange to me, because if I force verbose output when linking, the output says explicitly that this path is in the linker's search path. If I don't add this search path manually, I get errors like this:If I use
g++-9, I get slightly different, but very similar errors, like this:In contrast, if I try to use Apple's
clang,g++orgcc(located in /usr/bin), I simply get an error that it can't find the gfortran library:It is possible that there is something wrong with the homebrew g++ compiler, and I have opened a discussion here.