以功能链接avrfix库使用AVR-GCC编译器/连接未定义引用 [英] undefined references to functions in linked avrfix library using avr-gcc compiler/linker

查看:275
本文介绍了以功能链接avrfix库使用AVR-GCC编译器/连接未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 avrfix库在一个项目中,使用Eclipse(v4.2.2)作为IDE和AVR-GCC作为编译器。无论是头文件(avrfix.h)和库文件(libavrfix.a)都包含在同一个目录中,这是该项目的搜索路径,以及链接程序的库搜索路径。编译时,我得到了以下错误:

  D:\\文档\\ Arduino的\\ IMU_Kalman \\发布/../ HMC5883 / HMC5883.cpp:359:未定义的引用`lsincoslk(很久很久*)'
D:\\文档\\ Arduino的\\ IMU_Kalman \\发布/../ HMC5883 / HMC5883.cpp:360:未定义的引用`lsincoslk(很久很久*)'
D:\\文档\\ Arduino的\\ IMU_Kalman \\发布/../ HMC5883 / HMC5883.cpp:361:未定义的引用`lmullkD(很久很久)
D:\\文档\\ Arduino的\\ IMU_Kalman \\发布/../ HMC5883 / HMC5883.cpp:362:未定义的引用`lmullkD(很久很久)
D:\\文档\\ Arduino的\\ IMU_Kalman \\发布/../ HMC5883 / HMC5883.cpp:365:未定义的引用`lmullkD(很久很久)
D:\\文档\\ Arduino的\\ IMU_Kalman \\发布/../ HMC5883 / HMC5883.cpp:365:未定义的引用`lmullkD(很久很久)
D:\\文档\\ Arduino的\\ IMU_Kalman \\发布/../ HMC5883 / HMC5883.cpp:365:未定义的引用`lmullkD(很久很久)
./HMC5883/HMC5883.o:D:\\Documents\\Arduino\\IMU_Kalman\\Release/../HMC5883/HMC5883.cpp:367:为`lmullkD(很久很久)更未定义引用'跟随
./HMC5883/HMC5883.o:在功能`HMC5883 :: Calc_Heading(很久很久):
D:\\文档\\ Arduino的\\ IMU_Kalman \\发布/../ HMC5883 / HMC5883.cpp:369:未定义的引用`latan2lk(很久很久)
使:*** [IMU_Kalman.elf]错误1

我明白,这意味着连接不正确查找和连接问题的功能(lsincoslk,lmullkD,latan2lk)。这些功能应该位于avrfix库。是完整的,是这里所用的连接器调用:

  AVR-GCC -Os轮候册, -  GC-部分轮候册,-Map,IMU_Kalman.map -  CREF --export-全符号-L D:\\文档\\ Arduino的\\ IMU_Kalman \\ avrfix-LD:\\文档\\ Arduino的\\ IMU_Kalman \\ Board_Support_Library-mmcu = ATMEGA328P -oIMU_Kalman.elf./Wire/Wire.o ./Wire/twi.o ./SPI/SPI.o ./MPU6000/MPU6000.o ./Kalman_Filters/GyroKalman.o ./HMC5883/HMC5883.o ./GlobalVariables.o ./IMU_Kalman.o -lavrfix -lArduino_Duemilanove_w__ATmega328 -lm

这里的重要部分是包括所述-lavrfix命令。我知道链接器能够找到库,因为如果我尝试拼写错误avrfix,它给它找不到库是错误的,而不是上面提到的那些。还值得一提的是,我包括libArduino_Duemilanove_w__ATmega328.a库成功地,使用的是什么,我认为是同样的方法。

当我看看编译器生成的.map文件,我看到几个功能,这来自Arduino_Duemilanove_w__ATmega328库,符合市场预期(的malloc,例如)。然而,没有从avrfix库函数或物体似乎已经使它成为地图。搜索avrfix在.MAP文件的产量在那里提到只有一个行:

  LOAD D:\\文档\\ Arduino的\\ IMU_Kalman \\ avrfix \\ libavrfix.a

是否有可能有一个与链接顺序有问题?我在什么可能是错在这里会出现亏损。是avrfix库我使用了某些原因AVR-gcc编译器不兼容?我也有点不熟悉二进制解析器(或如果他们甚至有什么与我的问题做的),但我已经尝试在C中选择多个不同的解析器(包括GNU精灵分析器)/ C ++建设 - >设置 - >二进制解析器选项卡中的项目属性。欲了解更多信息,我有整个项目(尽管这是一项正在进行的工作,在早期阶段)在github 这里。我试着寻找其他线程的帮助,但似乎无法找到特定于我的应用程序avrfix库的信息。在一个其他线程,我发现了一个建议使用连接器的召唤--export-全符号选项,但似乎并没有帮助我的情况。

如果有人知道发生了什么事请帮帮忙!不要犹豫,向我索取更多信息。

问候,


解决方案

  

