Compiling google test framework with Mingw compiler - windows

I have a Qt project and i wanted to use google tests framework GoogleTestFramework in order to do google test. The framework compiled fine on Linux.
I have managed to compile the libraries on windows, using tips provided in the following link:
Installing Gtest without pthreads
The following advice do not let me compile the libraries, because of errors due to pthreads:
Sackoverflow compiling with MSYS
I have :
GNU Make 3.81 for make.exe
GNU Make 3.82 for mingw32-make
CMake 2.8.7
QT 4.7.4
Qt MingW gcc v 4.4.0
When i try to compile my test projet, i get an error saying:
undefined reference to '__chkstk_ms'
File not found: gtest-all.cc
Here is my qmake project code (I have semplified the code).
QT += core gui
DEPENDPATH += . headers src ../FastTrans/headers ../FastTrans/src ../FastTrans/forms C:/MinGW/msys/1.0/home/zakharan/gtest-1.6.0/include
INCLUDEPATH += . headers src ../FastTrans/headers ../FastTrans/src ../FastTrans/forms C:/MinGW/msys/1.0/home/zakharan/gtest-1.6.0/include
TARGET = tstall
#CONFIG += console
#CONFIG -= app_bundle
TEMPLATE = app
HEADERS += ../FastTrans/headers/shortcutsactionsitem.h \
../FastTrans/headers/shortcutsactionsmodel.h \
../FastTrans/headers/isavesettings.h
SOURCES += ../FastTrans/src/shortcutsactionsitem.cpp \
../FastTrans/src/shortcutsactionsmodel.cpp \
../FastTrans/src/isavesettings.cpp \
src/tstshortcutsactionsitem.cpp \
src/tstshortcutsactionmodel.cpp
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
win32: LIBS += C:/MinGW/msys/1.0/home/zakharan/gtest-1.6.0/mybuid/libgtest.a
win32: LIBS += C:/MinGW/msys/1.0/home/zakharan/gtest-1.6.0/mybuid/libgtest_main.a

Google recommends the following for compiling in Windows:
### Windows Requirements ###
* Microsoft Visual C++ 7.1 or newer
### Cygwin Requirements ###
* Cygwin 1.5.25-14 or newer
I've heard of some people using MingW for compiling this. Supposedly compiling with MingW can be a little faster because there doesn't need to be a comparability layer between the OS and the application.
But, since this is just for dev testing purposes Cygwin should suffice. Just download the version that Google recommends.
See Also:
Compile Cygwin project in Eclipse
How Cygwin compares to MingW for porting Linux applications to Windows

Related

OpenCV libraries not found in Qt5 on OSX 10.10

I am currently trying to use OpenCV in a Qt project. When I build it, i get the error:
error: 'opencv2/opencv.hpp' file not found
#include <opencv2/opencv.hpp>
I know that there are many similar questions out there in the web, but none of the answers was actually able to fix my problem so far.
My specifications:
Qt 5.4.0 (Clang 6.0 (Apple), 64 bit)
Mac OSX 10.10.1
OpenCV 2.4.9 installed from homebrew
My .pro file looks like this:
QT += core gui multimedia multimediawidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MainProject
TEMPLATE = app
SOURCES += main.cpp mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/include/opencv2
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_ml
LIBS += -lopencv_video
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
LIBS += -lopencv_objdetect
LIBS += -lopencv_contrib
LIBS += -lopencv_legacy
LIBS += -lopencv_flann
I made sure the links actually link to the right locations. All the header files and all the .dylib files are there as well. I checked the type of the libraries:
$ file libopencv_core.dylib
libopencv_core.dylib: Mach-O 64-bit dynamically linked shared library x86_64
In my project settings, the qmake command is:
qmake: qmake MainProject.pro -r -spec macx-clang CONFIG+=debug CONFIG+=x86_64
Unfortunately I only have a basic understanding of these compile-things, so I am not too sure, whether it has something to do with clang? I read something about clang behaving somehow different on OSX 10.10 Yosemite, but I did not completely understand why. Info about my clang:
$ clang --version
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
I also tried to use the gcc-kit in Qt (GCC x86 64bit in /usr/bin), but this messed up a lot more, which I did not understand.
Does somebody have an idea what I am doing wrong? Any help appreciated!
Patrick
You are already including the directory opencv2 in your #include statement. You should change your include path to just INCLUDEPATH += /usr/local/include.

