Boost_program_option linker error even "boost_program_options" exist - c++

I have defined boost_program_options in qmake file .
> CONFIG(debug, debug|release) {
> LIBS += -L"C:\boost_1_55_0\stage\lib" -lboost_program_options-mgw48-mt-d-1_55 -lboost_system-mgw48-mt-d-1_55 -lboost_thread-mgw48-mt-d-1_55 }
CONFIG(release, debug|release) {
> LIBS += -L"C:\boost_1_55_0\stage\lib" -lboost_program_options-mgw48-mt-1_55 -lboost_system-mgw48-mt-1_55 -lboost_thread-mgw48-mt-1_55 }
I want to use a library which called mlpack . And compiled it with the help of mingw.
When I add
"#include <mlpack/core.hpp>"
I am having tones of linker errors( I am pasting a few for ease of read. ):
C:/Qt/Tools/QtCreator/bin/aubioSecond/libs//libmlpack.a(cli.cpp.obj):cli.cpp:(.text+0x3ed): undefined reference to `boost::program_options::options_description::m_default_line_length'
C:/Qt/Tools/QtCreator/bin/aubioSecond/libs//libmlpack.a(cli.cpp.obj):cli.cpp:(.text+0x41e): undefined reference to `boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)'
C:/Qt/Tools/QtCreator/bin/aubioSecond/libs//libmlpack.a(cli.cpp.obj):cli.cpp:(.text+0x43b): undefined reference to `boost::program_options::variables_map::variables_map()'
C:/Qt/Tools/QtCreator/bin/aubioSecond/libs//libmlpack.a(cli.cpp.obj):cli.cpp:(.text+0x486a): undefined reference to `boost::program_options::notify(boost::program_options::variables_map&)'
c:/qt/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe:
C:/Qt/Tools/QtCreator/bin/aubioSecond/libs//libmlpack.a(cli.cpp.obj): bad reloc address 0x2 in section `.text$_ZN5boost16exception_detail10clone_baseD1Ev[__ZN5boost16exception_detail10clone_baseD1Ev]'
If anyone has a idea why I am having this problem I will be very thankfull.
Regards

Gilles Barges reports on the mlpack mailing list that the linking error with boost_program_options can be resolved by modifying CMakeLists.txt, line 189, commenting out the bit
set(Boost_LIBRARIES "")
See the mailing list post for more information:
https://mailman.cc.gatech.edu/pipermail/mlpack/2014-August/000488.html

Related

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?

Qt - undefined reference to... (Ubuntu 14.04 LTS 64 bits)

