简体   繁体   English

g ++抱怨未定义引用'_register_callback'

[英]g++ complains undefined reference to '_register_callback'

I tried compiling a dll under Cygwin with a '.a file' that was created via dlltool using foo.def file. 我尝试用通过foo.def文件通过dlltool创建的'.a文件'编译Cygwin下的dll。 In the .def file, I can see that register_callback exists: 在.def文件中,我可以看到register_callback存在:

EXPORTS
    ...
    register_callback @7569
    ...

The .a file was created using dlltool --def foo.def --output-lib libfoo.a . .a文件是使用dlltool --def foo.def --output-lib libfoo.a

However, when linking the main.o file, g++ complains that _register_callback is undefined. 但是,在链接main.o文件时,g ++抱怨_register_callback未定义。 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' nm libfoo.a | grep 'register_callback' shows: nm libfoo.a | grep 'register_callback'显示:

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. 不论是否使用-lfoo,都没有任何区别。

Any pointers towards solving this issue would be appreciated. 任何解决这个问题的指针将不胜感激。

g++ -shared -lfoo -o plugin.dll main.o

should be 应该

g++ -shared -o plugin.dll main.o -lfoo

ie 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 ld now expects that the files be specified in the same order that the symbols depend on each other. 这是较新版本的GCC(而不是GNU工具链)所必需的,因为ld现在期望以符号相互依赖的相同顺序指定文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM