未定义的引用,尽管正确的链接顺序 [英] Undefined reference to, despite correct link order

查看:117
本文介绍了未定义的引用,尽管正确的链接顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法连接外部程式库, MY_LIB.a

I am having trouble linking against an external library, MY_LIB.a.

通过mbed.org编译器创建的makefile,以及添加了到 MY_LIB.a 路径的链接。

The following is invoked from the makefile created by mbed.org compiler, and with the addition of my link to MY_LIB.a path.

arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wl,--gc-sections --specs=nano.specs 
-u _printf_float -u _scanf_float -T./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/LPC1768.ld 
-L./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM -o MyProg.elf main.o mbed/TARGET_LPC1768
/TOOLCHAIN_GCC_ARM/cmsis_nvic.o mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/system_LPC17xx.o
mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/startup_LPC17xx.o mbed/TARGET_LPC1768
/TOOLCHAIN_GCC_ARM/board.o mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/retarget.o  
-lstdc++ -lsupc++ -lm -lc -lgcc -lnosys  -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys 
-L/usr/local/lib/MY_LIB.a
main.o: In function `main':

然后我得到未定义的引用< function> MY_LIB 中定义的每个函数的错误。

And then I get undefined reference to <function> errors for every function defined in MY_LIB.

我的理解是 MY_LIB.a c>

我还需要在 main.o 尝试链接(立即) -o MyProg.elf main.o 后,但是我得到无法读取符号:文件格式错误

I also tried linking (immediately) after -o MyProg.elf main.o, but then I get could not read symbols: File in wrong format.

链接此库的正确方法是什么?是否需要在上一步中链接到这里列出的正确的格式?如何实现?

What is the correct way to link this library? Does it need to be linked in the previous step to be listed here in.. the correct format? How is that done?

推荐答案

-L 图书馆。您可以从包含 MY_LIB.a 的参数中删除它,例如:

-L only specifies the search path for libraries. You could remove it from your parameter that is including MY_LIB.a, e.g.:

arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wl,--gc-sections --specs=nano.specs 
-u _printf_float -u _scanf_float -T./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/LPC1768.ld 
-L./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM -o MyProg.elf main.o mbed/TARGET_LPC1768
/TOOLCHAIN_GCC_ARM/cmsis_nvic.o mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/system_LPC17xx.o
mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/startup_LPC17xx.o mbed/TARGET_LPC1768
/TOOLCHAIN_GCC_ARM/board.o mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/retarget.o  
-lstdc++ -lsupc++ -lm -lc -lgcc -lnosys  -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys 
/usr/local/lib/MY_LIB.a

这篇关于未定义的引用,尽管正确的链接顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