Compile OpenNN with Qt in Windows and Mingw 5.30 - qt

Im trying to compile the openNN Project with Qt.
Im using qt precompiled mingw32 for windows and the last opennn 3.1 projekt sources.
Opennn comes already with .pro Project files for direct use with qt creator/qmake.
However when i try to compile it i get the following errors:
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0xfc): undefined reference to `omp_get_num_threads'
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0x103): undefined reference to `omp_get_thread_num'
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0x22f): undefined reference to `GOMP_loop_dynamic_start'
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0x3d3): undefined reference to `GOMP_loop_dynamic_next'
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0x3e0): undefined reference to `GOMP_loop_end_nowait'
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0x64b): undefined reference to `GOMP_loop_dynamic_start'
it seems to be connected to openmp, however the *.pro files of opennn already contain the always suggested lines:
QMAKE_CXXFLAGS+= -fopenmp
QMAKE_LFLAGS += -fopenmp
trying to add the following didnt help either
LIBS+= -fopenmp
i need to make it work with qt, because i wanted to add it to an already existing qt project later.

solution:
edit in openn/tests/tests.pro
and the "exampletitle".pro file of each example in openn/examples/"exampletitle"/
change:
win32-g++{
QMAKE_LFLAGS += -static-libgcc
QMAKE_LFLAGS += -static-libstdc++
QMAKE_LFLAGS += -static
}
to
win32-g++{
QMAKE_LFLAGS += -static-libgcc
QMAKE_LFLAGS += -static-libstdc++
QMAKE_LFLAGS += -static
LIBS += -fopenmp
}

Related

Qt error: undefined reference to 'QDebug::~QDebug()'

