g ++链接问题:未定义的函数引用 [英] g++ linking issues: undefined reference to functions

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

问题描述

我使用CMake和Visual C ++来构建HyDE库。然后,仍然在VC ++中,我能够成功地创建代码并构建一个链接到HyDE.lib和HyDE头文件的可执行文件。

I used CMake and Visual C++ to build the HyDE library. Then, still in VC++, I was able to successfully create code and build an executable that links into HyDE.lib and the HyDE header files.

然后我发现,在我公司与其他人合作,最好在Eclipse CDT中开发。了解Eclipse CDT很少,我创建了一个默认的hello world项目,删除代码,然后将所有代码转储到src文件夹中。然后我试图更改include和lib路径和libs镜像在VC ++中工作。这一切似乎都编译,但我得到一个错误在链接:

I then discovered that in order to work with others at my company, it would be preferable to develop in Eclipse CDT. Knowing very little about Eclipse CDT, I created a default hello world project, deleted the code and then dumped in all of my code into the src folder. Then I attempted to change the includes and lib path and libs to mirror what had worked in VC++. At this point everything seems to compile, but I get an error in linking:


/ cygdrive / c / EclipseWorkspace / 425HyDE / Debug /。 ./src/FS5HyDE.cpp:16:未定义引用HyDEAPI :: HyDE :: HyDE(HyDESystemModel :: SystemModel *,bool)'

/cygdrive/c/EclipseWorkspace/425HyDE/Debug/../src/FS5HyDE.cpp:16: undefined reference to `HyDEAPI::HyDE::HyDE(HyDESystemModel::SystemModel*, bool)'


$ b $这里是在命令行运行:

(There are many more errors like this, all referring to HyDE methods.) Here is what is being run at the command line:


g ++ -LC:\Progra_1 1 \boost\boost_1_42\lib-LC:\EclipseWorkspace\HyDE-o425HyDE.exe./src/Adapter_FS5HyDE.o ./src/EPSCommands.o ./src/EPSCurrentSensor.o ./src/EPSFault.o ./src/FS5HyDE.o ./src/HyDEObservation.o ./src/MCDH.o ./src/MCDH_Module.o。 /src/PDBComponent.o ./src/PowerSystem.o ./src/Program.o ./src/SSPCComponent.o ./src/Telemetry.o ./src/TelemetryReport.o -l:libboost_thread-vc90-mt- gd-1_42.lib -lHyDE

g++ -L"C:\Progra~1\boost\boost_1_42\lib" -L"C:\EclipseWorkspace\HyDE" -o"425HyDE.exe" ./src/Adapter_FS5HyDE.o ./src/EPSCommands.o ./src/EPSCurrentSensor.o ./src/EPSFault.o ./src/FS5HyDE.o ./src/HyDEObservation.o ./src/MCDH.o ./src/MCDH_Module.o ./src/PDBComponent.o ./src/PowerSystem.o ./src/Program.o ./src/SSPCComponent.o ./src/Telemetry.o ./src/TelemetryReport.o -l:libboost_thread-vc90-mt-gd-1_42.lib -lHyDE

这绝对不是一个库排序问题,因为我有另一个排序只有两个)。在VC ++(使用Windows编译器)编译HyDE.lib和编译我的程序与g ++有可能是一个问题? Eclipse CDT是否会自动生成makefile文件的方式有问题吗?任何其他想法?

This is definitely not a library ordering problem because I've the other ordering as well (there are only two). Is it possible that there is a problem with compiling HyDE.lib in VC++ (which uses a Windows compiler) and compiling my program with g++? Could there be a problem in the way that Eclipse CDT is autogen'ing the makefiles? Any other ideas?

(注意:似乎有很多其他问题的SO有类似的问题,但阅读后,我还没有找到一个,问题。)

(Note: there appear to be plenty of others questions on SO with similar problems, but after reading through them I have yet to find one that addresses my problem.)

推荐答案

解决方案:由于HyDE库是用Visual Studio编译器编译的,它使用Cygwin工具链链接到它,两个编译器使用不同的名称修整方案,以便后面的链接器在HyDE库中找不到预期的符号。我发现的唯一解决方案是使用Cygwin工具链重新编译HyDE库使用Visual Studio正在使用的任何编译器编译新代码。 (grumble grumble)

Solution: Since the HyDE library was compiled with the Visual Studios compiler and I'm attempting to build the code that links to it with the Cygwin toolchain the two compilers use different name mangling schemes so that the latter linker can not find the expected symbols in the HyDE library. The only solution that I've found is to recompile the HyDE library with the Cygwin toolchain or compile the new code with whatever compiler Visual Studios is using. (grumble grumble)

这篇关于g ++链接问题:未定义的函数引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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