How to embed soname to a shared library in Qt? - qt

Is there a way to embed "soname" to a shared library that is created in Qt ?
Are there any flags to be assigned in .pro ?
My project.pro file contains
QT -= gui
TEMPLATE = lib
CONFIG += plugin
I am expecting the output to be like below
For example,
objdump -p libxyz.so | grep SONAME
This outputs: SONAME libxyz.so

Below is the command, I have used for adding SONAME to Qt shared libraries.
Below command is added in Qt .pro file
QMAKE_POST_LINK += patchelf --debug --set-soname libQtUILib.so libQtUILib.so
Below command is used to verify the SONAME
objdump -p libQtUILib.so | grep SONAME
SONAME libQtUILib.so

Related

How to ask QtCreator to use a custom build library on user path instead of using system library

My Ubuntu has ffmpeg library in /usr/lib/x86_64-linux-gnu. I also rebuild ffmpeg from source and install it into my home directory.
In project file, I have added following lines:
TARGET = testFFmpeg
INCLUDEPATH += /home/kiet/ffmpeg/include
LIBS += -L/home/kiet/ffmpeg/lib/ -lavcodec -lavformat -lavutil -lswscale
I build my project successfully. But my binary file still links to ffmpeg in /usr/lib/x86_64-linux-gnu
ldd testFFmpeg | grep libav
libavcodec-ffmpeg.so.56 => /usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56 (0x00007f9085ce7000)
libavformat-ffmpeg.so.56 => /usr/lib/x86_64-linux-gnu/libavformat-ffmpeg.so.56 (0x00007f90858e9000)
libavutil-ffmpeg.so.54 => /usr/lib/x86_64-linux-gnu/libavutil-ffmpeg.so.54 (0x00007f908567a000)
How can I ask qmake to find library in my folder first?
How can I ask qmake to find library in my folder first ?
Operator += adds the item to the end of the list, but you need to put it at the head of the list like this:
LIBS = stuff $$LIBS

Makefile made by qmake only works on my pc

For a university project we made an OpenGL application which uses Qt for the GUI. When I use qmake -spec macx-g++ project.pro I can make a Makefile, and if I then do make it correctly makes the application. However, when I then send the complete folder to the other person in the project and he does make he gets the error
Makefile:209: warning: overriding commands for target `moc_window.cpp'
Makefile:203: warning: ignoring old commands for target `moc_window.cpp'
make: *** No rule to make target `/usr/lib64/qt-3.3/mkspecs/default/qmake.conf', needed by `Makefile'. Stop.
However, when in the same folder he does qmake; make it does work correctly. The problem is that when handing the code in we don't know if the professor has qmake available, so we would like it to work by only using make. Are we missing something that should be addded to have the Makefile made with qmake work, without having to do qmake again? Our .pro file is below.
TEMPLATE = app
TARGET = smoke
QT = core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += \
fluids.cpp \
simulation.cpp \
visualization.cpp \
window.cpp \
myglwidget.cpp \
vector.cpp \
grid.cpp \
scalar.cpp
HEADERS += \
window.h \
myglwidget.h \
simulation.h \
vector.h \
grid.h \
visualization.h \
scalar.h
INCLUDEPATH += fftw-2.1.5/include /usr/local/include include
LIBS += -L"$$_PRO_FILE_PWD_/fftw-2.1.5/lib" -lrfftw -lfftw -framework OpenGL -framework GLUT -stdlib=libc++
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -std=c++11
FORMS += \
window.ui
The build directory is not portable. It is only ever meant to work on the system where you executed qmake, and for the particular Qt install that you ran qmake from. Recall that each Qt install has its own qmake, so e.g. if you have three Qt versions, each provides its own qmake that you must use to build a project using that version.
The project you ship should contain the .pro file, the sources, and whatever else the build calls for, like icon files, resources, etc.
The recipient, to build it, should:
Create a build folder.
cd into the build folder.
qmake /path/to/sources/project.pro && make -j
That's how you distribute and build Qt projects.
why does qmake not build the application directly?
Why do you not make your own shoes? The reasons are the same. Don't reinvent the wheel.
Of course, engineers sometimes have an itch to scratch. Enter Qt Build System (qbs). If your project's build is given as a .qbs file, then you do:
Create a build root folder.
cd into the build root folder.
qbs -f /path/to/sources/project.qbs - this builds the project.

