问题描述
我的 Irrlicht 程序没有链接.我使用的编译器是 g++.
My Irrlicht program doesn't link. The compiler I use is g++.
代码:
#include <irrlicht.h>
int main()
{
irr::IrrlichtDevice *device = irr::createDevice();
// And other init stuff
while(device->run())
{
driver->beginScene();
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
}
链接器输出:
...
(path)/main.cpp:28: undefined reference to `__imp_createDevice'
collect2.exe: error: ld returned 1 exit status
命令行:
g++.exe -o "(Path)Test.exe" "(Path)Testmain.o"
............MinGWliblibIrrlicht.a
链接器找到了库文件.怎么了?
The linker founds the library file. What's wrong?
我做了很少的实验.结果是,当我注释 createDevice()
行时,不会出现链接器错误.所以这意味着,该链接器找到了所有其他函数,即 IrrlichtDevice::run()
.
I made little experimenting. The result was, that when I comment createDevice()
-line out, no linker errors will come. So that means, that linker founds all the other functions, i.e. IrrlichtDevice::run()
.
推荐答案
__imp_createDevice 指的是为动态链接到 .so 或 .dll 而构建的 .lib 文件.参见这篇文章和回答.
__imp_createDevice refers to a .lib file that is built for dynamic linking to an .so or .dll. See this post and answer.
查找为静态链接构建的 .lib,或者检查是否必须指定预编译器定义(例如 _IRR_STATIC_LIB_、IRRLICHT_STATIC 或 IRRLICHT_EXPORTS)以获得正确链接.
Find the .lib that is built for static linking, or alternatively check if you have to specify a pre-compiler definition such as _IRR_STATIC_LIB_, IRRLICHT_STATIC or IRRLICHT_EXPORTS to have correct linkage.
这篇关于C++ Irrlicht 程序不链接:“对‘__imp_createDevice’的未定义引用";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!