[英]Qt/mingw32 undefined reference errors… unable to link a .lib
I am new to Qt and have one error I am unable to fix. 我是Qt的新手,有一个我无法解决的错误。
I have a bunch of windows (VS2005) static library file ( .lib
). 我有一堆windows(VS2005)静态库文件(
.lib
)。 And I am testing if they work well with Qt. 我正在测试它们是否与Qt配合良好。 So I took the most simple library that I have.
所以我选择了最简单的库。 (Called
MessageBuffer
). (称为
MessageBuffer
)。
So I added MessageBuffer.h
to the main.cpp
, and added the location of those file in the INCLUDEPATH
of the .pro
. 所以我将
MessageBuffer.h
添加到main.cpp
,并在.pro
的INCLUDEPATH
中添加了这些文件的位置。
Until then everything seem fine, I can use the class and Qt IDE show all method and everything. 在那之前一切都很好,我可以使用类和Qt IDE显示所有方法和一切。 So to me it look like it found the .h file.
所以对我来说,它看起来像是找到了.h文件。
Now I added the MessageBuffer.lib
(VS2005/Debug build) in the .pro
like this: 现在我在
.pro
添加了MessageBuffer.lib
(VS2005 / Debug build),如下所示:
LIBS += E:/SharedLibrary/lib/MessageBufferd.lib
I have also tried the following: 我也尝试过以下方法:
win32:LIBS += E:/SharedLibrary/lib/MessageBufferd.lib
LIBS += -LE:/SharedLibrary/lib -lMessageBufferd
win32:LIBS += -LE:/SharedLibrary/lib -lMessageBufferd
Here is the content of my .pro
file: 这是我的
.pro
文件的内容:
QT += opengl
TARGET = SilverEye
TEMPLATE = app
INCLUDEPATH += E:/SharedLibrary/MessageBuffer
SOURCES += main.cpp \
silvereye.cpp
HEADERS += silvereye.h
FORMS += silvereye.ui
OTHER_FILES +=
win32:LIBS += E:/SharedLibrary/lib/MessageBufferd.lib
They all give me the same errors: (and I get the same even if I don't include the .lib
) 他们都给了我同样的错误:(即使我不包含
.lib
,我也会得到相同的错误)
Running build steps for project SilverEye...
Configuration unchanged, skipping QMake step.
Starting: C:/Qt/2009.03/mingw/bin/mingw32-make.exe -w
mingw32-make: Entering directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
C:/Qt/2009.03/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\SilverEye.exe debug/main.o debug/silvereye.o debug/moc_silvereye.o -L"c:\Qt\2009.03\qt\lib" -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind E:/SharedLibrary/lib/MessageBufferd.lib -lQtOpenGLd4 -lQtGuid4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
mingw32-make: Leaving directory `C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye'
debug/main.o: In function `Z5qMainiPPc':
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:12: undefined reference to `MessageBuffer::MessageBuffer()'
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:13: undefined reference to `MessageBuffer::Append(char*, int)'
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:17: undefined reference to `MessageBuffer::~MessageBuffer()'
C:/Documents and Settings/JP/My Documents/QTProjects/SilverEye/main.cpp:17: undefined reference to `MessageBuffer::~MessageBuffer()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\SilverEye.exe] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project SilverEye
When executing build step 'Make'
Can anyone help please? 有人可以帮忙吗?
Based on the question Use libraries compiled with visual studio in an application compiled by g++ (mingw) and the MSDN forum post I can't mix VC & GCC it does not appear you can link a gcc application with visual c++ compiled libraries. 基于在g ++(mingw)和MSDN论坛帖子编译的应用程序中使用可视化工作室编译的库, 我不能混合VC和GCC ,看起来你不能将gcc应用程序与visual c ++编译库链接。
The solution would be to recompile everything with the same compiler. 解决方案是使用相同的编译器重新编译所有内容。
The MinGW FAQ discusses this problem and offers a solution: MinGW FAQ讨论了这个问题,并提供了一个解决方案:
That didn't work. 那没用。 We finally removed the ordinals from the function names, which caused it to compile.
我们最终从函数名中删除了序数,这导致它编译。 But the program wouldn't run because it couldn't find the linked functions in the DLL.
但程序无法运行,因为它无法在DLL中找到链接的函数。 Finally, after consulting the MSDN documentation for definition files, we changed the build instructions:
最后,在查阅定义文件的MSDN文档后,我们更改了构建说明:
It worked! 有效! To compile the project you must simply:
要编译项目,您必须简单地:
Taken from: http://blog.outofhanwell.com/2006/05/01/linking-msvc-libraries-with-mingw-projects/ 摘自: http : //blog.outofhanwell.com/2006/05/01/linking-msvc-libraries-with-mingw-projects/
I assume that you have used the MessageBuffer library in another application with problems. 我假设你在另一个有问题的应用程序中使用了MessageBuffer库。 The error looks like it either cannot find the library or the MessageBuffer class is not being exported.
该错误看起来无法找到库或未导出MessageBuffer类。
Have you tried putting -l on front of the library in the pro file? 您是否尝试在专业文件中将-l放在库的前面?
win32:LIBS += -lE:/SharedLibrary/lib/MessageBufferd.lib
See my other answer . 看到我的其他答案 。 I added the other answer because I didn't want to make this answer any more messy than it already was.
我添加了另一个答案,因为我不想让这个答案比现在更混乱。
Tried so far: 到目前为止尝试过:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.