:: error:collect2:ld使用QT和opengl返回1退出状态

时间:2011-08-11 21:01:07

标签: qt linker

我正在尝试在QT应用程序中使用QGLWidget,并且我已将“QT + = opengl”行添加到.pro文件中,但我现在正在获取:: error:collect2:ld返回1退出状态当我尝试编译我的程序时

编译输出显示以下内容,

Running build steps for project MapEditor...
Configuration unchanged, skipping qmake step.
Starting: "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `C:/Qt/2010.05/MapEditor-build-desktop'

C:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug

mingw32-make[1]: Entering directory `C:/Qt/2010.05/MapEditor-build-desktop'

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\MapEditor.exe debug/Main.o debug/window.o debug/glwidget.o debug/moc_window.o debug/moc_glwidget.o  -L"c:\Qt\2010.05\qt\lib" -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtOpenGLd4 -lQtGuid4 -lQtCored4 

mingw32-make[1]: Leaving directory `C:/Qt/2010.05/MapEditor-build-desktop'

mingw32-make: Leaving directory `C:/Qt/2010.05/MapEditor-build-desktop'

debug/moc_glwidget.o:moc_glwidget.cpp:(.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x14): undefined reference to `GLWidget::~GLWidget()'

debug/moc_glwidget.o:moc_glwidget.cpp:(.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x18): undefined reference to `GLWidget::~GLWidget()'

debug/moc_glwidget.o:moc_glwidget.cpp:(.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x118): undefined reference to `non-virtual thunk to GLWidget::~GLWidget()'

debug/moc_glwidget.o:moc_glwidget.cpp:(.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x11c): undefined reference to `non-virtual thunk to GLWidget::~GLWidget()'

collect2: ld returned 1 exit status

mingw32-make[1]: *** [debug\MapEditor.exe] Error 1

mingw32-make: *** [debug] Error 2

进程“C:/Qt/2010.05/mingw/bin/mingw32-make.exe”退出,代码为%2。 构建项目MapEditor时出错(目标:桌面) 执行构建步骤'Make'时

和我的.pro文件包含以下内容,

TARGET = MapEditor
TEMPLATE =app

QT += opengl

SOURCES += \
    Main.cpp \
    window.cpp \
    glwidget.cpp

HEADERS += \
    window.h \
    glwidget.h

2 个答案:

答案 0 :(得分:0)

看起来有些文件丢失了。你有没有把它添加到标题中?

 #include <QtOpenGL>

答案 1 :(得分:0)

检查.pro文件(即项目文件),你已经在SOURCES和HEADERS标签中添加了所有类文件和头文件。[为此目的,从build menubar options运行qmake命令] 还要检查你是否在glwidget类的开头声明了Q_OBJECT宏。