tbeu / matio

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

link errors building master on OpenBSD due to `-Wl,--no-undefined` #187

Closed seanm closed 8 months ago

seanm commented 2 years ago

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...

tbeu commented 2 years ago

Thanks for reporting. Does it work when building by GNU autotools?

seanm commented 2 years ago

Seems like yes, and I'm able to run the tests (many fail, but whatever).

tbeu commented 2 years ago

I added FreeBSD OS by Cirrus CI and cannot reproduce with current master: https://cirrus-ci.com/build/5653130858725376

tbeu commented 2 years ago

OK, closing then.

seanm commented 2 years ago

Did you fix it? Or is one expected to use autotools and not CMake?

tbeu commented 2 years ago

No, cannot fix as I do not have a patch if I cannot repoduce.

seanm commented 2 years ago

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...

tbeu commented 2 years ago

PR is welcome.

seanm commented 9 months ago

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...

tbeu commented 8 months ago

Can you please give f058e5d a try?

seanm commented 8 months ago

That worked! Thanks!

tbeu commented 8 months ago

Thanks for confirmation!