link OpenGL to Qt Creator under Mac osx - macos

I'm trying to link OpenGL to my Qt .pro file. I've installed the SDL Library properly and this is my .pro file :
QT += opengl
INCLUDEPATH += /Library/Frameworks/SDL.framework/Versions/A/Headers
LIBS += -framework Cocoa -framework SDL
LIBS += -F/Library/Frameworks
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
HEADERS += \
SDLMain.h
OBJECTIVE_SOURCES += \
SDLMain.m
The problem is that #include <GL/gl.h> and #include <GL/glu.h> are still not find by the QtCreator. The error message is:
/Users/Anass/testsdl/main.cpp:42: erreur : 'GL/glu.h' file not found
Can you help me ?

Well, you have to add the OpenGL framework as well if you want to use OpenGL.

These are not the correct header file names on Mac OS:
#include <GL/gl.h>
#include <GL/glu.h>
On Mac OS, for headers that are part of a framework, the first part of the include file name is the name of the framework. This is OpenGL in this case. Therefore, the include statements need to be:
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
Also make sure that you link the OpenGL framework by adding -framework OpenGL to the link options.

Related

Setting up Qt Creator 3.3.2 and openCV 2.4.11 on Windows

I have a configuration problem while compiling and building a program with Qt Creator and the imageprocessing library openCV on my Windows machine. OpenCV worked some time ago with Visual Studio, but now I want to build programs with Qt Creator. I am working with opencv-2.4.11 and Qt Creator 3.3.2
I started a new program and tried to compile the following code:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.h>
using namespace std;
using namespace cv;
int main()
{
cout << "Hello World!" << endl;
Mat Bild;
return 0;
}
This building process ends with the errors:
C:...\build-Test01-Desktop_Qt_5_4_1_MinGW_32bit-Debug\debug\main.o:-1: In function ZN2cv3MatD1Ev':
C:\opencv\build\include\opencv2\core\mat.hpp:278: Fehler: undefined reference tocv::fastFree(void*)'
C:...\build-Test01-Desktop_Qt_5_4_1_MinGW_32bit-Debug\debug\main.o:-1: In function ZN2cv3Mat7releaseEv':
C:\opencv\build\include\opencv2\core\mat.hpp:367: Fehler: undefined reference tocv::Mat::deallocate()'
collect2.exe:-1: Fehler: error: ld returned 1 exit status
My .pro file includes the “INCLUDEPATH” and the “LIBS”:
INCLUDEPATH += C:\opencv\build\include\ \
C:\opencv\sources\include\
LIBS += -L C:\opencv\build\x86\vc12\lib\
-lopencv_core2411\
-lopencv_calib3d2411\
-lopencv_highgui2411\
-lopencv_imgproc2411\
SOURCES += main.cpp
What am I doing wrong – why do I always get an error :( ?
I tried also different other ways to define the include folders and libs, but I was not able to compile the testcode.
Regards
matl
You are using MinGW compiler and OpenCV extraction doesn't contain libraries built by it. So, you'll have to manually build them using MinGW provided by Qt. Use the following post for help:
How to link opencv in QtCreator and use Qt library
Make sure you have all the environment variables for Qt, MinGW and OpenCV libraries set properly. With all these done you should be all set.
Hope this helps.

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.

Can't use C++11 features when building with Qt

I'm on OS X 10.8.4 (Mountain Lion) with the latest command line tools from Xcode. I'm trying to build a Qt project (in Qt Creator) which uses some C++11 features; notably std::unique_ptr. Whenever I try building though, I get the following error:
clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)
My .pro file is as follows:
QT += core gui
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7 -std=c++11 -stdlib=libc++
LIBS += -mmacosx-version-min=10.7 -stdlib=libc++
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = APPNAME
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
cache()
I've tried the solutions presented in other answers (see here and the top answer here), neither of which seemed to work.
According to this site add
CONFIG += c++11
to your .pro file (see at the bottom of that web page). It requires Qt 5.
UPDATE: As for Qt 4, see How to enable C++11 in Qt Creator?

include GLUT in qt project with cmake

I'm trying to do a cmake project with opengl and qt.
this is the cmake where I include opengl:
# opengl
set(QT_USE_QTOPENGL TRUE)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
set(OPENGL_LIBS ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
And it found them, this is a part of cmake output:
-- Found OpenGL: /System/Library/Frameworks/OpenGL.framework
-- Found GLUT: -framework GLUT
And I can include OpenGL with this:
#include <QtOpenGL>
with this it finds correctly gl* glGetString(GL_VENDOR) or glGetString(GL_VERSION) and they works.
BUT I'm not able to include GLUT includes.
I'm on Mac OSX 10.8.4, Qt 4.8, QtCreator 2.7.1 and Opengl 2.1
Please note that the same cmake file under Ubuntu 12.04 let me include GL/gl.h and GL/glut.h correctly.
BUT I'm not able to include GLUT includes.
Why would you want to use GLUT when you're already using Qt?
GLUT is a framework for window creation and event loop processing.
Qt is a framework for window creation and event loop processing.
You can't (well, should not) have two framework within the same program doing the exact same thing (unless you're interested in seeing them fighting some battle over the same resources).
On OSX you need to include GLUT/glut.h, so write something like that in your code:
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

mingw32 linker error when including QDebug

I have this minimal example:
QT -= gui
CONFIG += qt console
SOURCES += main.cpp
#include <QDebug>
int main(int argc, char** argv)
{
return 0;
}
which gives this link error when building the project:
c:/qtsdk/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: final link failed: Invalid argument
The link command looks like this:
g++ -Wl -Wl -Wl,-subsystem,console -mthreads -o debug\test.exe debug/main.o -L"c:\QtSDK\Desktop\Qt\4.8.1\mingw\lib" -lQtCored4
My setup:
Windows XP SP3
Qt SDK version 1.2.1 (QtCreator 2.4.1, Qt Desktop version 4.8.1) (fresh install at C:\QtSDK\)
MinGW32 version 4.4.0 (included in Qt SDK at C:\QtSDK\mingw\)
If I remove the #include <QDebug>, it compiles fine. If I include some other Qt header file, like for example QCoreApplication, it compiles fine, too.
EDIT: Here is a very strange minimal example. Consider an empty main function like above. Now if i put these includes, it fails to link:
#include <QWidget>
#include <QVariant>
But if I remove one of them, it links without an error.
What's the problem? Why doesn't mingw tell me what the invalid argument is?
Im wondering is the linker could not find the lQtCored4 lib? Is it actually in the -L directory?

Resources