How to link OpenGL to a QT application on Win32? - c++

I have a sample QT application with the following raw OpenGL calls (not with QGLFunctions):
#define GL_GLEXT_PROTOTYPES
#include <QtOpenGL/QtOpenGL>
GLuint positionBuffer = 1;
glDeleteBuffers(1, &positionBuffer);
glClearColor(0, 1, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
In Windows desktop configuration I get the following linker errors:
error LNK2019: unresolved external symbol _glDeleteBuffers#8 referenced in function "public: void __thi
scall OsgViewer::beforeRendering(void)" (?beforeRendering#OsgViewer##QAEXXZ) [D:\Repos\build\geoviewer\GeoViewer.vcxpro
j]
It is noteworthy that glClearColor and glClear are linked successfully. I tried both QMake and CMake with the same result.
My QMake file is:
QT += qml quick opengl
CONFIG += c++11
DEFINES += GL_GLEXT_PROTOTYPES
#see https://stackoverflow.com/questions/31688370/qt-5-5-with-qmake-linker-cannot-resolve-opengl-function-calls
#LIBS += -llibEGLd.lib -llibGLESv2d.lib
LIBS += opengl32.lib glu32.lib
VERSION = 1.0.11
DEFINES += VERSION_STRING=\\\"$$VERSION\\\"
SOURCES += main.cpp \
squircle.cpp
#Icon files are added in the same way as in quickcontrols2\gallery\ sample
RESOURCES += qml.qrc
HEADERS += \
squircle.h
It links fine (to ANGLE) with 'LIBS += -llibEGLd.lib -llibGLESv2d.lib' but with 'LIBS += opengl32.lib glu32.lib' it does not.
My CMake file contains:
find_package(OpenGL)
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
it finds glu32 and opengl32 and corresponding DLLs exist in C:/Windows/System32, but I have an impression that opengl32.dll supports some old version of OpenGL, because it has glDeleteLists, but does not have glDeleteBuffers:
so if I have old OpenGL libraries, the question is where to get new libraries?
Qt5OpenGL.dll has QGLFunctions::glDeleteBuffers, but does not have raw glDeleteBuffers:
It is interesting that OpenGLES DLL has all the functions:

Related

Qt 5.3.1 - static building results in linker errors

I just built the static libraries from Qt 5.3.1 for Windows x86 with MSVC 2013. The second step is obviously a static linked application that uses these libraries. So I created a small application (just a MainWindow with some controls, for testing purposes). This is my *.pro-file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = projectname
TEMPLATE = app
CONFIG += static
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
LIBS += -LC:\statics\lib\ -lQt5Core \
-LC:\statics\lib\ -lQt5Gui \
-LC:\statics\lib\ -lQt5Widgets \
-LC:\statics\lib\ -lqtmain \
-LC:\statics\lib\ -lQt5PlatformSupport \
INCLUDEPATH += C:\statics\include
Yeah. This is what I got from several tutorials/my memory from when I worked with 5.1. But when compiling I get those errors:
Qt5Core.lib(Qt5Core.dll):-1: error: LNK2005: "public: __thiscall QString::~QString(void)" (??1QString##QAE#XZ) allready defined in mainwindow.obj.
mainwindow.obj:-1: error: LNK2019: Unresolved extern symbol ""public: static struct QArrayData const * const QArrayData::shared_null" (?shared_null#QArrayData##2QBU1#B)" in Funktion ""public: __thiscall QString::QString(void)" (??0QString##QAE#XZ)".
moc_mainwindow.obj:-1: error: LNK2001: Unresolved extern symbol ""public: static struct QMetaObject const QMainWindow::staticMetaObject" (?staticMetaObject#QMainWindow##2UQMetaObject##B)".
Does somebody know how to handle these errors? Do I have to link against some other libraries not mentioned above, or include some files? I googled this topic and found out that many people experienced the same problem, but they mostly use older versions of Qt oder VS. I also tried to export the project to Visual Studio (working from Qt Creator), but the errors remain.
Thank you for your answers :)
QT += core gui
LIBS += -LC:\statics\lib\ -lQt5Core \
-LC:\statics\lib\ -lQt5Gui \
You are loading both Qt libraries twice: default and custom versions. By default, QT contains both core and gui libraries... you must delete them manually:
QT -= core gui
Just remove LIBS, INCLUDEPATH from project file and run qmake from static build on the project file to create makefile. If this will not help check your PATH

