g++链接问题:对函数的未定义引用
我使用 CMake 和 Visual C++ 构建 HyDE 库。然后,仍然在 VC++ 中,我能够成功创建代码并构建链接到 HyDE.lib 和 HyDE 头文件的可执行文件。
然后我发现,为了与我公司的其他人一起工作,最好在 Eclipse CDT 中进行开发。由于对 Eclipse CDT 知之甚少,我创建了一个默认的 hello world 项目,删除了代码,然后将所有代码转储到 src 文件夹中。然后我尝试更改包含和库路径以及库以镜像 VC++ 中的工作内容。此时一切似乎都已编译,但我在链接时遇到错误:
/cygdrive/c/EclipseWorkspace/425HyDE/Debug/../src/FS5HyDE.cpp:16:对“HyDEAPI::HyDE::HyDE(HyDESystemModel::SystemModel*, bool)”的未定义引用
(还有更多错误,例如这一切都指的是 HyDE 方法。)以下是在命令行中运行的内容:
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 的方式是否存在问题?还有其他想法吗?
(注意:似乎还有很多关于 SO 的其他问题也有类似的问题,但在阅读完它们之后,我还没有找到一个可以解决我的问题的问题。)
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.
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: undefined reference to `HyDEAPI::HyDE::HyDE(HyDESystemModel::SystemModel*, bool)'
(There are many more errors like this, all referring to HyDE methods.) Here is what is being run at the command line:
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
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?
(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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
经典的缺少符号错误。哪个源文件定义:
HyDEAPI::HyDE::HyDE(HyDESystemModel::SystemModel*, bool)'
?该文件是否已添加到编译中?你能在你粘贴的命令行上找到它吗?
如果此符号属于外部库,则在使用
-L
添加目录路径后,您可以使用-l
添加要与程序链接的特定库的名称>。我建议您尝试将 HyDE.lib 的目录路径添加到编译命令中,后跟库名称,如下所示:
然后告诉我们发生了什么。
Classic missing symbol error. Which source file defines:
HyDEAPI::HyDE::HyDE(HyDESystemModel::SystemModel*, bool)'
?Was this file added to the compilation? Can you spot it on the command line you pasted?
If this symbol belongs to an external library, after adding the directory path with
-L
, you could add the name of the specific library you want to link with your program using-l
.I'm going to suggest that you try to add to the compilation command the directory path to HyDE.lib, followed immediately by the library name, like this:
and then tell us what happened.
解决方案:由于 HyDE 库是使用 Visual Studios 编译器编译的,并且我正在尝试构建使用 Cygwin 工具链链接到它的代码,因此两个编译器使用不同的名称重整方案,以便后一个链接器无法在中找到预期的符号海德图书馆。我找到的唯一解决方案是使用 Cygwin 工具链重新编译 HyDE 库,或者使用 Visual Studios 使用的任何编译器编译新代码。 (咕咕咕)
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)
如果有其他目标文件(*.o 文件),
./src/FS5HyDE.o
和./src/HyDEObservation.o
应该是最新参数> 需要它们,这意味着最需要的目标文件
应该尽可能出现在参数列表的最后。./src/FS5HyDE.o
and./src/HyDEObservation.o
should be the latest parameter if other object files (*.o files) need them, it means that the most neededobject files
should be appeared as last as possible in the parameters list.