我在与C中的库正确链接时遇到了一些问题.
我敢肯定这是我不完全理解的那些神秘的C链接规则之一,但我无法弄清楚.
我有libn,我编译成一个静态库libn.a
nm libn显示:
doug@ninja:~/projects/libnw/build$ nm ../../libn/build/libn.a |grep nIndex
00000034 T nIndex
00000000 D nIndex_
00000026 T nIndex_finalize
00000013 T nIndex_init
00000000 T nIndex_map
Run Code Online (Sandbox Code Playgroud)
我也有libnw,这取决于libn.libnw上的nm显示:
doug@ninja:~/projects/libnw/build$ nm libnw.a |grep Index
U nIndex
Run Code Online (Sandbox Code Playgroud)
但是,当我编译一个针对libnw和libn的编程链接时,我得到:
doug@ninja:~/projects/libnw/build$ make
[ 70%] Built target nw
[ 80%] Built target test-template
Scanning dependencies of target test-Core
[ 85%] Building C object tests/nw/mvc/Core/CMakeFiles/test-Core.dir/Tests.c.o
[ 90%] Building C object tests/nw/mvc/Core/CMakeFiles/test-Core.dir/test.c.o
Linking C executable test-Core
../../../../libnw.a(Impl.c.o): In function `nwCore__Impl_init':
/home/doug/projects/libnw/src/nw/mvc/Core/Impl.c:76: undefined reference to `nIndex'
collect2: ld returned 1 …Run Code Online (Sandbox Code Playgroud)