how do I create a Qt project option for linux only - qt

I know I can insert this to .pro file
win32 {
LIBS += libbreakpad_client.lib
}
so that the option is only used when building under windows.
How do I do same for linux? I tried both
linux-g++ {
LIBS += libbreakpad_client.a
}
linux {
LIBS += libbreakpad_client.a
}
but it works only in qt5-qmake on qt4 it doesn't work at all...

You can use unix:
unix {
message("Creating Makefile for UNIX ...")
LIBS += libbreakpad_client.a
}

Related

qmake: Use flags from pkg-config if they exist, otherwise use defaults

In my setup, I want to support both system-wide Qt installations and custom Qt installations. I can use pkg-config to get the correct compile and link flags for my system-wide installation:
CONFIG += link_pkgconfig
PKGCONFIG += Qt5Core
However, if pkg-config cannot find Qt5Core, the build will fail with Project ERROR: Qt5Core development package not found.
Instead of failing, I want to set reasonable defaults (e.g. /usr/local/qt5). It should achieve the following:
if pkg-config can find Qt5Core {
PKGCONFIG += Qt5Core
} else {
INCLUDEPATH += /usr/local/qt5/
LIBS += -lQt5Core
}
How can I accomplish this in my project configuration?
There is a qmake function for this:
http://doc.qt.io/qt-5/qmake-test-function-reference.html#packagesexist-packages
packagesExist(Qt5Core) {
PKGCONFIG += Qt5Core
} else {
INCLUDEPATH += /usr/local/qt5/
LIBS += -lQt5Core
}
You can use the system built-in test function which executes the given command in a secondary shell. Succeeds if the command returns with a zero exit status; otherwise fails.
system(pkg-config --exists Qt5Core) {
PKGCONFIG += Qt5Core
} else {
INCLUDEPATH += /usr/local/qt5/
LIBS += -lQt5Core
}

Qt 4.8.4 Creating release

I'm trying to build a release version of a project I'm working on. When building in Qt creator in Debug it works great. When I try building as release I get "cannot find -lQtSerialPort". Qt 4.8.4 does not include QtSerialPort. I had to add that manually. I'm assuming there is something I'm forgetting to include here. Possibly in the .pro file?
Also, I noticed in my Qt/4.8.4/lib directory I have many .prl files. There is one for QtSerialPortd.prl. This is the only one in here that seems to have a .dll version. Not sure if this is significant or not.
Makefile includes this:
Makefile: ???.pro
c:/Qt/4.8.4/mkspecs/features/serialport.prf \
$(QMAKE) -config release -o Makefile ???.pro
c:/Qt/4.8.4/mkspecs/features/serialport.prf:
serialport.prf looks like this:
qtAddLibrary(QtSerialPort)
!isEmpty(QTSERIALPORT_BUILD_ROOT) {
INCLUDEPATH -= $$QMAKE_INCDIR_QT/QtSerialPort
QMAKE_INCDIR += $$QTSERIALPORT_BUILD_ROOT/include $$QTSERIALPORT_BUILD_ROOT/include/QtSerialPort
QTSERIALPORT_BUILD_SUBDIR = src/serialport
debug_and_release_target {
CONFIG(debug, debug|release) {
QTSERIALPORT_BUILD_SUBDIR = $$QTSERIALPORT_BUILD_SUBDIR/debug
} else {
QTSERIALPORT_BUILD_SUBDIR = $$QTSERIALPORT_BUILD_SUBDIR/release
}
}
QMAKE_LIBDIR += $$QTSERIALPORT_BUILD_ROOT/$$QTSERIALPORT_BUILD_SUBDIR
}
mac {
LIBS -= -framework QtSerialPort$${QT_LIBINFIX}
if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
LIBS += -lQtSerialPort$${QT_LIBINFIX}_debug
} else {
LIBS += -lQtSerialPort$${QT_LIBINFIX}
}
}
Edit:
After figuring out I can change the name of the file by removing the d at the end, I realized that all the libraries included on the exe that is built include files that do not end in 'd.dll' with the exception of the QtSerialPortd.dll file.
I.E ldd on the debug .exe:
QtCored4.dll => /cygdrive/c/Qt/4.8.4/bin/QtCored4.dll (0x69cc0000)
QtGuid4.dll => /cygdrive/c/Qt/4.8.4/bin/QtGuid4.dll (0xf30000)
QtNetworkd4.dll => /cygdrive/c/Qt/4.8.4/bin/QtNetworkd4.dll (0x6cb40000)
QtSerialPortd.dll => /cygdrive/c/Qt/4.8.4/bin/QtSerialPortd.dll (0x63680000)
ldd on the release .exe:
QtCore4.dll => /cygdrive/c/Qt/4.8.4/bin/QtCore4.dll (0x6e0c0000)
QtGui4.dll => /cygdrive/c/Qt/4.8.4/bin/QtGui4.dll (0x67700000)
QtNetwork4.dll => /cygdrive/c/Qt/4.8.4/bin/QtNetwork4.dll (0x65c80000)
QtSerialPortd.dll => /cygdrive/c/Qt/4.8.4/bin/QtSerialPortd.dll (0x63680000)
Release vs Debug, it looks like the QtSerialPortd.dll remained the same. I'm guessing this is going to be problematic when I try this application on different machines.
I changed the name of Qt/4.8.4/lib/libQtSerialPortd.a to Qt/4.8.4/lib/libQtSerialPort.a. It builds now. Not sure if this is going to have adverse effects.