Sha512 hash in QT via OpenSSL

I'm trying to use the Sha512 function in openSSL but can't seem to get it to work as I get compiler errors just starting into the code. I include #include <openssl/sha.h> at the top of the .cpp file, then in the action of a button event I put just the following code below.
SHA512_CTX ctx;
SHA512_Init(&ctx);
//Will uncomment below in later if I get SHA512_Init to work
//SHA512_Update(&ctx, string, strlen(string));
//SHA512_Final(digest, &ctx);
I get a linker error telling my undefined symbols for architecture x86_64, implying the function does not exist?
I'm aware QT 5 has a hash function, but I'm limited to QT 4.8 so I can not use the cryptographic sha512 hash function available in the QT 5+ framework.
Any help is appreciated!
Used macports to install openssl
I'm using Mac OS 10.9.2
MAKE FILE
#-------------------------------------------------
#
# Project created by QtCreator 2014-06-11T20:27:49
#
#-------------------------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ExchangeTab
TEMPLATE = app
LIBS += -L/usr/include/openssl -openssl
INCLUDEPATH += /usr/include/openssl
SOURCES += main.cpp\
mainwindow.cpp \
httpsocket.cpp \
cloaksend.cpp \
exchange.cpp
HEADERS += mainwindow.h \
httpsocket.h \
cloaksend.h \
exchange.h
FORMS += mainwindow.ui
RESOURCES += \
AppResources.qrc
Looking for cross platform solution please.
You need to link to the right library (openSSL)
Have a look here: How to Include OpenSSL in a Qt project
Specifically, add this to your .pro file.:
LIBS += -L/opt/local/lib/ -lcrypto
For including .h files add this line to your .pro file :
INCLUDEPATH += /opt/local/include
[1] says that the default include path will be /opt/local/include/.
LIBS += -L/usr/include/openssl -openssl
INCLUDEPATH += /usr/include/openssl
This looks incorrect. The OpenSSL libraries are libcrypto (-lcrypto) and libssl (-lssl). There is nolibopenssl(-lopenssl). Try:
LIBS += -L/usr/lib -lcrypto
INCLUDEPATH += /usr/include/openssl
But the libraries are version 0.9.8. You might consider upgrading to 1.0.1h.
$ ls /usr/lib | grep crypto
libcrypto.0.9.7.dylib
libcrypto.0.9.8.dylib
libcrypto.dylib
libk5crypto.dylib
And
$ /usr/bin/openssl version
OpenSSL 0.9.8y 5 Feb 2013
If you choose to upgrade, OpenSSL will install into /usr/local/ssl. Avoid mixing/matching version of OpenSSL with the following.
INCLUDEPATH += /usr/local/ssl/include/openssl
LIBS += /usr/local/ssl/lib/libcrypto.a
Its OK to specify objects and archives in LIBS. See How to add object files to a project in Qt.
Okay so I may have answered my own question but I will need some help understanding why it worked.
My make file was indeed the problem. I added the following 3 lines.
INCLUDEPATH += $$OPENSSL_INCLUDE_PATH
LIBS += $$join(OPENSSL_LIB_PATH,,-L,)
LIBS += -lcrypto
Then it magically compiled just fine. I found these in another project made with QT that compiled for OpenSSL.
Interestingly enough. I removed the top two lines so only the following remained. Then ran the clean on my project to be sure the code was being recompiled.
LIBS += -lcrypto
This also just 'worked' without linker errors. It looks like that is the only command I need. Question is... will that be cross platform friendly if I take this code and compile on linux or windows? That I am not sure, but this worked.

Configure Qt Creator to use TBB on Windows [duplicate]

I have compiled TBB from source using Mingw following the comment #5 in this post: http://software.intel.com/en-us/forums/topic/291331. That went ok.
When I try to use the new TBB library in a QtCreator project, I end with this errors (ignore the warning messages): http://postimage.org/image/yrrecugix/
Here's the sample code I tried (I omit the non-tbb code):
#include "tbb/task_scheduler_init.h"
int main()
{
tbb::task_scheduler_init init;
/// more things.
}
And here's the .pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp
#QMAKE_CXXFLAGS += -fopenmp
#QMAKE_LFLAGS += -fopenmp
INCLUDEPATH += "E:\TRABAJO\LIBRERIAS\tbb-4.1_src\include"
LIBS += -L"E:\TRABAJO\LIBRERIAS\tbb-4.1_src\build\windows_intel64_gcc_mingw4.5.4_debug\" \
-ltbb_debug
Any idea?.
Thanks!.
When built with MinGW on Windows, TBB binaries are tbb.dll and tbb_debug.dll. The option -ltbb_debug in your configuration files probably causes the linker to look for libtbb_debug.<something>. It can't find such a binary and reports about unresolved symbols.