未定义参考`lsincoslk(很久很久*)


这是 C ++ 重整名称<参考/ A>

这是可能的 libavrfix.a 该符号定义为的未修饰 C 名称。您可以通过运行验证这一点。

  AVR-readelf -ws libavrfix.a | grep的lsincoslk

如果你看到 NNNN牛逼_Z9lsincoslklPl ,我的猜测是不正确。但是,如果你看到 NNNN牛逼lsincoslk ,那么我的猜测是正确的。

看着<一个href=\"http://gitorious.org/mikrokopter/davys-flightctrl-uni-bremen-clone/source/69ff8429bac0385760751a1039214b5ad1dab3d5%3aavrfix.h\"相对=nofollow> avrfix.h >,我看到它缺乏适当的的externC警卫。如果包括此标题为 C ++ ,你必须这样做:

 的externC{
#包括avrfix.h
}

您就不必这样做,如果 avrfix 开发商关心 C ++ 。你可以向他们发送一个补丁 avrfix.h 。补丁应该在一开始补充一点:

 的#ifdef __cplusplus
为externC{
#万一

和本底:

 的#ifdef __cplusplus
}
#万一

I am trying to use the avrfix library in a project, using Eclipse (v4.2.2) as the IDE and avr-gcc as the compiler. Both the header file (avrfix.h) and the library file (libavrfix.a) are included in the same directory, which is in the project's search path as well as the linker's library search path. When compiling, i get the following errors:

D:\Documents\Arduino\IMU_Kalman\Release/../HMC5883/HMC5883.cpp:359: undefined reference to `lsincoslk(long, long*)'
D:\Documents\Arduino\IMU_Kalman\Release/../HMC5883/HMC5883.cpp:360: undefined reference to `lsincoslk(long, long*)'
D:\Documents\Arduino\IMU_Kalman\Release/../HMC5883/HMC5883.cpp:361: undefined reference to `lmullkD(long, long)'
D:\Documents\Arduino\IMU_Kalman\Release/../HMC5883/HMC5883.cpp:362: undefined reference to `lmullkD(long, long)'
D:\Documents\Arduino\IMU_Kalman\Release/../HMC5883/HMC5883.cpp:365: undefined reference to `lmullkD(long, long)'
D:\Documents\Arduino\IMU_Kalman\Release/../HMC5883/HMC5883.cpp:365: undefined reference to `lmullkD(long, long)'
D:\Documents\Arduino\IMU_Kalman\Release/../HMC5883/HMC5883.cpp:365: undefined reference to `lmullkD(long, long)'
./HMC5883/HMC5883.o:D:\Documents\Arduino\IMU_Kalman\Release/../HMC5883/HMC5883.cpp:367: more undefined references to `lmullkD(long, long)' follow
./HMC5883/HMC5883.o: In function `HMC5883::Calc_Heading(long, long)':
D:\Documents\Arduino\IMU_Kalman\Release/../HMC5883/HMC5883.cpp:369: undefined reference to `latan2lk(long, long)'
make: *** [IMU_Kalman.elf] Error 1

I understand that this implies the linker is not properly finding and linking the functions in question (lsincoslk, lmullkD, latan2lk). Those functions should be located in the avrfix library. To be complete, here is the linker invocation used:

avr-gcc -Os -Wl,--gc-sections  -Wl,-Map,"IMU_Kalman.map",--cref --export-all-symbols -L"D:\Documents\Arduino\IMU_Kalman\avrfix" -L"D:\Documents\Arduino\IMU_Kalman\Board_Support_Library" -mmcu=atmega328p  -o"IMU_Kalman.elf"  ./Wire/Wire.o ./Wire/twi.o  ./SPI/SPI.o  ./MPU6000/MPU6000.o  ./Kalman_Filters/GyroKalman.o  ./HMC5883/HMC5883.o  ./GlobalVariables.o ./IMU_Kalman.o   -lavrfix -lArduino_Duemilanove_w__ATmega328 -lm

The important piece here is that the -lavrfix command is included. I know the linker is able to find that library, because if I try mispelling avrfix, it gives an error that it cannot find the library, instead of the ones mentioned above. It is also worth mentioning that I am including the libArduino_Duemilanove_w__ATmega328.a library succesfully, using what I think is same method.

When I take a look at the compiler's generated .map file, I do see several functions which come from the Arduino_Duemilanove_w__ATmega328 library, as expected (malloc, for instance). However, no functions or objects from the avrfix library seem to have made it into the map. Searching 'avrfix' in the .map file yields only one single line where it is mentioned:

LOAD D:\Documents\Arduino\IMU_Kalman\avrfix\libavrfix.a

Is it possible there is a problem with link order? I'm at a loss for what may be going wrong here. Is the avrfix library incompatible with the avr-gcc compiler I am using for some reason? I'm also a bit unfamiliar with binary parsers (or if they even have anything to do with my problem), but I have tried selecting multiple different parsers (including the GNU Elf Parser) in the C/C++ Build->Settings->Binary Parsers tab in the project properties. For more info, I have the entire project (although it's a work in progress, in early stages) on github here. I've tried looking for help in other threads, but can't seem to find much information specific to the avrfix library in my application. In one other thread, I found a recommendation to use the --export-all-symbols option in the linker evocation, but that didn't seem to help my situation.

Please help if anyone knows what's going on! Don't hesitate to ask for more information from me.

Regards,

Paul

解决方案

undefined reference to `lsincoslk(long, long*)'

This is a reference to C++ mangled name.

It is likely that the libavrfix.a defines that symbol as undecorated C name. You can verify this by running

avr-readelf -Ws libavrfix.a | grep lsincoslk

If you see NNNN T _Z9lsincoslklPl, my guess is incorrect. But if you see NNNN T lsincoslk, then my guess is correct.

Looking at this version of avrfix.h, I see that it lacks proper extern "C" guards. When you include this header into C++, you must do this:

extern "C" {
#include "avrfix.h"
}

You wouldn't have to do that if avrfix developers cared about C++. You can send them a patch to avrfix.h. The patch should add this at the beginning:

#ifdef __cplusplus
extern "C" {
#endif

and this at the end:

#ifdef __cplusplus
}
#endif

这篇关于以功能链接avrfix库使用AVR-GCC编译器/连接未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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