简体   繁体   English

创建共享库时,如何告诉链接器可执行文件中包含符号?

[英]When creating a shared library, how to tell the linker that a symbol is in the executable?

I'm creating a an apache module which is basically a shared library (not in C, but in rust, so I can't use the usual apache tooling that hides all this stuff). 我正在创建一个基本上是共享库的apache模块(不在C中,而是在rust中,所以我不能使用隐藏所有这些东西的常用apache工具)。

When I go to link, ld is telling me there's a bunch of undefined symbols. 当我转到链接时, ld告诉我有一堆未定义的符号。 These symbols are all defined in the executable that will be loading this shared library, namely /usr/sbin/httpd . 这些符号均在将加载此共享库的可执行文件(即/usr/sbin/httpd I verified this with nm . 我用nm验证了这一点。 I can't find them in any other static or shared libs. 我在任何其他静态或共享库中找不到它们。

How do I tell the linker the symbols are in httpd ? 如何告诉链接器httpd的符号?

here is an abbreviated linker command it is firing off: 这是一个简短的链接器命令,它正在触发:

"cc" "-m64" "-L" "/Users/me/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/me/dev/apacheagent-myco/target/debug/deps/apacheagentmyco.apacheagentmyco0.rcgu.o" ...<tons of .o files>  "-Wl,-exported_symbols_list,/var/folders/6h/qx6jssj16q95_h_kqjd6qt_00000gn/T/rustc.xMMi8AxcVg62/list"  "-Wl,-dead_strip" "-nodefaultlibs" "-L" <tons of rlibs>  "-l" "onig" "-framework" "Security" "-framework" "CoreFoundation" "-l" "System" "-l" "resolv" "-l" "pthread" "-l" "c" "-l" "m" "-dynamiclib" "-Wl,-dylib" "-lapr-1" "-laprutil-1"

here are the errors: 错误如下:

note: Undefined symbols for architecture x86_64:
            "_ap_is_initial_req", referenced from:
                apache2::httpd::_$LT$impl$u20$apache2..wrapper..Wrapper$LT$apache2..ffi..request_rec$GT$$GT$::is_initial_req::h078b0dbdc2d2d488 in libapache2-850bd4b18832aac1.rlib(apache2-850bd4b18832aac1.apache20.rcgu.o)
            "_ap_hook_handler", referenced from:
                apacheagentmyco::apache_agent_myco_hooks::h3461197a43567639 in apacheagentmyco.apacheagentmyco7.rcgu.o
            "_ap_server_root", referenced from:
                apacheagentmyco::myco_child_init::h52c8c1513f7742ef in apacheagentmyco.apacheagentmyco7.rcgu.o
            "_ap_get_brigade", referenced from:
                apacheagentmyco::myco_apache2::apache2_body::read_body::h41bdc64c0c81a6d6 in apacheagentmyco.apacheagentmyco15.rcgu.o
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

These symbols are all in /usr/sbin/httpd. 这些符号都在/ usr / sbin / httpd中。

How do I tell the linker the symbols are in httpd ? 如何告诉链接器httpd中的符号?

You shouldn't need to: UNIX linkers by default assume that a shared library will have unresolved symbols. 您不需要:缺省情况下,UNIX链接程序假定共享库将包含未解析的符号。

Your problem appears to be: missing -shared flag on the link line (without it, the linker is trying to link an executable, and not a shared library that you want to link). 您的问题似乎是:链接行上缺少-shared标志(如果没有,链接器将尝试链接可执行文件,而不是您要链接的共享库)。

PS Using -nodefaultlibs is ill -advised. PS使用-nodefaultlibs -advised。 You should never use it unless you know what you are doing. 除非您知道自己在做什么,否则切勿使用它。

仅供以后参考,以防万一其他人遇到相同的问题,我通过告诉链接器忽略特定的符号来解决此问题。

... -Wl,-U,_ap_is_initial_req -Wl,-U,_ap_hook_handler -Wl,-U,_ap_server_root  

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

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