matio
matio copied to clipboard
link errors building master on OpenBSD due to `-Wl,--no-undefined`
Using cmake on OpenBSD 7.0. make VERBOSE=1
gives:
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/matio.dir/link.txt --verbose=1
/usr/bin/cc -fPIC -Wl,--no-undefined -Wl,--retain-symbols-file,/home/builder/external/matio-bin/src/matio.sym -shared -Wl,-soname,libmatio.so.11 -o libmatio.so.11.0.3 CMakeFiles/matio.dir/src/endian.c.o CMakeFiles/matio.dir/src/mat.c.o CMakeFiles/matio.dir/src/io.c.o CMakeFiles/matio.dir/src/inflate.c.o CMakeFiles/matio.dir/src/mat73.c.o CMakeFiles/matio.dir/src/matvar_cell.c.o CMakeFiles/matio.dir/src/matvar_struct.c.o CMakeFiles/matio.dir/src/mat4.c.o CMakeFiles/matio.dir/src/mat5.c.o CMakeFiles/matio.dir/src/snprintf.c.o CMakeFiles/matio.dir/src/read_data.c.o -lm /usr/lib/libz.so.6.0 -Wl,-rpath-link,/usr/X11R6/lib:/usr/local/lib
ld: error: undefined symbol: malloc
Running that line manually without the -Wl,--no-undefined
results in a successful linking.
I'm not familiar with what that is, or why it's there...
Thanks for reporting. Does it work when building by GNU autotools?
Seems like yes, and I'm able to run the tests (many fail, but whatever).
I added FreeBSD OS by Cirrus CI and cannot reproduce with current master: https://cirrus-ci.com/build/5653130858725376
OK, closing then.
Did you fix it? Or is one expected to use autotools and not CMake?
No, cannot fix as I do not have a patch if I cannot repoduce.
Looks like there is no OpenBSD option with Cirrus CI? I reproed in a VM with a very vanilla OpenBSD installation. That's a fair bit of work of course, which I'm not expecting you to do...
PR is welcome.
I'm also able to solve the link error explicitly adding -lc
, to link against libc, which contains malloc.
The OpenBSD docs say "it is not necessary to supply the loader flag -lc", so that's a bit surprising, but maybe that general statement does not apply when --no-undefined
is also supplied.
In any case, adding -lc
explicitly should be harmless, and seems a good way to fix this. But I'm not sure where's the best place to add it...
Can you please give f058e5d a try?
That worked! Thanks!
Thanks for confirmation!