11

我是 Qt 新手,有一个无法修复的错误。

我有一堆 Windows (VS2005) 静态库文件 ( .lib)。我正在测试它们是否可以很好地与 Qt 配合使用。所以我选择了我拥有的最简单的库。(称为MessageBuffer)。

所以我添加MessageBuffer.hmain.cpp, 并将那些文件的位置添加INCLUDEPATH.pro.

在那之前一切看起来都很好,我可以使用类和 Qt IDE 显示所有方法和所有内容。所以对我来说,它看起来像是找到了 .h 文件。

现在我像这样添加了MessageBuffer.lib(VS2005/Debug build).pro

LIBS += E:/SharedLibrary/lib/MessageBufferd.lib

我还尝试了以下方法:

win32:LIBS += E:/SharedLibrary/lib/MessageBufferd.lib
LIBS += -LE:/SharedLibrary/lib -lMessageBufferd
win32:LIBS += -LE:/SharedLibrary/lib -lMessageBufferd

这是我的.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

他们都给了我同样的错误:(即使我不包括,我也会得到同样的错误.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'

有人可以帮忙吗?

4

3 回答 3

5

基于问题在由 g++ (mingw) 编译的应用程序中使用 Visual Studio 编译的库和 MSDN 论坛帖子我不能混合 VC 和 GCC,您似乎无法将 gcc 应用程序与 Visual C++ 编译库链接。

解决方案是使用相同的编译器重新编译所有内容。

于 2009-07-16T15:17:11.917 回答
4

MinGW FAQ 讨论了这个问题并提供了解决方案:

  1. 使用 reimp(用于 lib 文件)或 pexports(用于 dll 文件)创建定义文件。
  2. 从 stdcall 函数中删除下划线前缀。
  3. 使用 dlltool 将 MSVC 库转换为具有新定义的 MinGW 库。

那没有用。我们最终从函数名称中删除了序数,这导致它可以编译。但是程序无法运行,因为它在 DLL 中找不到链接的函数。最后,在查阅了 MSDN 文档中的定义文件后,我们更改了构建说明:

  1. 使用 reimp 创建定义文件。
  2. 为每个 stdcall 函数(格式为 _name@ordinal)添加一个 line name = _name@ordinal,允许 MinGW 将其 stdcall 命名约定映射到 MSVC 的命名约定。
  3. 使用 dlltool 将 MSVC 库转换为具有新定义的 MinGW 库。

有效!要编译项目,您必须简单地:

  1. 下载并安装包含 MinGW 的 Qt/Windows 包。
  2. 下载 reimp 并将其放入 MinGW/bin 文件夹。
  3. 下载第三方库的开发包并将环境变量指向该位置。
  4. 使用常用的 qmake/make 命令构建项目。

取自: http ://blog.outofhanwell.com/2006/05/01/linking-msvc-libraries-with-mingw-projects/

于 2009-07-16T15:38:03.747 回答
0

我假设您在另一个有问题的应用程序中使用了 MessageBuffer 库。该错误看起来像是找不到库或未导出 MessageBuffer 类。

您是否尝试将 -l 放在 pro 文件中的库前面?

win32:LIBS += -lE:/SharedLibrary/lib/MessageBufferd.lib

请参阅我的其他答案。我添加了另一个答案,因为我不想让这个答案变得比现在更混乱。

到目前为止尝试过:

  • 不是错字, d 附加到库中
  • 如输出所示,使用 lib 扩展是正确的
于 2009-07-16T13:45:40.257 回答