Qt4 change linker search order - qt

I have a Qt project which compiles library and application which links with the library.
With Qt5 everything works just fine. But with Qt4 I have one annoying problem.
On linking the application qmake for some reason brings:
-L<where_qt_libs_installed>
before
-L<build_dir/library_dir> -lmylib.
So if Qt4 libs installed in /usr/lib and previous version of my library is there too, the application will link with old version of library what usually finishes with link failures.
Is there any way to change link order except adding
LIBS += <full_path_to/libmylib.so>

Finally I solved it with this.
LIBS += -lmylib
!greaterThan(QT_MAJOR_VERSION, 4):equals(QMAKE_LINK_SHLIB, g++)|equals(QMAKE_LINK_SHLIB, ld) {
QMAKE_LFLAGS += -L<build_dir/library_dir>
} else {
LIBS += -L<build_dir/library_dir>
}

Related

Qt Quick Designer Components module Static Linking not working

I'm trying to cross compile Qt Quick Designer Components to get QtQuick.Studio.Effects module on Qt 6.5 on arm64 target as I'm getting "module 'QtQuick.Studio.Effects' is not installed" when I try to to run my cross compiled qt application.
So far I have cross compiled Qt Quick Designer Components with help of this and it outputs libQuickStudioEffects.a static library. I tried to link it in .Pro file by adding the library with qt creator which generated following lines.
unix:!macx: LIBS += -L/home/user/qt/ -lQuickStudioEffects
INCLUDEPATH += /home/user/qt/
DEPENDPATH += /home/user/qt/
unix:!macx: PRE_TARGETDEPS += /home/user/qt/libQuickStudioEffects.a
lib file and executable both are in /home/user/qt/ location in target and host pc.
also I tried with following line.
LIBS += /home/user/qt/libQuickStudioEffects.a
So far executable is not detecting the lib file and giving me the above mentioned error. I can run other cross compiled qt6 programs on my target device without any issue. My host runs Ubuntu 20 and target runs on debian 11. Any help is really appreciated. Thanks.
Build the dev branch from here and it will give the dynamic QtQuick.Studio.Effects library which can be cross compiled.

Qt project with Boost

I have a Qt project which requires boost. The project works fine in Linux, but compiling on windows has presented some difficulties. I have been able to make it work, but not properly, and that bothers me.
Here's the relevant part of .pro (working)
win32{
INCLUDEPATH +=C:\Boost\Boost
LIBS += "C:\Boost\Boost\stage\lib\libboost_system-mgw53-mt-1_65_1.a"
LIBS += -lws2_32
}
This does not work, but should according to the documentation I've found online.
win32{
INCLUDEPATH +=C:\Boost\Boost
LIBS += -LC:\Boost\Boost\stage\lib -lboost_system-mt
LIBS += -lws2_32
}
Note: Boost was compiled using the mingw distributed with Qt Creator.
I believe I have found the solution! I noticed that I had two copies of every boost library in \stage\lib.
libboost_system-mgw53-mt-1_65_1.a and libboost_system-mgw53-mt-d-1_65_1.a
I compiled the project using both and while the former had some warnings, the latter did not. Removing libboost_system-mgw53-mt-1_65_1.a from the folder allowed -lboost_system-mt to work just fine.
I don't know why I had both of these files, but it was undoubtedly due to me fumbling around with compiling boost.

Qt and Boost (installed through Homebrew) result in Qt compile errors

I am in the exact situation described in this question (Qt Creator on Mac and boost libraries) but the accepted answer is not working for me. I've searched around and tried all the suggestions I've found but I still end up with errors
Environment:
OSX 10.9.5
Qt 5.5.1 - Qt Creator 3.5.1 - installed using the Qt
installer
Boost 1.59.0 – installed through Homebrew
Am able to compile and run Qt apps
After creating a new Qt test application, when I add the Boost information to the .pro file (shown below) as described in the question linked above, I end up with very confusing compile errors within the Qt classes. I don't get it. Does anyone understand the conflict and know how to resolve this – I've been at it for hours now.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = audiowaveform_test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
macx {
QMAKE_CXXFLAGS += -std=c++11
_BOOST_PATH = /usr/local/Cellar/boost/1.59.0
INCLUDEPATH += "$${_BOOST_PATH}/include/"
LIBS += -L$${_BOOST_PATH}/lib
## Use only one of these:
LIBS += -lboost_chrono-mt -lboost_system # using dynamic lib (not sure if you need that "-mt" at the end or not)
#LIBS += $${_BOOST_PATH}/lib/libboost_chrono-mt.a # using static lib
}
I finally got it working by changing this line in the .pro file:
QMAKE_CXXFLAGS += -std=c++11
to this:
CONFIG += c++11
If someone can explain what -std means in compiler speak, I would appreciate it. Does it mean that everything should be compiled as c++11?