How to install OpenCV with Visual Studio 2012 (64 bit) on Windows 7?

I'm following this guide to install OpenCV for Qt: http://www.laganiere.name/opencvCookbook/chap1s1_2.shtml. But this tutorial is made for Qt with mingw32 compiler kit.
Kindly suggest me the steps to install it on Visual Studio 2012 on Windows 7 64bit (with or without cmake).
You need to select your compiler not MinGW.
You then specify the compilers that will generate the project. In our case, they are the compilers of MinGW installed by default by Qt.
You need to select 64 bit Visual Studio 11.0. And when you finish configuration and click generate button cmake is going to generate you a solution file, all you need to do is open that solution file and compile it.
Use this guide http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html. If you will have problems with building Qt 5.x, use Qt 4.x - it's much easier to build it.
Ok, I was able to solve this problem by following the guide mentioned by cyriel:http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html.
And adding following lines to myproject.pro file:
INCLUDEPATH += C:\OpenCV\build\include
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_core244.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_highgui244.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_imgproc244.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_calib3d244.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_calib3d244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_contrib244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_core244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_features2d244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_flann244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_gpu244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_highgui244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_imgproc244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_legacy244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_ml244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_nonfree244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_objdetect244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_photo244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_stitching244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_ts244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_video244d.lib
LIBS += C:\OpenCV\build\x64\vc11\lib\opencv_videostab244d.lib
By doing this, there is no need for additional compilation again by vsc2012. It also saves hard disk space. And anyone will be able to run their opencv project written in Qt5.1.

Multicore compilation with Qt 5.1 and jom on Windows 7 failed

