tbeu / matio

MATLAB MAT File I/O Library
https://matio.sourceforge.io
BSD 2-Clause "Simplified" License
330 stars 97 forks source link

macOS cmake build fails with `ld: unknown option: --no-undefined` with dynamic libs #172

Closed seanm closed 3 years ago

seanm commented 3 years ago
mkdir matio-bin
cd matio-bin
cmake -DMATIO_MAT73=OFF -DMATIO_WITH_HDF5=OFF ../matio
make

results in:

[ 77%] Linking C shared library libmatio.dylib
ld: unknown option: --no-undefined
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libmatio.11.0.3.dylib] Error 1
make[1]: *** [CMakeFiles/matio.dir/all] Error 2
make: *** [all] Error 2

No such problem when using MATIO_SHARED=OFF.

This is with Xcode 11.3.1 on macOS 10.14.

MaartenBent commented 3 years ago

Looks like LLD (LLVM Linker) on macOS (maybe on all platforms) does not support these options. Suitable replacements seem: -Wl,-undefined,error -Wl,-exported_symbols_list,${PROJECT_SOURCE_DIR}/src/matio.sym

The second one does cause a new problem, it expects all definitions in matio.sym to start with an _. GNU linker seems to handle this without problem, so I think it is fine to add them. Otherwise a second .sym file could be used.

I'll create a PR to fix this in the CMake build system.