I am compiling my code with caffe, opencv 3.1 and Qt5.6. Following is my .pro file. I have not included the actual source and header file names here.
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = outsideSituationDetection
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
<and others>
HEADERS += mainwindow.h \
< and others >
FORMS += mainwindow.ui
DEFINES += CPU_ONLY
QMAKE_CXXFLAGS += -std=c++11 -Wall -D_REENTRANT -D__STDC_CONSTANT_MACROS -pthread
QMAKE_CXXFLAGS += -DQT_COMPILING_QSTRING_COMPAT_CPP -DQT_COMPILING_QIMAGE_COMPAT_CPP
CONFIG += link_pkgconfig
PKGCONFIG += opencv
INCLUDEPATH += /usr/local/include /usr/local/lib /usr/lib
DEPENDPATH += /usr/local/include
LIBS += -L/usr/local/lib/ -lopencv_imgproc
LIBS += -lm -lglib-2.0 -lgthread-2.0 -lxml2 -pthread
INCLUDEPATH += /usr/include/glib-2.0
INCLUDEPATH += /usr/lib/x86_64-linux-gnu/glib-2.0/include
INCLUDEPATH += /usr/include/libxml2
INCLUDEPATH += /usr/include/ \
/usr/lib/x86_64-linux-gnu/ \
LIBS += -L/usr/lib/x86_64-linux-gnu/ -lglog -lpthread -lm -lrt -ldl -lnsl
DEPENDPATH += /usr/lib/x86_64-linux-gnu/
# BOOST Library
LIBS += -L/usr/lib/x86_64-linux-gnu/ -lboost_system
INCLUDEPATH += /usr/lib/x86_64-linux-gnu
#Caffe for CPU System
INCLUDEPATH += $$PWD/../../../../../src/caffe/build/include \
$$PWD/../../../../../src/caffe/include \
$$PWD/../../../../../src/caffe/build
unix:!macx: LIBS += -L$$PWD/../../../../../src/caffe/build/lib/ -lcaffe -lglog
INCLUDEPATH += $$PWD/../../../../../src/caffe/build
DEPENDPATH += $$PWD/../../../../../src/caffe/build
RESOURCES += icons.qrc
Problem - When I compile the code, I get a bunch of 'error: undefined reference to 'QDebug::~QDebug()'' errors along with 'error: undefined reference to `QDebug::putString(QChar const*, unsigned long)'' against all of my .cpp files. (I have successfully built and executed another application without errors using Qt5.6 and Qt5.7.)
(.qtversion[qt_version_tag]+0x0):-1: error: undefined reference to `qt_version_tag' File not found (.qtversion[qt_version_tag]+0x0) in main.o
What I have tried - Check Qt version to make sure I am using Qt5.6. Deleted the installed qt5-default by doing 'sudo apt-get remove qt5-default'. Downgraded from Qt5.7 to Qt5.6 although it didn't make any difference. I have deleted qt4 and qt5 folders from /usr/include and /usr/share.
Can you please suggest what I might be missing?
I had multiple declarations of ' #include "QDebug" ' in files. Removing them and having it in only one file removed the error. (edit- it's incorrect and doesn't work)
What worked - Though I had removed older versions of Qt 3, 4 & 5 , qt was internally using 5.2.1 versions. I do not know where they came from. But when I deleted them all in /usr/lib/x86_linux_gnu/, the code compiled! I also specified the paths to the installed directory explicitly in qtchooser/default.conf. This may not be the best way to do but it worked anyway.

QtOpengl conflict with Opengl framwork on mac

I am trying to merge cocos2d-x 3.12 and Qt 5.7 together and was keep getting the conflict error message when linking:
In file included from Qt5.7.0/5.7/clang_64/lib/QtOpenGL.framework/Headers/QGLWidget:1:
In file included from Qt5.7.0/5.7/clang_64/lib/QtOpenGL.framework/Headers/qgl.h:45:
In file included from Qt5.7.0/5.7/clang_64/lib/QtGui.framework/Headers/qopengl.h:124:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl3.h:2704:21: error: conflicting types for 'glDepthRange'
GLAPI void APIENTRY glDepthRangef (GLclampf n, GLclampf f);
^
demo/cocos2d-x/cocos/platform/mac/CCGL-mac.h:43:41: note: expanded from macro 'glDepthRangef'
#define glDepthRangef glDepthRange
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl3.h:1662:21: note: previous declaration is here
GLAPI void APIENTRY glDepthRange (GLclampd near, GLclampd far);
I tried to remove the Opengl Framework in .pro file like this :
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QtApplication
TEMPLATE = app
#INCLUDEPATH += /usr/local/include
#LIBS += -L/usr/local/lib/ -lGLEW
LIBS += -L/usr/local/lib/ -lz
LIBS += -L/usr/local/lib/ -lcurl
LIBS += -framework Cocoa
LIBS += -framework Foundation
LIBS += -framework OpenAL
LIBS += -framework IOKit
LIBS += -framework CoreVideo
LIBS += -framework OpenGL
But it was not working, still the same error.
Any advice will be appreciated, thanks :)
I assume this error arises due to Qt's policy of overwriting OpenGL-related macro definitions as provided by glew.h or GL.h. Others have tried to deal with this and encountered similar problems (e.g. GLEW and Qt5 redefinition of headers). The workaround that got it going for me was to avoid including GL.h/glew.h and any Qt header related to OpenGL in the same file.

Importing Libraries into QTCreator

I am creating an OpenGL project in QT Creator, and would like to import GLFW and potentially other libraries later on.
I compiled and imported GLFW and was able to import it via
#include <GLFW/glfw3.h>
Qt Creator was even able to autofill the glfw methods. However, when I attempted to call one of them (e.g. glfwInit();, the compiler threw me the following error:
Undefined symbols for architecture x86_64:
"_CFArrayAppendValue", referenced from:
_addJoystickElement in libglfw3.a(iokit_joystick.m.o)
"_CFArrayApplyFunction", referenced from:
__glfwInitJoysticks in libglfw3.a(iokit_joystick.m.o)
_addJoystickElement in libglfw3.a(iokit_joystick.m.o)
"_CFArrayCreateMutable", referenced from:
... etc
I'm assuming it was unable to find the implementation of these methods.
I imported GLFW through the following procedure:
1. I used CMake to build a Unix Script. 2. I ran "make" in terminal on the generated makefile. This created a file called "libglfw3.a" 3. I imported the library into the project through QT, setting the Library as libglfw3.a and include path as "mypath/include/" (this folder contains another folder called GLFW, which contains glfw3.h).
QT Creator then entered the following into the QT project file.
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/glfw-3.1.1/src/release/ -lglfw3
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/glfw-3.1.1/src/debug/ -lglfw3
else:unix: LIBS += -L$$PWD/glfw-3.1.1/src/ -lglfw3
INCLUDEPATH += $$PWD/glfw-3.1.1/include
DEPENDPATH += $$PWD/glfw-3.1.1/include
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/release/libglfw3.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/debug/libglfw3.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/release/glfw3.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/debug/glfw3.lib
else:unix: PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/libglfw3.a
Help would be greatly appreciated. I've spent at least 10 hours trying to figure out how to import a GL library into QT Creator, but all I can find are CMake tutorials for XCode, Visual Studio, etc.
I would ideally like to this by just modifying the QT .pro file, because I don't have experience with CMake, but if there are no alternatives, that's fine.
I'm developing with QT creator on Mac 10.10.15.
If anyone's curious, I figured it out.
I followed the procedure here: Compiling with GLFW3, linker errors 'undefined reference'
I didn't at first think this was relevant because it was specifically referring to building on XCode, but it turns out you have to do the exact same thing with QT Creator.
right click the project, Import Library -> System/Library/Frameworks -> and import Cocoa, CoreVideo, and IOKit.
My .pro file had the following lines added to them after I did all that
mac: LIBS += -framework Cocoa
else:unix|win32: LIBS += -lCocoa
mac: LIBS += -framework IOKit
else:unix|win32: LIBS += -lIOKit
mac: LIBS += -framework CoreVideo
else:unix|win32: LIBS += -lCoreVideo

Error linking static boost_filesystem library with Qt Creator

I am getting an error when trying to link a static boost_filesystem library with QMake.
I know that my boost install is working, because I can link to it no problem outside of QMake like this:
g++ -o my_file my_file.cpp -IC:\boost_1_55_0\boost_1_55_0 -LC:\boost_1_55_0\boost_1_55_0\stage\lib -lboost_system -lboost_filesystem
I tried linking Qt with boost_filesystem like this at first, but it seems that it could not find the libraries:
LIBS += -LC:\boost_1_55_0\boost_1_55_0\stage\lib -lboost_system -lboost_filesystem
"-lboost_system not found -lboost_filesystem not found"
I read something about how you need to specify absolute paths to static libs when using QMake, so I've changes my LIBS line in my .pro to the following:
LIBS += "C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a" \
"C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a"
The libraries are found with this method, however I get the following error message:
undefined reference to boost::system::generic_category()
I was under the impression that this error only happen when boost_system isn't linked! I seems like it is linked though, because it finds the proper library for it, and I know my install of boost is good because the same library links fine (with the same compiler) outside of Qt Creator.
Here's the include in mainwindow.h:
include <boost/filesystem.hpp>
Here the full .pro:
QT += core gui
QT += network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QMAKE_CXXFLAGS += -std=c++11
TARGET = Downloader
TEMPLATE = app
INCLUDEPATH += C:\boost_1_55_0\boost_1_55_0
LIBS += "C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a" \
"C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a"
SOURCES += main.cpp\
mainwindow.cpp\
rar_process.cpp\
HEADERS += mainwindow.h\
rar_process.h\
FORMS += mainwindow.ui
RESOURCES += \
graphics.qrc
And here's the full compiler output:
C:\Qt\Qt5.1.1\5.1.1\mingw48_32\bin\qmake.exe -spec win32-g++ -o Makefile ..\qt- downloader\Downloader.pro
C:/Qt/Qt5.1.1/Tools/mingw48_32/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Users/Patrick/Desktop/cpp/build-Downloader- Desktop_Qt_5_1_1_MinGW_32bit-Release'
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\Downloader.exe release/main.o release/mainwindow.o release/rar_process.o release/qrc_graphics.o release/moc_mainwindow.o release/moc_rar_process.o -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmain C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a - LC:\Qt\Qt5.1.1\5.1.1\mingw48_32\lib -lQt5Widgets -lQt5Network -lQt5Gui -lQt5Core
release/main.o:main.cpp:(.text.startup+0x1a): undefined reference to `boost::system::generic_category()'
release/main.o:main.cpp:(.text.startup+0x24): undefined reference to `boost::system::generic_category()'
Makefile.Release:86: recipe for target 'release\Downloader.exe' failed
c:/qt/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686- w64-mingw32/bin/ld.exe: release/main.o: bad reloc address 0x24 in section `.text.startup'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [release\Downloader.exe] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/Patrick/Desktop/cpp/build-Downloader- Desktop_Qt_5_1_1_MinGW_32bit-Release'
makefile:34: recipe for target 'release' failed
GCC is very sensitive to the order in which you specify libraries during the linking stage. For example, if libA.a depends on libB.a and an executable App depends on both, then you'd have to invoke linker in the following way:
gcc main.o object1.o ... object2.o -lA -lB -o App
This implies that you have to change it to:
LIBS += "C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a" \
"C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a"
To be cross-platform, it's recommended to make your build more robust:
Boost_VERSION = 1_55
COMPILER = mgw48
win32-g++* {
LIBS += $$(Boost_DIR)/stage/lib/libboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION}.a \
$$(Boost_DIR)/stage/lib/libboost_system-$${COMPILER}-mt-$${Boost_VERSION}.a
PRE_TARGETDEPS += $$(Boost_DIR)/stage/lib/libboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION}.a \
$$(Boost_DIR)/stage/lib/libboost_system-$${COMPILER}-mt-$${Boost_VERSION}.a
}
linux-g++* {
LIBS += -L$$(Boost_DIR)/stage/lib -lboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION} \
-lboost_system-$${COMPILER}-mt-$${Boost_VERSION}
PRE_TARGETDEPS += $$(Boost_DIR)/stage/lib/libboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION}.a \
$$(Boost_DIR)/stage/lib/libboost_system-$${COMPILER}-mt-$${Boost_VERSION}.a
}
NOTE: Boost_DIR would be treated as an environment variable here. So that you can flexibly build it on any system without hardcoding the system-dependent path to Boost. This is general practice in professional software development: try to hardcode as little as possible in your build system, whatever it is. Furthermore, it's reasonable to even make Boost_VERSION environment variable too. All you'd have to change then, are brackets to parentheses, i.e. $${Boost_VERSION} to $$(Boost_VERSION).
Finally, notice that I've used forward slash / as a path separator for both Windows and Linux. Backward slash \ is not only deprecated in QMake, but it is also discouraged in general. Once again, be cross-platform: simply let QMake handle the conversion.
Apparently boost-system will not link against mingw gcc 4.8.0 if it was built with mingw gcc 4.8.1.
I re-built boost with mingw gcc 4.8.0 and linked against those libs, and now it works!