I try to compile one of my project I made with windows 7 64 bits using Qt5.3.1 MSVC2012, by using now Qt5.4 gcc 64 bits with Unbuntu 14.04 LTS.
But I have some "undefined reference to" errors :
/home/innocore/Software/CES_2015/trunk/MainProgram/../bin//libSmartphoneController.a(smartphonecontroller.o): In function SmartphoneController::init()':
/home/innocore/Software/CES_2015/trunk/bin/../LibSmartphoneController/smartphonecontroller.cpp:11: undefined reference toRemoteADBInterface::RemoteADBInterface(QString, QString, int, QObject*)'
/home/innocore/Software/CES_2015/trunk/bin/../LibSmartphoneController/smartphonecontroller.cpp:13: undefined reference to RemoteADBInterface::newMessage(RemoteADBInterface::Message const&, QVariant const&)'
/home/innocore/Software/CES_2015/trunk/MainProgram/../bin//libSmartphoneController.a(smartphonecontroller.o): In functionQMetaObject::Connection QObject::connect(QtPrivate::FunctionPointer::Object const*, void (RemoteADBInterface::)(RemoteADBInterface::Message const&, QVariant const&), QtPrivate::FunctionPointer::Object const, void (SmartphoneController::*)(RemoteADBInterface::Message const&, QVariant const&), Qt::ConnectionType)':
/opt/5.4/gcc_64/include/QtCore/qobject.h:239: undefined reference to `RemoteADBInterface::staticMetaObject'
collect2: error: ld returned 1 exit status
my project is composed of one exe and several libraries like libSmartphoneController.a or libRemoteADB.a.
All the libraries compile correctly and are created in the right directory. The problem occurs when I compile my exe program (MainProgram).
In the .pro, I'm sure I include the right dependencies :
unix:!macx {
CONFIG(release, release|debug) {
LIBS += -L$$PWD/../Lib/ -lAudioPlayer -lDisplay -lSWCom -lRemoteADB -lDMS -lTVRemote \
-lHDMIMixer -lSmartphoneController -lRemoteServer
}
CONFIG(debug, release|debug) {
LIBS += -L$$PWD/../bin/ -lAudioPlayer -lDisplay -lSWCom -lRemoteADB -lDMS -lTVRemote \
-lHDMIMixer -lSmartphoneController -lRemoteServer
} }
The lib SmartphoneController also have two dependencies :
in SmartphoneController.pro :
unix:!macx {
CONFIG(release, release|debug) {
LIBS += -L$$PWD/../Lib/ -lRemoteADB -lRemoteServer
}
CONFIG(debug, release|debug) {
LIBS += -L$$PWD/../bin/ -lRemoteADB -lRemoteServer
} }
The problem is that it does not find the definition of some function in the lib RemoteADB (contructor, signal readMessage...). I don't have any problem with all other libs + it compiles perfectly on windows...
Any idea ?
Thanks in advance for your help
I see a possible cause for your problem: the compiler does not find the library file and you can solve this by adding in the .pro file the full path where you have saved the libraries, what I can see here is that you have different path where to search libraries if are compiling debug or release, are you sure you have the correct libraries in both places ?
This would be an example of what to put in your pro file:
LIBS += -L$$OUT_PWD/../../../projects/mylibs/release/

Errors while trying to compile OpenCV project on Dev C++

Im getting this error:
D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o Source2.cpp:(.text+0xdf): undefined reference to `cv::imread(std::string const&, int)'
D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o Source2.cpp:(.text+0xdec): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o Source2.cpp:(.text+0xe41): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
d:\devc\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o: bad reloc address 0x20 in section `.text$_ZSt4sqrtf[__ZSt4sqrtf]'
D:\devc\opencv\projekty\test 3 opencv\test 3 opencv\collect2.exe [Error] ld returned 1 exit status
What i did in Dev Options:
I have added this command line to compiler:
-L"C:\opencv\build\x86\vc11\lib" -lopencv_highgui248 -lopencv_core248 -lopencv_imgproc248 -lopencv_calib3d248 -lopencv_video248 -lopencv_features2d248 -lopencv_ml248 -lopencv_highgui248 -lopencv_objdetect248 -lopencv_contrib248 -lopencv_legacy248 -lopencv_flann248
This lane to linker options:
-static-libgcc -lopencv_highgui248 -lopencv_core248 -lopencv_imgproc248 -lopencv_calib3d248 -lopencv_video248 -lopencv_features2d248 -lopencv_ml248 -lopencv_highgui248 -lopencv_objdetect248 -lopencv_contrib248 -lopencv_legacy248 -lopencv_flann248
In directiories i have added:
binaries: D:\devc\opencv\build\x86\vc11\bin
libs: D:\devc\opencv\build\x86\vc11\lib
headers C: D:\devc\opencv\build\include\opencv2 D:\devc\opencv\build\include\opencv D:\devc\opencv\build\include
headers C++: same as above
I have added opencv path D:\devc\opencv to PATH variable
My dev C++ version is: 5.7.0, OpenCV: 2.4.8
Anyone know how to fix that?
EDIT
Same problem using CodeBlock
Did you link Source2 to collect2 properly? Source2.cpp should be compiled into an object file before linking with your main program.
If I am not mistaken, the problems are not related to linking libraries it is because imread and imwrite shouldnt be like you called
imread(string, mat)
But you called
imread(string, int)
So it gives error. Same with other lines.
Build the libraries using CMake and CodeBlocks as given in here till step 3 of codeblock settings.
Then include the following as given in the blog to Devc++ C and C++ Includes tab
C:\OpenCV\my_build\install\include
C:\OpenCV\my_build\install\include\opencv
C:\OpenCV\my_build\install\include\opencv2
since you have included opencv and opencv2, remove /opencv2/..and /opencv ..in the header files.
and add the below line to libraries in Devc++
C:\OpenCV\my_build\install\x64\mingw\lib
also add all the .dll.a files in C:\OpenCV\my_build\install\x64\mingw\lib to Project Options.
Copy all the dll files from opencv\my_build\install\x64\mingw\bin and paste to folder where EXE of your program would be built.

FLTK 1.3 Linking errors

I update my FLTK from 1.1 to 1.3, then I can't compile my code which is worked well before update.
...
[100%] Building CXX object CMakeFiles/PROSTVIEW.dir/include/nifti/vtkznzlib.cxx.o
Linking CXX executable PROSTVIEW
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `fontopen(char const*, int, bool, int)':
fl_font.cxx:(.text+0x298): undefined reference to `FcPatternCreate'
fl_font.cxx:(.text+0x362): undefined reference to `FcPatternAddString'
fl_font.cxx:(.text+0x3e3): undefined reference to `FcPatternAddString'
fl_font.cxx:(.text+0x3f7): undefined reference to `FcPatternAddInteger'
fl_font.cxx:(.text+0x40b): undefined reference to `FcPatternAddInteger'
fl_font.cxx:(.text+0x424): undefined reference to `FcPatternAddDouble'
fl_font.cxx:(.text+0x43c): undefined reference to `FcPatternAddString'
fl_font.cxx:(.text+0x4df): undefined reference to `FcMatrixRotate'
fl_font.cxx:(.text+0x4f7): undefined reference to `FcPatternAddMatrix'
fl_font.cxx:(.text+0x516): undefined reference to `FcPatternAddBool'
fl_font.cxx:(.text+0x52c): undefined reference to `FcPatternAddBool'
fl_font.cxx:(.text+0x549): undefined reference to `XftFontMatch'
fl_font.cxx:(.text+0x5a0): undefined reference to `XftFontOpen'
fl_font.cxx:(.text+0x5b0): undefined reference to `FcPatternDestroy'
fl_font.cxx:(.text+0x5f3): undefined reference to `XftFontOpenPattern'
fl_font.cxx:(.text+0x603): undefined reference to `FcPatternDestroy'
fl_font.cxx:(.text+0x659): undefined reference to `XftFontOpenXlfd'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `utf8extents(Fl_Font_Descriptor*, char const*, int, _XGlyphInfo*)':
fl_font.cxx:(.text+0x84b): undefined reference to `XftTextExtents32'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `fl_xft_width(Fl_Font_Descriptor*, unsigned int*, int)':
fl_font.cxx:(.text+0x98a): undefined reference to `XftTextExtents32'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `fl_destroy_xft_draw(unsigned long)':
fl_font.cxx:(.text+0x102e): undefined reference to `XftDrawChange'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `Fl_Xlib_Graphics_Driver::draw(char const*, int, int, int)':
fl_font.cxx:(.text+0x10c6): undefined reference to `XftDrawCreate'
fl_font.cxx:(.text+0x10f6): undefined reference to `XftDrawChange'
fl_font.cxx:(.text+0x1140): undefined reference to `XftDrawSetClip'
fl_font.cxx:(.text+0x1202): undefined reference to `XftDrawString32'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `fl_drawUCS4(Fl_Graphics_Driver*, unsigned int const*, int, int, int)':
fl_font.cxx:(.text+0x1313): undefined reference to `XftDrawCreate'
fl_font.cxx:(.text+0x1343): undefined reference to `XftDrawChange'
fl_font.cxx:(.text+0x138d): undefined reference to `XftDrawSetClip'
fl_font.cxx:(.text+0x1433): undefined reference to `XftDrawString32'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `Fl_Xlib_Graphics_Driver::rtl_draw(char const*, int, int, int)':
fl_font.cxx:(.text+0x1480): undefined reference to `FcUtf8Len'
fl_font.cxx:(.text+0x14ff): undefined reference to `FcUtf8ToUcs4'
collect2: ld returned 1 exit status
make[2]: *** [PROSTVIEW] Error 1
make[1]: *** [CMakeFiles/PROSTVIEW.dir/all] Error 2
make: *** [all] Error 2
Here's my CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
PROJECT(PROSTVIEW)
SET(CMAKE_BUILD_TYPE DEBUG)
SET(CMAKE_CXX__FLAGS -O3 -pipe -ffast-math -Wno-deprecated)
# Chargement Package
# FLTK
FIND_PACKAGE ( FLTK )
IF ( FLTK_FOUND )
INCLUDE_DIRECTORIES( ${FLTK_INCLUDE_DIR} )
ENDIF ( FLTK_FOUND )
# ITK
FIND_PACKAGE ( ITK )
IF ( ITK_FOUND )
INCLUDE( ${USE_ITK_FILE} )
ENDIF( ITK_FOUND )
# VTK
FIND_PACKAGE ( VTK )
IF ( VTK_FOUND )
INCLUDE( ${USE_VTK_FILE} )
ENDIF( VTK_FOUND )
SET(VTK_LIBRARIES vtkCommon vtkRendering vtkWidgets vtkGraphics vtkGenericFiltering vtkzlib)
# vtkFlRenderWindowInteractor
SET(VTKFL_INCLUDE_DIR "include/vtkfl")
SET(VTKFL_CPP
${VTKFL_INCLUDE_DIR}/vtkFlRenderWindowInteractor.cxx)
# Auxiliary_Tools
SET(AT_DIR "include/Auxiliary_Tools")
SET(AT_INCLUDE_DIR ${AT_DIR}/include)
SET(AT_LIBRARY_DIR ${AT_DIR}/lib)
#Nifty
SET(NII_DIR "include/nifti")
SET(NII_SRC
${NII_DIR}/vtkNIfTIReader.cxx
${NII_DIR}/vtkNIfTIWriter.cxx
${NII_DIR}/vtkAnalyzeReader.cxx
${NII_DIR}/vtkAnalyzeWriter.cxx
${NII_DIR}/vtknifti1_io.cxx
${NII_DIR}/vtkznzlib.cxx)
#Other include
SET(PROSTVIEW_INCLUDE_DIR "include")
SET(PROSTVIEW_SRC
${PROSTVIEW_INCLUDE_DIR}/ContourTmt.cpp
${PROSTVIEW_INCLUDE_DIR}/conversion.cpp
${PROSTVIEW_INCLUDE_DIR}/TmtMatrix.cpp)
# VOLUME Widget
SET(VOLUME_WIDGET_DIR "include/GUI")
SET(VOLUME_WIDGET
${VOLUME_WIDGET_DIR}/VOLUME_Loader.cpp
${VOLUME_WIDGET_DIR}/VOLUME_Widget.cpp
${VOLUME_WIDGET_DIR}/VOLUME_Mouse_Widget.cpp
${VOLUME_WIDGET_DIR}/VOLUME_3DView.cpp
${VOLUME_WIDGET_DIR}/CONTOUR_Loader.cpp
${VOLUME_WIDGET_DIR}/ProstView.cpp)
# MODULES
SET(MODULE_DIR "Module")
# SEGMENTATION
SET(SEGMENTATION_DIR "Module/Segmentation")
SET(SEGMENTATION
${SEGMENTATION_DIR}/DDC2D.cpp
${SEGMENTATION_DIR}/DDC3D.cpp
${SEGMENTATION_DIR}/DDC3DHu.cpp
${SEGMENTATION_DIR}/DDC3DPlus.cpp
${SEGMENTATION_DIR}/DDC3DBal.cpp
${SEGMENTATION_DIR}/IMAGE_ENERGY.cpp
${SEGMENTATION_DIR}/REGULARIZATION.cpp
${SEGMENTATION_DIR}/OPTIMAL_SURFACE_DETECTION.cpp
${SEGMENTATION_DIR}/OPTIMAL_MULTIPLE_SURFACES_DETECTION.cpp
${SEGMENTATION_DIR}/RESAMPLE_From_Prostate.cpp
${SEGMENTATION_DIR}/RECTAL_WALL_US.cpp
${SEGMENTATION_DIR}/BLADDER_MRI.cpp
${SEGMENTATION_DIR}/RECTUM_MRI.cpp
${SEGMENTATION_DIR}/REGION_GROWING.tpp )
#MESH
SET(MESH_DIR "Module/Mesh")
SET(MESH
${MESH_DIR}/GENERIC_MESH.cpp
${MESH_DIR}/ELLIPSOID_MESH.cpp
${MESH_DIR}/PROSTATE_MESH.cpp
${MESH_DIR}/TUBULAR_MESH.cpp
${MESH_DIR}/OPEN_MESH.cpp
${MESH_DIR}/QUADRIC_MESH.cpp
${MESH_DIR}/ELLIPTICAL_CYLINDER_MESH.cpp
${MESH_DIR}/CONTOURS_MAN_MESH.cpp)
#STUDY
SET(STUDY_DIR "Module/Statistics")
SET(STUDY
${STUDY_DIR}/PROFILE.cpp
${STUDY_DIR}/Histogram.cpp
${STUDY_DIR}/HISTOGRAM_FROM_MESH.cpp
${STUDY_DIR}/TRAINING_SET_ALIGNMENT.cpp
${STUDY_DIR}/APPEARANCE_MODEL.cpp)
# MOMENTS
SET(MOMENTS_DIR "Module/Moments")
SET(MOMENTS
${MOMENTS_DIR}/KRAWTCHOUK_Moments.tpp
${MOMENTS_DIR}/TCHEBICHEF_Moments.tpp
${MOMENTS_DIR}/GEOMETRIC_Moments.tpp)
#VALIDATION
SET(VALIDATION_DIR "Module/Evaluation")
SET(VALIDATION
${VALIDATION_DIR}/Metrics.cpp)
# Include et Link Directories
INCLUDE_DIRECTORIES(${FLTK_INCLUDE_DIR} ${VTK_INCLUDE_DIRS} ${VTKFL_INCLUDE_DIR} ${AT_INCLUDE_DIR} ${NII_DIR} ${PROSTVIEW_INCLUDE_DIR} ${VOLUME_WIDGET_DIR} ${MODULE_DIR})
LINK_DIRECTORIES(${FLTK_LIBRARY_DIR} ${VTK_LIBRARY_DIRS} ${AT_LIBRARY_DIR} ${PROSTVIEW_INCLUDE_DIR} ${VOLUME_WIDGET_DIR} ${MODULE_DIR})
# Sources
SET(SRC main.cpp)
# Executables and "stand-alone " librairies
ADD_EXECUTABLE(PROSTVIEW ${SRC} ${PROSTVIEW_SRC} ${VTKFL_CPP} ${VOLUME_WIDGET} ${SEGMENTATION} ${MESH} ${STUDY} ${MOMENTS} ${VALIDATION} ${NII_SRC})
# Linkage
TARGET_LINK_LIBRARIES(PROSTVIEW ${FLTK_LIBRARIES} ${VTK_LIBRARIES} ${ITK_LIBRARIES})
I tried to add some libs in my CMakeLists.txt, but it's not work. Who can tell me what’s the problem?
From FLTK 1.3's README.CMake.txt:
USING CMAKE WITH FLTK
This howto assumes that you have FLTK libraries which were built using
CMake, installed. Building them with CMake generates some CMake
helper files which are installed in standard locations, making FLTK
easy to find and use.
Here is a basic CMakeLists.txt file using FLTK.
cmake_minimum_required(VERSION 2.6)
project(hello)
find_package(FLTK REQUIRED NO_MODULE) include(${FLTK_USE_FILE})
add_executable(hello WIN32 hello.cxx)
target_link_libraries(hello fltk)
The find_package command tells CMake to find the package FLTK,
REQUIRED means that it is an error if it's not found. NO_MODULE tells
it to search only for the FLTKConfig file, not using the
FindFLTK.cmake supplied with CMake, which doesn't work with this
version of FLTK.
Once the package is found we include the ${FLTK_USE_FILE} which adds
the FLTK include directories and library link information to its
knowledge base. After that your programs will be able to find FLTK
headers and when you link the fltk library, it automatically links the
libraries fltk depends on.
It seems that from FLTK 1.1 to 1.3 they changed the method needed to find the library, maybe for comparability/testing reasons?
I got hung up on the same issue, hope someone finds this useful. :)

Problems compiling an c++ application using QT and OpenGL

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!