CMake generates incorrect linker command for GCC in MacOSX
I'm compiling a project in MacOSX using both GCC 9.1 and LLVM 8.0 (both obtained via Brew). My CMakeList is exporting only API symbols by defining:
# Mark all exported symbols as hidden by default
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
and the code is explicitly making some symbols visible by setting __attribute__ ((visibility("default")))
on the chosen methods. However, this setting is preventing GCC 9 from working, I get this error: ld: unknown option: --exclude-libs
My compilation commands looks like:
/usr/local/Cellar/gcc/9.1.0/bin/g++-9 ... -Wl,--exclude-libs,ALL ...
but indeed, ld
in MacOSX doesn't support "--exclude-libs"
as it does in Linux.
Ergo, IMHO, CMake shouldn't generate that option for GCC in the former. It doesn't happen if I use LLVM, i.e., this fails:
# MacOSX compiler settings
SET(CMAKE_CXX_COMPILER "/usr/local/Cellar/gcc/9.1.0/bin/g++-9")
while this succeeds:
# MacOSX compiler settings
SET(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/8.0.0_1/bin/clang++")
Versions: CMake 3.15.1
, MacOSX 10.14.6
, GCC 9.1
, LLVM 8.0