How to use existing QMake project (.pro project file) as "external project" in CMake?

Is there a concise doc or example for how to use an existing QMake project with .pro project file as an "external project" in CMake? This can somewhat be done in qtcreator by marking one project as dependency of another, but it would be nice to define it more explicitly with the ExternalProject() CMake syntax.
related question: CMake: How to build external projects and include their targets
Something like this works. You can then edit the files from either qtcreator in main CMake project tree, OR from opening the .pro file; great for iterating quickly on QT widgets in SomeGarbageApplication that is part of large cmake build tree.
macro(DeclareProjectFiles Tag Filez)
######### Trick: use this syntax to make arbitrary files
######### appear in IDE project. #######################
### Note: pass in the raw name of a list variable,
### since it will get expanded here in this macro.
add_custom_target(${Tag}_files ALL
pwd
COMMAND ls -ltrh
COMMENT " ${Tag} files thunk... got list: [ ${${Filez}} ]"
VERBATIM
SOURCES ${${Filez}}
)
endmacro()
message(STATUS "QT_QMAKE_EXE is: ${QT_QMAKE_EXECUTABLE}")
set(Z SomeGarbageApplication)
file(GLOB ${Z}_Files
./*.cpp
./*.h
./*.ui
./*.pro
./*.png
./*.jpg)
DeclareProjectFiles( ${Z}_grbg ${Z}_Files )
add_custom_target(${Z}_pro ALL)
set(ExtraQMakeArgs -r -spec linux-g++ CONFIG+=release)
# note: use killall because this can/will fail if the exe is running
# But, need || true to not fail build when it's not running.
add_custom_command(TARGET ${Z}_pro
COMMAND killall
ARGS -q -9 -v ${Z} || true
COMMAND ${QT_QMAKE_EXECUTABLE}
ARGS -query
COMMAND ${QT_QMAKE_EXECUTABLE}
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${Z}.pro ${ExtraQMakeArgs}
COMMAND make ${Z}
ARGS -j4
COMMAND cp
ARGS ${Z} ${CMAKE_CURRENT_SOURCE_DIR}/${${Z}_config} ${CMAKE_BINARY_DIR}/bin/
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
#################################################################

How to put gstab+ option to mingw makefile generated by qmake

I am newby in Qt, and try to compile tutorial application with MinGW. The only problem, that I need to put -gstab+ option to gcc compiler instead of -g option that qmake generated by default.
Currently, I select debug configuration (it add CONFIG += debug to the qmake command-line).
I've tried to add CONFIG += gstab+ to the .pro file, but it does not work. qmake generates makefile.Debug file with -g option.
What do I make wrong? And how should it be?
I've found a solution here http://qt-project.org/forums/viewthread/2412
I've added the following lines to my .pro file:
QMAKE_CXXFLAGS_DEBUG += "-gstabs+"
QMAKE_CFLAGS_DEBUG += "-gstabs+"

Qmake incorrect output directory

When I try to generate a makefile with qmake in a sub-directory, the makefile is generated in a wrong directory.
Here is my QmakeTest.pro, the main.cpp is a simple hello world code :
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
When I run qmake:
qmake -makefile -o build/makefile
qmake -makefile -o build/makefile
The first time, the folder build/ is created and the makefile is created in the right directory, the second time(and each time if build/ already exist), the makefile is generated in the folder build/build/ (a subfolder build inside the first one).
Why does qmake create a second subdirectory if the subdirectory build/ already exist ?
For info: qmake --version
QMake version 3.0
Using Qt version 5.3.0 in /usr/lib/x86_64-linux-gnu
Edit: The bug seems to be fixed with the QMake provided with qt 5.4.0
You can use
QMAKE_MAKEFILE += build/makefile
in your project file to create the makefile

Resources