I have installed Qt 5.1.1 with MinGW 4.8 and QtCreator through Qt Online installer.
I launched Qt creator and made new project (Qt application Desktop) with MainWindow class based on QMainWindow (default). It works fine and popped up a mainwindow after compilation.
However, when I used C:\Qt\Qt5.1.1\Tools\QtCreator\bin\jom.exe instead of C:\Qt\Qt5.1.1\Tools\mingw48_32\bin\mingw32-make.exe , I got some output like below.
jom 1.0.13 - empower your cores
C:\Qt\Qt5.1.1\Tools\QtCreator\bin\jom.exe -f Makefile.Release
g++ -c -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../foobar -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include' -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtWidgets' -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtGui' -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtCore' -I'release' -I'.' -I'.' -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/mkspecs/win32-g++' -o release/main.o ../foobar/main.cpp
In file included from ../foobar/main.cpp:1:0:
../foobar/mainwindow.h:4:23: fatal error: QMainWindow: No such file or directory
#include <QMainWindow>
^
compilation terminated.
jom: D:\work\build-foobar-Desktop_Qt_5_1_1_MinGW_32bit-Release\Makefile.Release [release\main.o] Error 1
jom: D:\work\build-foobar-Desktop_Qt_5_1_1_MinGW_32bit-Release\Makefile [release] Error 2
15:17:38: Process "C:\Qt\Qt5.1.1\Tools\QtCreator\bin\jom.exe" stopped with code 2
Error while building/deploying project foobar (kit: Desktop Qt 5.1.1 MinGW 32bit)
During step 'Make'
15:17:38: Elapsed time: 00:00.
My .pro is like this.
#-------------------------------------------------
#
# Project created by QtCreator 2013-09-08T15:16:13
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = foobar
TEMPLATE = app
SOURCES += main.cpp\ mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I think the line in .pro greaterThan(QT_MAJOR_VERSION, 4): QT += widgets and in the output during compilation -I'C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtWidgets' looks fine, but failed.
How can I compile with Qt 5.1 and jom on Windows 7 (32 bit)?
Thanks in advance.
Jom is a replacement of nmake and not MinGW's make.
nmake is the Visual Studio command line tool used to compile makefiles. Unfortunately that tool is using only one core (Parallel builds are handled inside Visual Studio either directly or using MSBuild, I'm not really sure). That being said, Jörg Bornemann wrote a tool called jom that sort of adds the -j command to nmake. It will allow you to compile your code using the Visual C++ compiler across different threads.
MinGW on the other end contains (amongst other things) a port of the GNU GCC compiler for Windows. Being a port, not everything that is possible to do with GCC is possible with MinGW and I guess that -jN is one of these. However, MinGW do support the option -j that will spawn as many processes as it can (beware that if you use this option, you may not be able to use your computer whilst compiling).
In your case, you probably want to use MinGW as your Qt version is compiled with it. If you want to use Visual Studio, you will have to install it but also either:
recompile Qt (and all other library dependencies) or
download the binary corresponding to the Visual Studio version you just installed.
Using jom should just work with QtCreator once this is done.
In my case I fixed this error by overriding system environment PATH in project settings by adding only bin path to qt, mingw and qtcreator: "E:\Qt\4.8.1\bin;E:\qt\mingw-4.4.0\bin;E:\Qt\qtcreator-4.0.0\bin" and after Run qmake and Rebuild

Qt5, Visual Studio 2012 Express and OpenMp. How to?

I am trying to compile http://www.kevinbeason.com/smallpt/ raytracer using Qt5 and Visual Studio 2012 compiler.
It works Okay but when I try to use openmp by adding
QMAKE_CXXFLAGS += -fopenmp
LIBS += -fopenmp
to project.pro
, Qt says that /fopenmp is not recognized and ignored.
When I compile using VS command
cl /c /O2 /EHsc /openmp main.cpp
it works and I get a program 3 times faster then the one compiled from Qt.
How to make Qt recognize openmp and how to enable the other optimizations in the command line?
Thanks in advance.
I finally got all the required elements to get it compiled with openmp from Qt Creator:
Add #include <omp.h> to the source, which is not required if you compile with
the command line mentioned above.
Add QMAKE_CXXFLAGS += -openmp to the project file. It wont work
with -fopenmp. No need for any openmp lib like I did ( LIBS += -openmp ) neither for QMAKE_LFLAGS += -openmp
Compile as release. With debug it has no impact on performance.
The other optimization options are already configured in mkspecs\win32-msvc2012\
qmake.conf
Hope this helps someone else.
I want to run Qt project with openmp. I have followed the above steps, I could build the project, but execution time is increasing instead of reducing.
Here is the configuration I used
CONFIG += console c++11
CONFIG -= app_bundle
#CONFIG -= qt
QMAKE_CXXFLAGS+= -openmp

How can I force qtcreator to create non-universal binaries

When I use qtcreator on mac, it creates universal binaries.
Does anyone know how to set it so it just creates a 'native' binary? (So i386' in my case?)
Qtcreator uses qmake as a buildsystem.
Google hasn't been my friend so far, I hope stackoverflow will.
EDIT:
my config file so far:
TARGET = mongowriter
CONFIG += console
CONFIG -= app_bundle
CONFIG += x86
#CONFIG -= ppc
TEMPLATE = app
INCLUDEPATH += /opt/local/include/.
INCLUDEPATH += ../mongodb/.
SOURCES += main.cpp
LIBS += /usr/local/lib/libmongoclient.a
LIBS += /opt/local/lib/libboost_thread-mt.a
LIBS += /opt/local/lib/libboost_filesystem.a
LIBS += /opt/local/lib/libboost_program_options.a
It still gives the error on the libmongoclient.a
The libboost libraries are all ok, but this is because I got them from macports with the +universal option.
Since mongoclient doesn't support universal I'm currently removing all the universal stuff. I was hoping to get 3 errors for the boost libs and that at l;east mongoclient would link.
At that point I could redo the whole macport story again but this time with universal removed.
Unfortunately it seems it still builds a universal binary since I still have the same linker errors.
thanks for the help
you can use the 'CONFIG' variable in your project file to specify which plattforms shall be supported to create a universial binary you use
CONFIG += x86 ppc
if you only need x86 you use
CONFIG += x86

Resources