qmake CONFIG constains release and debug variable at the same time

I want to change some DEFINES and LIBS paths depending on Debug or Release build configuration, but my CONFIG variable constains release and debug variables at the same time.
Simple test in pro file:
CONFIG(debug, debug|release) {
message(DEBUG build)
}
CONFIG(release, debug|release) {
message(RELEASE build)
}
This test outputs:
Project MESSAGE: DEBUG build
Project MESSAGE: RELEASE build
How should I set up my project?
You should use this:
debug_and_release_target {
CONFIG(debug, debug|release) {
message("debug")
} else {
message("release")
}
}
This is what we use inside Qt as well, including QtSerialPort. Although we use this as well for Mac, just in case:
if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
LIBS += -lQtSerialPort$${QT_LIBINFIX}_debug
} else {
LIBS += -lQtSerialPort$${QT_LIBINFIX}
}

Undefined Referernce Errors FFMPEG + QT + Ubuntu 12.04.2 LTS

i have 2 machines with Ubuntu 12.04.2 LTS (64 mb) and the other is a snow leopard OS.
In my mac i work with ffmpeg without any trouble but then i try to use ffmpeg in ubuntu and 6700 (!) errors appear:
error: undefined reference to `av_freep'
error: undefined reference to `av_strstart'
error: undefined reference to `av_freep'
...
I use QT 4.8.5 and g++ x86 64b
I installed ffmpeg following http://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide without errors or warnings.
My test code is:
.h
QT += core gui
INCLUDEPATH += \
/usr/local/Include
LIBS += /usr/local/lib/libavcodec.a
LIBS += /usr/local/lib/libavutil.a
LIBS += /usr/local/lib/libavformat.a
LIBS += /usr/local/lib/libswscale.a
SOURCES += main.cpp
.cpp:
extern "C"
{
#ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS
#endif
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
}
#include <stdio.h>
int main()
{
AVFormatContext *pFormatCtx;
av_register_all();
const char* fil = "/home/cits/Desktop/movFile.mov";
if(avformat_open_input(&pFormatCtx, fil, NULL, NULL)!=0)
{
return -1; // Couldn't open file
}
if(avformat_find_stream_info(pFormatCtx, NULL)<0)
{
return -1; // Couldn't find stream information
}
return 0;
}
Any ideas??
Thanks in advance.
Your .pro file should read something like:
QT += core gui
INCLUDEPATH += \
/usr/local/Include
LIBS += -L/usr/local/lib/ -llibavcodec -llibavutil -llibavformat -llibswscale
SOURCES += main.cpp

How to create distro-specific conditional qmake project

Suppose I write code on 2 computers which runs different linux distros.
How to make qmake differ those two distros and assign specific LIBS for those two.
For instance;
unix: {
ubuntu*: {
LIBS += -lcxcore -lhighgui -lm
}
gentoo*: {
LIBS += -lopencv_imgproc -lopencv_highgui -lm
}
}
I think you can run "uname -a" and use a regular expression to check the return value in your .pro file:
UNAME = $$system(uname -a)
contains(UNAME, YourRegExpToMatchGentoo): GENTOO = 1
contains(UNAME, YourRegExpToMatchUbuntu): UBUNTU = 1
contains(GENTOO, 1): {
LIBS += -lcxcore -lhighgui -lm
}
contains(UBUNTU, 1): {
LIBS += -lopencv_imgproc -lopencv_highgui -lm
}

Resources