Wt with Qt, .pro settings

I am trying to get Wt working with Qt. I have installed 1.47 boost library, compiled Wt (3.2.1) under Windows using cmake 2.8.8. Tired simple hello world but doesn't compile, getting undefined reference errors for example:
undefined reference to `Wt::WApplication::WApplication(Wt::WEnvironment const&, Wt::WtLibVersion)'
Here is my .pro file:
QT -= core
QT -= gui
INCLUDEPATH += ../../../lib/Wt/include \
../../../lib/boost_1_47 \
../../../lib/Wt/src
LIBS += -L../../../lib/Wt/lib \
-L../../../lib/boost_1_47/lib
win32:LIBS += -lwthttpd -lwtd -lboost_regex-vc100-mt-1_47
TARGET = HttpServerWt
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
This is the program I am trying to compile:
http://www.webtoolkit.eu/wt/src/hello
Probably, your WT libraries will be added to /usr/loca/lib by default. so specify link libraries accordingly[after checking whether its present there, else check in /usr/lib and include accordingly].
Set LIBS Variable as follows
LIBS += -L/usr/local/lib -lwtd -lwthttpd -lboost_regex-vc100-mt-1_47
I don't see any Problem in setting the INCLUDEPATH variable in your post.
And also make sure that you are adding the module corresponding to Wt::WApplication::WApplication(Wt::WEnvironment const&, Wt::WtLibVersion) in LIBS Variable.
For more look here.
I think you need more libraries, because in Ubuntu you need to add more than two libraries to compile a wt code with qt creator.
Here is my *.pro file
QT += core
QT -= gui
TARGET = prueba3
LIBS += -L/usr/lib -lwt -lwthttp -I/usr/local/include
LIBS += -L/usr/local/lib -lwthttp -lwt -lboost_regex -lboost_signals
LIBS += -lboost_system -lboost_thread -lboost_filesystem -lboost_date_time
#QMAKE_CXXFLAGS += -DNDEBUG
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
and it compiles/Build great, finally you must add this line to run settings(ctrl+5)
--docroot . --http-address 0.0.0.0 --http-port 9090

Resources