as the title indicates, I am trying to compile a simple project in Qt that makes use of the addressbook.pb.h/addressbook.pb.cc files that are generated in the google protobuf3 tutorial for C++ users. Here is my .pro file
#-------------------------------------------------
#
# Project created by QtCreator 2016-11-07T10:33:12
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = prototest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
../protobuf/examples/addressbook.pb.cc
HEADERS += mainwindow.h \
../protobuf/examples/addressbook.pb.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/Cellar/protobuf/3.1.0/include
LIBS += /usr/local/Cellar/protobuf/3.1.0
Unfortunately, this throws
:-1: error: can't map file, errno=22 file '/usr/local/Cellar/protobuf/3.1.0' for architecture x86_64
I'm stuck at this point. Any help would be greatly appreciated. I have been able to compile and run the exact same (addressbook.*) files using Xcode8.
Solved it: Add the following to the .pro file
macx: LIBS += -L$$PWD/../../../usr/local/Cellar/protobuf/3.1.0/lib/ -lprotobuf.11
INCLUDEPATH += $$PWD/../../../usr/local/Cellar/protobuf/3.1.0/include
DEPENDPATH += $$PWD/../../../usr/local/Cellar/protobuf/3.1.0/include
I should add how I arrived at this answer. Right click your project and select "Add Library->External Library", select your platform and enter your specific library (not path) that you want to add, and your include path (the options it gives you indicate such). Qt will generate the code and automatically add it to your .pro file.
Related
I am trying to compile a open source project on windows: https://github.com/francisengelmann/FabScan100
I am using QtCreator 2.7.0, Qt Qt5.0.2 msvc2010_opengl, MSVC2010
My direcotries look like this:
C:\
C:\libs\opencv-2.4.2\
C:\libs\pcl-1.6.0
C:\libs\Qt\Qt5.0.2
C:\fabscan\FabScan100-master
I modified the qtTest.pro file to include the neccessary headers and libs:
INCLUDEPATH += C:\libs\pcl-1.6.0\3rdParty\Eigen\include
LIBS += C:\libs\pcl-1.6.0\3rdParty\Eigen\bin
INCLUDEPATH += C:\libs\pcl-1.6.0\3rdParty\FLANN\include\flann
LIBS += C:\libs\pcl-1.6.0\3rdParty\FLANN\lib
INCLUDEPATH += C:\libs\pcl-1.6.0\3rdParty\Boost\include\boost
LIBS += C:\libs\pcl-1.6.0\3rdParty\Boost\lib
INCLUDEPATH += C:\libs\opencv-2.4.2\opencv\build\include
LIBS += C:\libs\opencv-2.4.2\opencv\build\x86\vc10\lib
INCLUDEPATH += C:\libs\pcl-1.6.0\include\pcl-1.6
LIBS += C:\libs\pcl-1.6.0\lib \
-lpcl_common \
-lpcl_io \
-lpcl_filters \
-lpcl_kdtree \
-lpcl_registration \
-lpcl_features \
-lpcl_segmentation \
-lpcl_surface \
-lpcl_search
But when I press the compile button QtCreator throws me an error:
..\qtTest\staticHeaders.h(4) : fatal error C1083: Cannot open include file: 'Eigen/Core': No such file or directory
Which is kind of strange because the file is actually there. I am also able to open it in QtCreator by pressing STRG & Clicking on the include statement in staticHeaders.h
Any ideas?
Based on the staticHeaders.h code (line 4), you need to have a folder called "Eigen" which contains the "Core" file. For instance, I have /usr/include/eigen2/Eigen/Core on Linux, in which case /usr/include/eigen2 has to be added to the INCLUDEPATH variable with qmake. Make sure you have C:\libs\pcl-1.6.0\3rdParty\Eigen\include.
Also, if it does not work in QtCreator as per your comment, you can always try to force explicitly to rerun qmake by the execute qmake option.
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.
I am not a C++ master (far from that actually), I try to setup an OpenCV + Qt project. I have downloaded the last release of OpenCV. I did nothing more with that (if I understand well, everything is pre-built, so I just have to add the path to the libs in my .pro file).
I added the path to the include folder /opencv/include
That should work that way, since the includes in cv.h, for example, are like that :
include "opencv2/core/core_c.h"
However, when I browse through my opencv folder, opencv2 is empty, there is no core folder in it, nor anything else, actually there is just a header file, opencv.h .
I noticed that all my include are spread into several folders, under the module folder... what should I do??
Thank you very much!
You have to add those libraries in .pro file module wise, means you have to add all modules you are using in the project to LIBS variable in .pro file. Say if you are using modules libopencv1, libopencv2, libopencv3
LIBS += -L/usr/lib -lopencv1 -lopencv2 -lopencv3
like that.
If opencv libraries are added to /usr/local/lib, use -L/usr/local/lib instead of -L/usr/lib
Here is my .pro file :
QT += core gui
TARGET = test_MTI880
TEMPLATE = app
SOURCES += ... ... ...
INCLUDEPATH += D:/PointGreyResearch/FlyCapture2/include \
+= D:/opencv/include
LIBS += D:/opencv/build/x86/vc10/lib/opencv_core240.lib \
D:/opencv/build/x86/vc10/lib/opencv_highgui240.lib \
D:/opencv/build/x86/vc10/lib/opencv_imgproc240.lib \
D:/opencv/build/x86/vc10/lib/opencv_objdetect240.lib \
D:/PointGreyResearch/FlyCapture2/lib/FlyCapture2.lib \
D:/PointGreyResearch/FlyCapture2/lib/C/FlyCapture2_C.lib \
D:/PointGreyResearch/FlyCapture2/lib/FlyCapture2d.lib \
D:/PointGreyResearch/FlyCapture2/lib/FC1/PGRFlyCapture.lib
OK I found the answer...
The right include folder is the one into the build folder ... -_-'
How do I make apps smaller with qmake and macdeployqt?
I have set QT = core gui in the projects .pro file and run qmake and macdeployqt on the resulting app.
The problem is that the program is bundling QtNetwork, QtScript, QtSvg etc. I've tried setting QT -= network script svg (and then make clean, rm -rf *.app, qmake, make).
In total the app is 32 MB.
.pro file:
TEMPLATE = app
TARGET = throw
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += x86_64 release
QT = core gui
unix {
CONFIG += link_pkgconfig
PKGCONFIG += glib-2.0
}
# Input
SOURCES += main.cpp
# Headers
HEADERS += throw.h
RESOURCES += throw.qrc
ICON = throw.png
mac {
QMAKE_INFO_PLIST = Info.plist
ICON = throw.icns
}
This is a great article about (re)building Qt statically and dynamically to reduce its size considerably: Building Qt Static (and Dynamic) and Making it Small with GCC, Microsoft Visual Studio, and the Intel Compiler
While this is talking about Qt in the windows context, it does give some good insight into how one would go about compiling for minimal size.
You could strip the binary afterwards in a post-build step. The Qt libraries themselves are shared by default.
I am having a problem with running an example from qt which uses win32 libraries. When I compile I don't get any errors but when I run it is not able to open the application (.exe) file in Windows 7. But when I compile this example in WindowsXP it works fine. Can anyone let me know whether I need to change my .pro file in order to get it worked under Windows 7?
Here is my .pro file:
# -------------------------------------------------
# Project created by QtCreator 2010-04-16T11:45:43
# -------------------------------------------------
QT += network
QT += xml
QT += opengl
TARGET = Application
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp \
Tools.cpp \
Objects.cpp
HEADERS += mainwindow.h \
Tools.h\
Objects.h
unix {
OBJECTS_DIR = .obj
MOC_DIR = .moc
}
# UNIX installation
isEmpty(PREFIX):PREFIX = /usr/local
unix {
headers.path = $$PREFIX/include/ZIP
headers.files = $$HEADERS
target.path = $$PREFIX/lib
INSTALLS += headers \
target
}
!mac:x11:LIBS += -ldns_sd
win32:LIBS += -ldnssd
LIBPATH = C:/Temp/mDNSResponder-107.6/mDNSWindows/DLL/Debug
INCLUDEPATH += c:/Temp/mDNSResponder-107.6/mDNSShared
You can use Dependency Walker to help you find out what Qt DLLs are needed and copy them to the same folder as the .exe.
Your problem is probably because Windows can't find the Qt libraries.
Try placing the required Qt libraries (for instance QtNetwork4.dll, etc...) in the same directory as your .exe and see if it works.