Problems compiling an c++ application using QT and OpenGL - c++

I'm following this tutorial for building a simple OpenGl application in C++ using QT.
I'm trying to compile the application using g++ and the command line but I get the following errors:
/tmp/ccH2KFoZ.o: In function `GLWidget::GLWidget(QWidget*)':
GLWidget.cpp:(.text+0x38): undefined reference to `QGLWidget::QGLWidget(QWidget*, QGLWidget const*, QFlags<Qt::WindowType>)'
GLWidget.cpp:(.text+0x41): undefined reference to `vtable for GLWidget'
GLWidget.cpp:(.text+0x4b): undefined reference to `vtable for GLWidget'
GLWidget.cpp:(.text+0x5e): undefined reference to `QGLWidget::setMouseTracking(bool)'
GLWidget.cpp:(.text+0x6f): undefined reference to `QGLWidget::~QGLWidget()'
/tmp/ccH2KFoZ.o: In function `GLWidget::GLWidget(QWidget*)':
GLWidget.cpp:(.text+0xbe): undefined reference to `QGLWidget::QGLWidget(QWidget*, QGLWidget const*, QFlags<Qt::WindowType>)'
GLWidget.cpp:(.text+0xc7): undefined reference to `vtable for GLWidget'
GLWidget.cpp:(.text+0xd1): undefined reference to `vtable for GLWidget'
GLWidget.cpp:(.text+0xe4): undefined reference to `QGLWidget::setMouseTracking(bool)'
GLWidget.cpp:(.text+0xf5): undefined reference to `QGLWidget::~QGLWidget()'
/tmp/ccH2KFoZ.o: In function `GLWidget::resizeGL(int, int)':
GLWidget.cpp:(.text+0x1e1): undefined reference to `gluOrtho2D'
/tmp/ccH2KFoZ.o: In function `GLWidget::keyPressEvent(QKeyEvent*)':
GLWidget.cpp:(.text+0x2dd): undefined reference to `QWidget::close()'
/tmp/ccDIuk1w.o: In function `main':
main.cpp:(.text+0x29): undefined reference to `QApplication::QApplication(int&, char**, int)'
main.cpp:(.text+0x6a): undefined reference to `QApplication::exec()'
main.cpp:(.text+0xa0): undefined reference to `QApplication::~QApplication()'
main.cpp:(.text+0xb8): undefined reference to `QApplication::~QApplication()'
/tmp/ccDIuk1w.o: In function `QWidget::resize(int, int)':
main.cpp:(.text._ZN7QWidget6resizeEii[QWidget::resize(int, int)]+0x2d): undefined reference to `QWidget::resize(QSize const&)'
/tmp/ccDIuk1w.o: In function `GLWidget::~GLWidget()':
main.cpp:(.text._ZN8GLWidgetD1Ev[GLWidget::~GLWidget()]+0x13): undefined reference to `vtable for GLWidget'
main.cpp:(.text._ZN8GLWidgetD1Ev[GLWidget::~GLWidget()]+0x1d): undefined reference to `vtable for GLWidget'
main.cpp:(.text._ZN8GLWidgetD1Ev[GLWidget::~GLWidget()]+0x28): undefined reference to `QGLWidget::~QGLWidget()'
collect2: ld returned 1 exit status
I've tried searching for a solution but all the solutions I can suggest altering a .pro file which I assume is something used by Netbeans or Codeblocks, neither of which I'm using.
What are the correct command line flags to pass to g++ so I can compile this application?
Here is the g++ command I'm currently using:
g++ *.cpp -I/usr/include/qt4 -I/usr/include/qt4/Qt -I/usr/include/QtCore -I/usr/include/QtGui -lGL
Edit: I ended up using a project file that looks like this.
TEMPLATE = app
TARGET = glQt
QT += opengl
HEADERS += \
GLWidget.h
SOURCES += \
GLWidget.cpp \
main.cpp

The .pro file is needed by QMake, the make app distributed with Qt.
This pro file specifies all the files needed to build your project, as well as the Qt modules.
More about qmake and the .pro file here: http://qt-project.org/doc/qt-4.8/qmake-manual.html
If you install the IDE QtCreator, the task of modifying the .pro file and compiling your app will be a bit easier.
After you modify the .pro file, you usually build the Qt app using the command qmake, which produces a make file ready to be used by your system (on Windows it can also produce .sln solutions for Visual Studio)
A short .pro file from one of my projects:
TEMPLATE = app
TARGET = icat2browser
QT += network webkit <-- add here the opengl module
DEFINES += QT_LARGEFILE_SUPPORT
HEADERS += \
qicat2networkaccessmanager.h \
ctimeline.h \
cobjectsview.h \
cicat2WebResponse.h \
cicat2usersdialog.h \
cicat2previewdialog.h \
cicat2login.h \
cicat2clients.h \
cicat2browser.h \
SOURCES += \
qicat2networkaccessmanager.cpp \
main.cpp \
ctimeline.cpp \
cobjectsview.cpp \
cicat2WebResponse.cpp \
cicat2usersdialog.cpp \
cicat2previewdialog.cpp \
cicat2login.cpp \
cicat2clients.cpp \
cicat2browser.cpp \

It looks like you are having a linker error. Although I have not used Qt, but from the way you compiling it looks like you are not linking Qt libraries. Try linking Qt libraries while building your example as follows (untested):
g++ *.cpp -I./ -I/usr/include/qt4 -I/usr/include/qt4/Qt -I/usr/include/QtCore -I/usr/include/QtGui -lGL -lQtCore -lQtGui -lQtOpenGL
I am guessing you must have installed development packages for Qt libraries in which case most likely you will have pkg-config files i.e. .pc files on you system in /usr/lib/pkgconfig. Try compiling as follows (untested):
g++ *.cpp -I./ `pkg-config --cflags --libs QtOpenGL`
Hope this helps!

I suggest you use qmake to generate a correct Makefile for your Qt installation. Using QtCreator simplifies this. Write a .pro file which is 5 lines of code and remember to add QT += opengl. Then run qmake and make.

I HIGHLY recommend you use qmake! Otherwise you will have to manually call the moc, uic, and rcc yourself!

Related

How to compile rpcgen files with Qt classes?

I'm working on an assignment where we have to use RPCgen generated server and client .c files to exchange information about a shared drawing board. The drawing board was implemented using QtCreator and QtPainter.
The issue I'm having is that, when compiling, I get errors of undefined references both to xdr functions such as xdr_int and to functions in the class files I created inside QtCreator related to xdr. I think it's worth saying that the client/server independent code runs fine with the -ltirpc flag.
I've already tried adding the -ltirpc flag both directly in the makefile generated by the .pro + qmake, and only in the pro. file and then running through QtCreator. The LineArea function below is one of the undefined references and the first line, where it creates the client, is a reference to xdr function clnt_create.
LineArea::LineArea(char *hostname, QWidget *parent) : QWidget(parent)
{
clnt = clnt_create(hostname, WHITEBOARD_PROG, WHITEBOARD_VERSION, "udp");
if (clnt)
{
clnt_info = register_client_1(clnt_info, clnt);
setAttribute(Qt::WA_StaticContents);
press_start = false;
pen_width = 2;
pen_color = QColor(clnt_info->r, clnt_info->g, clnt_info->b);
board = QImage(500, 500, QImage::Format_RGB32);
board.fill(qRgb(255, 255, 255));
board_real = board;
update();
}
}
Here's the latest attempt at adding the compile flag to qmake/.pro:
CONFIG += c++11
SOURCES += \
LineArea.cpp \
main.cpp \
mainwindow.cpp \
whiteboard_clnt.c \
whiteboard_xdr.c
HEADERS += \
LineArea.h \
mainwindow.h \
whiteboard.h
FORMS += \
mainwindow.ui
#EXTRA FLAGS
QMAKE_CXXFLAGS += -ltirpc
Any help or suggestion is appreciated.
EDIT: these are the errors at compile time
g++ -Wl,-O1 -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o whiteboard LineArea.o main.o mainwindow.o moc_LineArea.o moc_mainwindow.o whiteboard_clnt.c whiteboard_xdr.c whiteboard.h /usr/lib/libQt5Widgets.so /usr/lib/libQt5Gui.so /usr/lib/libQt5Core.so /usr/lib/libGL.so -lpthread
/usr/bin/ld: LineArea.o: in function `LineArea::LineArea(char*, QWidget*)':
LineArea.cpp:(.text+0xa6f): undefined reference to `clnt_create'
/usr/bin/ld: /tmp/ccdM1OwC.o: in function `send_line_1':
whiteboard_clnt.c:(.text+0x43): undefined reference to `xdr_int'
/usr/bin/ld: /tmp/ccdM1OwC.o: in function `remove_client_1':
whiteboard_clnt.c:(.text+0x1cf): undefined reference to `xdr_int'
/usr/bin/ld: /tmp/cccxQLHU.o: in function `xdr_operands':
whiteboard_xdr.c:(.text+0x54): undefined reference to `xdr_int'
/usr/bin/ld: whiteboard_xdr.c:(.text+0x7e): undefined reference to `xdr_int'
/usr/bin/ld: whiteboard_xdr.c:(.text+0xa8): undefined reference to `xdr_int'
/usr/bin/ld: /tmp/cccxQLHU.o:whiteboard_xdr.c:(.text+0xd2): more undefined references to `xdr_int' follow
collect2: error: ld returned 1 exit status
make: *** [Makefile:410: whiteboard] Error 1
I'm running make manually, I've added the whiteboard_clnt.c whiteboard_xdr.c and whiteboard.h to the recipe at the makefile. Whithout them the same errors appear, except the xdr errors.
g++ -Wl,-O1 -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o whiteboard LineArea.o main.o mainwindow.o moc_LineArea.o moc_mainwindow.o /usr/lib/libQt5Widgets.so /usr/lib/libQt5Gui.so /usr/lib/libQt5Core.so /usr/lib/libGL.so -lpthread
/usr/bin/ld: LineArea.o: in function `LineArea::recvLines()':
LineArea.cpp:(.text+0x70): undefined reference to `consult_line_1'
/usr/bin/ld: LineArea.o: in function `LineArea::drawLineTo(QPoint const&)':
LineArea.cpp:(.text+0x7a0): undefined reference to `send_line_1'
/usr/bin/ld: LineArea.o: in function `LineArea::LineArea(char*, QWidget*)':
LineArea.cpp:(.text+0xa6f): undefined reference to `clnt_create'
/usr/bin/ld: LineArea.cpp:(.text+0xa86): undefined reference to `register_client_1'
collect2: error: ld returned 1 exit status
make: *** [Makefile:410: whiteboard] Error 1
QMAKE_CXXFLAGS += -ltirpc adds compiler flags, and compiler doesn't care about libraries. Assuming the lib name is correct and found without adding -L library search paths, this should work:
LIBS += -ltirrp

Relink objects from most basic Qt application - Linker error

Try first if the simple demo app (the console project template) compiles with qmake command line:
SET PATH=%PATH%;C:\Qt\Qt5.9.1\5.9.1\mingw53_32\bin;C:\Qt\Qt5.9.1\Tools\mingw530_32\bin
C:\Qt\Qt5.9.1\5.9.1\mingw53_32\bin\qmake.exe -makefile C:\Software\test.pro -spec win32-g++
mingw32-make.exe
pause
Now trying to relink the application:
C:\Qt\Qt5.9.1\Tools\mingw530_32\bin\ld -o test release\main.o -LC:\Qt\Qt5.9.1\5.9.1\mingw53_32\bin -lQt5Core --verbose > ld_dump.txt
pause
Errors
main.o undefined reference to _Unwind_Resume
main.o undefined reference to __gxx_personality_v0
For comparison a slightly more complex app with QtWidgets prodcues even more errors (of course I added the missing Qt libs in the linker bat file)
moc_widget.o undefined reference to strcmp
moc_widget.o QObject undefined reference to vtable for __xyyabiv1:: __class_type_info
...
Googling error 1+2 they say it may be caused by different compilers. But I am using the same tool.
The pro file looks like
QT += core
QT -= gui
CONFIG += c++11
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
Do I maybe need to pass some kind of c++11 flag to the linker ld?
I think ld needs a lot more information (e.g. it doesn't know anything about stdc++). Why don't you link using g++, instead? A line like this should work:
C:\Qt\Qt5.9.1\Tools\mingw530_32\bin\g++.exe \
-Wl,-rpath,C:\Qt\Qt5.9.1\5.9.1\mingw53_32\bin \
-o test release\main.o -LC:\Qt\Qt5.9.1\5.9.1\mingw53_32\bin -lQt5Core

Build library libtorrent debian and link it to program c++

I always have problems when building libraries and linking them, so I hope someone can give me a hand.
I downloaded libtorrent from here and I've built it like they explain here in the building with autotools section (skipping step 1). The building process was successfull I think, but when I did make check the output was:
============================================================================
Testsuite summary for libtorrent-rasterbar 1.0.5
============================================================================
# TOTAL: 0
# PASS: 0
# SKIP: 0
# XFAIL: 0
# FAIL: 0
# XPASS: 0
# ERROR: 0
============================================================================
Maybe it should say: total X?
I did a little program where I added #include <libtorrent/session.hpp> and when I compile with g++ file.cpp -o file it says libtorrent/session.hpp: No such file or directory.
Should I add some flags to g++ such as -lpthread for other projects and thinks like that?
Thanks
UPDATE:
When installing without building using sudo apt-get install libtorrent-rasterbar-dev and compiling my main.cpp file I get this error:
g++ main.cpp -o file
In file included from /usr/include/libtorrent/session.hpp:49:0,
from main.cpp:2:
/usr/include/libtorrent/config.hpp:46:2: error: #error you must define either BOOST_ASIO_SEPARATE_COMPILATION or BOOST_ASIO_DYN_LINK in your project in order for asio's declarations to be correct. If you're linking dynamically against libtorrent, define BOOST_ASIO_DYN_LINK otherwise BOOST_ASIO_SEPARATE_COMPILATION. You can also use pkg-config or boost build, to automatically apply these defines
#error you must define either BOOST_ASIO_SEPARATE_COMPILATION or BOOST_ASIO_DYN_LINK in your project in \
UPDATE 2:
Modified the main.cpp file to add the the following above the libtorrent #include directives:
#ifndef BOOST_ASIO_DYN_LINK
#define BOOST_ASIO_DYN_LINK
#endif
But then I have this problem:
$ g++ main.cpp
/tmp/ccM2ItFb.o: In function `main':
main.cpp:(.text+0x57): undefined reference to `libtorrent::default_storage_constructor(libtorrent::file_storage const&, libtorrent::file_storage const*, std::string const&, libtorrent::file_pool&, std::vector<unsigned char, std::allocator<unsigned char> > const&)'
main.cpp:(.text+0xb9): undefined reference to `libtorrent::session::~session()'
main.cpp:(.text+0x105): undefined reference to `libtorrent::session::~session()'
/tmp/ccM2ItFb.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x162): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x16e): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x17a): undefined reference to `boost::system::system_category()'
main.cpp:(.text+0x192): undefined reference to `boost::asio::error::get_netdb_category()'
main.cpp:(.text+0x19e): undefined reference to `boost::asio::error::get_addrinfo_category()'
main.cpp:(.text+0x1aa): undefined reference to `boost::asio::error::get_misc_category()'
/tmp/ccM2ItFb.o: In function `boost::asio::error::get_system_category()':
main.cpp (.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
/tmp/ccM2ItFb.o: In function `libtorrent::session::session(libtorrent::fingerprint const&, int, unsigned int)':
main.cpp:(.text._ZN10libtorrent7sessionC2ERKNS_11fingerprintEij[_ZN10libtorrent7sessionC5ERKNS_11fingerprintEij]+0x3c): undefined reference to `libtorrent::rel_clocktime_pools_nolog_resolvecountries_deprecated_dht_ext_()'
main.cpp:(.text._ZN10libtorrent7sessionC2ERKNS_11fingerprintEij[_ZN10libtorrent7sessionC5ERKNS_11fingerprintEij]+0x75): undefined reference to `libtorrent::session::init(std::pair<int, int>, char const*, libtorrent::fingerprint const&, int, unsigned int)'
/tmp/ccM2ItFb.o: In function `void boost::checked_delete<libtorrent::torrent_info const>(libtorrent::torrent_info const*)':
main.cpp:(.text._ZN5boost14checked_deleteIKN10libtorrent12torrent_infoEEEvPT_[_ZN5boost14checked_deleteIKN10libtorrent12torrent_infoEEEvPT_]+0x1a): undefined reference to `libtorrent::torrent_info::~torrent_info()'
collect2: error: ld returned 1 exit status
Also tried compiling using: g++ -I /usr/include/ -L /usr/local/lib -lboost_system -lpthread -lboost_thread main.cpp with the same result.
UPDATE 3:
I was able to solve the problem. I had to compile using:
g++ -I /usr/include/ -L /usr/local/lib -lboost_system -lpthread -lboost_thread main.cpp and add also the link library -ltorrent-rasterbar
Sounds like you've compiled the library but not actually installed it anywhere. An #include directive looks in /usr/include by default, but the libtorrent headers are somewhere in the directory where you built the library. You'll need to either install the library's files into the system directories, or give the compiler an -I option pointing to the libtorrent build directory. (You'll probably also need an -L option when linking, for the same reason.)

Using Crypto++ static library in a QT project

I have built cryptopp statically on my system it passes all tests too. These are the warning though I get during tests
WARNING: CRYPTOPP_NO_UNALIGNED_DATA_ACCESS is not defined in config.h.
WARNING: CRYPTOPP_INIT_PRIORITY is not defined in config.h.
WARNING: CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 is defined in config.h.
WARNING: You should make these changes in config.h, and not CXXFLAGS.
WARNING: You can 'mv config.recommend config.h', but it breaks versioning.
WARNING: See http://cryptopp.com/wiki/config.h for more details.
I now link this in my QT project file as
TEMPLATE = app
LIBS += -L/usr/lib/libcryptopp.a
#LIBS += -lcryptopp
CONFIG += console c++11
CONFIG += staticlib
SOURCES += main.cpp \
hashdata.cpp
HEADERS += \
hashdata.hpp
But when I compile this I get all undefined errors.
hashdata.o: In function `hashdata::hashfunction(std::string)':
hashdata.cpp:(.text+0x1fb): undefined reference to `CryptoPP::Algorithm::Algorithm(bool)'
hashdata.cpp:(.text+0x270): undefined reference to `CryptoPP::SHA512::InitState(unsigned long long*)'
hashdata.cpp:(.text+0x29a): undefined reference to `CryptoPP::Algorithm::Algorithm(bool)'
hashdata.cpp:(.text+0x2a1): undefined reference to `vtable for CryptoPP::StringSinkTemplate<std::string>'
hashdata.cpp:(.text+0x30b): undefined reference to `CryptoPP::Filter::Filter(CryptoPP::BufferedTransformation*)'
hashdata.cpp:(.text+0x312): undefined reference to `vtable for CryptoPP::Grouper'
hashdata.cpp:(.text+0x35e): undefined reference to `CryptoPP::Filter::Detach(CryptoPP::BufferedTransformation*)'
hashdata.cpp:(.text+0x375): undefined reference to `CryptoPP::Filter::Filter(CryptoPP::BufferedTransformation*)'
hashdata.cpp:(.text+0x37c): undefined reference to `vtable for CryptoPP::BaseN_Encoder'
hashdata.cpp:(.text+0x3d3): undefined reference to `CryptoPP::Filter::Detach(CryptoPP::BufferedTransformation*)'
hashdata.cpp:(.text+0x3e5): undefined reference to `CryptoPP::ProxyFilter::ProxyFilter(CryptoPP::BufferedTransformation*, unsigned long, unsigned long, CryptoPP::BufferedTransformation*)'
hashdata.cpp:(.text+0x3ec): undefined reference to `vtable for CryptoPP::HexEncoder'
hashdata.cpp:(.text+0x452): undefined reference to `vtable for CryptoPP::AlgorithmParametersTemplate<int>'
hashdata.cpp:(.text+0x4af): undefined reference to `vtable for CryptoPP::AlgorithmParametersTemplate<CryptoPP::ConstByteArrayParameter>'
...
I have seen a similar problem previously when I searched in google, but the solution isn't clear. Could it be because of C++11 flags ?
I have built cryptopp statically on my system it passes all tests too.
These are the warning though I get during tests
WARNING: CRYPTOPP_NO_UNALIGNED_DATA_ACCESS is not defined in config.h.
WARNING: CRYPTOPP_INIT_PRIORITY is not defined in config.h. WARNING:
CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 is defined in config.h.
WARNING: You should make these changes in config.h, and not CXXFLAGS.
WARNING: You can 'mv config.recommend config.h', but it breaks
versioning. WARNING: See http://cryptopp.com/wiki/config.h for more
details.
I can comment on this warning. You should perform the steps it says:
mv config.recommend config.h
config.recommend puts the library is a better configuration by completely avoiding known undefined behavior that could not be removed without breaking versioning. Since you don't appear to have versioning issues (like say, Fedora or Debian), then you can perform the move.
I now link this in my QT project file as
TEMPLATE = app
LIBS += -L/usr/lib/libcryptopp.a
#LIBS += -lcryptopp
CONFIG += console c++11
...
When you build Crypto++, you should use the same compiler and flags for the library and app. I suggest the following.
Crypto++:
# Be sure to 'mv config.recommend config.h'
export CXXFAGS="-DNDEBUG -g2 -O3 -std=c++11"
make static dynamic test
Qt App
# main.pro file
QMAKE_CXXFLAGS += -DNDEBUG -g2 -O3
Also see GNUmakefile | Building the Library on the Crypto++ wiki.
hashdata.o: In function `hashdata::hashfunction(std::string)':
hashdata.cpp:(.text+0x1fb): undefined reference to `CryptoPP::Algorithm::Algorithm(bool)'
hashdata.cpp:(.text+0x270): undefined reference to `CryptoPP::SHA512::InitState(unsigned long long*)'
...
These are coming from source (*.cpp) files. I'm guessing (and its purely a guess) one of two problems:
C++03 vs C++11 is causing missing symbols
QT Creator is not using libcryptopp.a
Use nm to inspect the symbols. Something like the following (the ' T " tells you its defined and in the text section):
$ nm libcryptopp.a 2>/dev/null | c++filt | \
grep 'Algorithm::Algorithm(bool)' | grep ' T '
0000000000000060 T CryptoPP::Algorithm::Algorithm(bool)
0000000000000070 T CryptoPP::Algorithm::Algorithm(bool)
If the symbols are present by QT Creator is not finding the Crypto++ library, then see something like Adding external library into Qt Creator project.
From Comments:
-lcryptopp works, but I don't know why -L/usr/lib/libcryptopp.a doesn't. ... Because if a person had both static and dynamic libraries, I still don't know how to force linking static ones.
An archive, like libcryptopp.a, is a collection of object files. You add it to OBJECTS, not LIBS, so you want something like:
# main.pro file
OBJECTS += /usr/lib/libcryptopp.a
You use -L to specify a library path to a linker. It does not make much sense to -L/usr/lib/libcryptopp.a since its used for paths.
Additional note is that when both the static and dynamic libs were present it was automatically linking the dynamic lib. Do you know how to force static linking ?
On Linux, you can force static linking by either (1) -Bstatic -lcryptopp; or (2) directly specifying /usr/lib/libcryptopp.a. The Crypto++ test program uses method (2):
g++ main.cpp /usr/lib/libcryptopp.a -o main.exe
On OS X, the linker always links to the dynamic object. It even does so on iOS, where userland is usually not allowed to load dynamic objects. To avoid dynamic linking, either (1) move or rename the *.dylib; or (2) directly specifying /usr/lib/libcryptopp.a. The Crypto++ test program uses method (2):
g++ main.cpp /usr/lib/libcryptopp.a -o main.exe

Qt Creator: Release build won't compile

I've written a relatively simple Qt program that I'm trying to compile for windows with MinGW under Qt Creator. The Debug version builds and runs without problem, but when I try to build the Release version I get these errors
main.cpp:-1: error: undefined reference to `_imp___ZN12QApplicationC1ERiPPci'
main.cpp:-1: error: undefined reference to `_imp___ZN7QWidget4showEv'
main.cpp:-1: error: undefined reference to `_imp___ZN12QApplication4execEv'
main.cpp:-1: error: undefined reference to `_imp___ZN12QApplicationD1Ev'
main.cpp:-1: error: undefined reference to `_imp___ZN12QApplicationD1Ev'
:-1: error: release/main.o: bad reloc address 0x13 in section `.eh_frame'
collect2.exe:-1: error: error: ld returned 1 exit status
The errors seem to suggest that one or more of the core Qt libraries cannot be found, however, the .pro file contains the line QT += core gui widgets and there is nothing Debug/Release specific. I've tried cleaning/rebuilding the project and restarting Qt Creator, to no avail. I have no problems compiling Release builds for other projects. I'm using Qt version 5.2.1. Any ideas?
Update:
I've singled out this line in the .pro file as the cause
win32: LIBS += -L"C:/Program Files (x86)/MATLAB/R2015b/bin/win32" -llibmat -llibmx
Inside the makefile I see this
LIBS = -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmain "-LC:/Program Files (x86)/MATLAB/R2015b/bin/win32" -llibmat -llibmx -LC:\Qt\Qt5.2.1\5.2.1\mingw48_32\lib -lQt5Widgets -lQt5Gui -lQt5Core
I suspect the problem lies in the order in which the link libraries are listed in the makefile. I vaguely recall encountering a similar problem in the past. How can I force qmake to place the Matlab libraries at the end of the list?