Qt linker errors: cannot find -lQtCored

A problem with a Qt *.pro file:
TARGET = ProgName
TEMPLATE = app
CONFIG += console
QT += core
QT += gui
LIBS += -LC:\\Qt\\4.8.5\\bin
LIBS += -LC:\\Qt\\4.8.5\\lib
LIBS += -LS:\\lib
# LIBS += -lQtCored4 # not necessary
# LIBS += -lQtCore4
# LIBS += -lQtGuid4
# LIBS += -lQtGui4
SOURCES += ...
HEADERS += ...
I get these linker errors:
:-1: error: cannot find -lQtGuid
:-1: error: cannot find -lQtCored
collect2.exe:-1: error: error: ld returned 1 exit status
All the DLLs exist in the specified directories.
The documentation did not help much.
This pro file worked a few days ago, and it seems to have issues since I installed Qt 5.1 (this is not used, yet; I am still working with Qt4).
Platform: Windows 7, MinGW, Qt 4.8.4
You only need the following content:
TARGET = ProgName
TEMPLATE = app
CONFIG += console
QT -= gui
SOURCES += ...
HEADERS += ...
That is because core and gui are added to the QT variable automatically. In this particular case however, you can remove the gui default if you wish to build a console application as you seem. Although "CONFIG += console" could eventually do that for you. Besides this, everything will work automatically for you, so you do not need to pass the library path to the qt libraries and so forth. You would only need to use QT += widgets and similar lines if you used further Qt modules there are not there by default. Even then, you would not need to set the Qt library path as you did in your question.
Besides, if you wanna target cross-platform later, you may wish to add this:
CONFIG -= app_bundle
to avoid creating Mac bundle for console based applications.
If you have multiple versions of Qt installed as it seems, you need to use the qmake from the required version, and it will be fine. Just to give an example: I use qmake for Qt 5 on my Archlinux system, and qmake-qt4 for Qt4.
On windows, you should either have the desired qt installation bin in the path before the undesired, or you need to call desired qmake explicitly, something like C:\path\to\my\desired\qmake.
There's no need to link to any Qt libraries afaik.
If you're using Qt Creator you need to make sure Qt 4.8.4 is properly recognized in Tools - Options - Build & Run - Kits. Since you installed 5.1 this may no longer be true. Then set the 4.8.4 kit for your project and compile it (cleaning the build directory also helps sometimes).

Linking opencv ".a" libraries with mingw and Qt 5.0

This one is tough ! Please don't mistake this for a newbie question ;) I have far too many miles in this OpenCV + MinGW static stuff for the simple mistakes....
Environment:
a. Qt 5.0.1 built with MinGW (the standard opensource download from qt-project) - so everything is built with the same MinGW environment.
b. Using CMake I setup minimal build (using the same g++/gcc as Qt) and turned OFF SHARED_LIBRARIES.
c. generated the cmake + mingw32-make + mingw32-make install works fine.
up till here everything looks pretty smooth ...
Now when I added:
win32-g++:INCLUDEPATH += D:/Dev/opencv/build/install/include
win32-g++:LIBS += -LD:/Dev/opencv/build/install/lib
win32-g++:LIBS += -static
win32-g++:LIBS += -llibopencv_core243d
win32-g++:LIBS += -llibopencv_imgproc243d
win32-g++:LIBS += -llibopencv_highgui243d
(and also without the "win32-g++" addition..)
I get d:/dev/qt/qt5.0.1/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -llibopencv_highgui243d
...
...
now.. I do have libopencv_highgui243d.a in the right directory, but the ld.exe linker is ignoring anything else than a lib ! which supposed to be a MS library (which I wanted to avoid in the first place!!!) - I even tried to rename the .a files to .lib which caused the linker to regard the files, but show many "unreferenced" errors...
So who's to blame? the linker? CMake? mingw? Qt? ....
I tried many command line / flag options but without success ..
You should be referring to the libraries as:
LIBS += -lopencv_core243d
LIBS += -lopencv_imgproc243d
LIBS += -lopencv_highgui243d
Since -l already inserts lib at the beginning of the name.

Resources