我有几个使用 avr-ar 创建的库。每个包含几个对象。
库 1 中的对象需要库 2 中对象的符号。问题是,当我尝试编译整个东西时,我遇到了 undefined reference
问题。
这就是它失败的地方,$(INCLUDE) $(CFLAGS) $(LIBS) 中没有什么特别的
CFLAGS=-mmcu=atmega328p -DF_CPU=16000000UL -Os -w -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
LIBS=library1.a library2.a
$(CXX) $(INCLUDE) $^ $(CFLAGS) -o $@ $(LIBS)
我正在运行 Ubuntu 12.04 和
Using built-in specs.
COLLECT_GCC=avr-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.5.3/lto-wrapper
Target: avr
Configured with: ../src/configure -v --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-libssp --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=avr
Thread model: single
gcc version 4.5.3 (GCC)
如果我从库中提取对象并将所有对象放入库中,一切都会顺利进行。
我想将它们分开,有什么办法可以实现吗?
最佳答案
您可以尝试通过对库进行分组来使链接器执行递归链接。我没有检查以下内容,但可能会更改:
LIBS=library1.a library2.a
到
LIBS=-Wl,--start-group library1.a library2.a -Wl,--end-group
这将导致链接器来回切换,直到所有符号都定义完毕,这会降低链接器的性能。这在两个库相互依赖时很有用,因为链接器通常只传递每个文件一次。
希望对你有帮助
关于c++ - 链接静态库时 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11946536/