Qt C++ ffmpeg cannot find library

I use Qt 5.0.2 with Mingw 4.7 on windows.
I'm working on a c++ program and i'm trying to get the duration of video files. I found ffmpeg. Now i tried to compile a simple program but I think it fails with the libraries. I've tried to include both the shared and dev but they both will fail. ( Zeranoe FFmpeg builds)
This is my pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
INCLUDEPATH += C:\programming\ffmpeg-20130606-git--win32-shared\bin
LIBS += -LC:\programming\ffmpeg-20130606-git--win32-shared\bin -lavcodec-55.dll - lavformat-55.dll -lavutil-52.dll
i get errors like:
":-1: error: cannot find -lavcodec-55.dll"
":-1: error: cannot find -lavformat-55.dll"
I've also tried:
INCLUDEPATH += C:\programming\ffmpeg-20130606-git--win32-dev\include
INCLUDEPATH += C:\programming\ffmpeg-20130606-git--win32-dev\lib
LIBS += -LC:\programming\ffmpeg-20130606-git--win32-dev\lib -lavcodec -lavformat -lavutil
LIBS += -LC:\programming\ffmpeg-20130606-git--win32-dev\lib -llibavcodec.dll.a -llibavformat.dll.a -llibavutil.dll.a
Here it gives a error "During startup program exited with code 0x0000135'
I even tried to include each library individually. But no results..
This is my main file:
#include <iostream>
using namespace std;
extern "C" {
#include <libavcodec/avcodec.h> // required headers
#include <libavformat/avformat.h>
}
int main(int argc, char**argv) {
av_register_all(); // offending library call
return 0;
}
A program simple as this will have 2 outcomes:
the program runs but crashes if i call 'av_register_all()'
It just tells me he cannot find the libraries.
Can someone tell me what it is i'm doing wrong? Or even give me a hint? I can't really find a lot of good documentation on this one.
Thanks in advance!
Configure PRO-file as shown below:
INCLUDEPATH += C:\programming\ffmpeg-20130606-git--win32-dev\include
LIBS += -LC:\programming\ffmpeg-20130606-git--win32-dev\lib
LIBS += -lavcodec -lavformat -lavutil
Then, build the project, copy the all dll libraries from C:\programming\ffmpeg-20130606-git--win32-shared\bin to exe output path and run application.
UPD
Maybe you need to copy some of the following libraries from Qt\5.0.2\mingw47_32\bin\:
libgcc_s_sjlj-1.dll
libstdc++-6.dll
libwinpthread-1.dll

QMake and wxWidgets (External Libraries)

I'm trying to compile a GUI program based on the wxWidgets libraries. I get a lot of undefined references to "something". I tried to add a few libraries manually on the LIBS variable of QMake without success. How can i add all the wxWidgets libraries to QMake without hard coding each library? Below is my .pro file.
# simple.pro
TARGET = sample
HEADERS += main.h simple.h
SOURCES += main.cpp simple.cpp
LIBS += -LC:/SourceCode/Libraries/wxWidgets2.8/lib/gcc_dll/wxmsw28_core_gcc.dll \
-LC:/SourceCode/Libraries/wxWidgets2.8/lib/gcc_dll/wxmsw28_gcc.dll \
-LC:/SourceCode/Libraries/wxWidgets2.8/lib/gcc_dll/wxmsw28_aui_gcc.dll
INCLUDEPATH += C:/SourceCode/Libraries/wxWidgets2.8/include
CONFIG += release
The errors are of the form:
release/simple.o:simple.cpp:(.rdata$_ZTV6Simple[vtable for
Simple]+0x320): undefined reference to
`wxFrameBase::SetStatusBar(wxStatusBar*)'
First, you need to use the .a files to add to the linker.
Then you need to define WXUSINGDLL if you link against the shared libraries.
Additionally, you forgot
wxbase29u.a
Hope that helps.