matio icon indicating copy to clipboard operation
matio copied to clipboard

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

Open seanm opened this issue 2 years ago • 8 comments

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

seanm avatar Mar 18 '22 17:03 seanm

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

tbeu avatar Mar 18 '22 19:03 tbeu

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

seanm avatar Mar 18 '22 22:03 seanm

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

tbeu avatar Mar 19 '22 09:03 tbeu

OK, closing then.

tbeu avatar Apr 08 '22 14:04 tbeu

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

seanm avatar Apr 08 '22 14:04 seanm

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

tbeu avatar Apr 08 '22 14:04 tbeu

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

seanm avatar Apr 08 '22 15:04 seanm

PR is welcome.

tbeu avatar Apr 08 '22 15:04 tbeu

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

seanm avatar Oct 07 '23 23:10 seanm

Can you please give f058e5d a try?

tbeu avatar Oct 17 '23 18:10 tbeu

That worked! Thanks!

seanm avatar Oct 17 '23 22:10 seanm

Thanks for confirmation!

tbeu avatar Oct 18 '23 15:10 tbeu