I tried compiling a dll under Cygwin with a ‘.a file’ that was created via dlltool using foo.def file. In the .def file, I can see that register_callback exists:
EXPORTS
...
register_callback @7569
...
The .a file was created using dlltool --def foo.def --output-lib libfoo.a.
However, when linking the main.o file, g++ complains that _register_callback is undefined.
main.o:main.cpp:(.text+0x6e): undefined reference to '_register_callback'
g++ -shared -lfoo -o plugin.dll main.o
nm libfoo.a | grep 'register_callback' shows:
00000000 b .bss$lazy_iregister_callback
00000000 r .rdata$lazy_iregister_callback
00000000 b __imp__register_callback
00000000 T _register_callback
00000000 b .bss$lazy_iunregister_callback
00000000 r .rdata$lazy_iunregister_callback
00000000 b __imp__unregister_callback
00000000 T _unregister_callback
It looks like with or without the -lfoo doesn’t make a difference.
Any pointers towards solving this issue would be appreciated.
should be
i. e. move the linker flag that specifies a library to the end of the command line invocation. This is required for newer versions of GCC (rather the GNU toolchain) since
ldnow expects that the files be specified in the same order that the symbols depend on each other.