I'm having trouble getting Qt to statically link its libraries when cross compiling from my Linux machine to windows. I added this to my config to make compile statically.
win32:CONFIG += -static
And by looking at the output of make it seems to have passed the flags correctly (omitting object files to make it short)
i686-w64-mingw32-g++ -static -static-libstdc++ -static-libgcc -Wl,-subsystem,windows -mthreads [exe and object files] /usr/i686-w64-mingw32/lib/libQt5Widgets.dll.a -ldwmapi -luxtheme /usr/i686-w64-mingw32/lib/libQt5Gui.dll.a -lopengl32 -lgdi32 -lcomdlg32 -loleaut32 -limm32 -ljpeg -lpng -L/usr/i686-w64-mingw32/lib -lfreetype -lbz2 -lharfbuzz -lm -lintl -lglib-2.0 -lshlwapi -lpcre -lgraphite2 /usr/i686-w64-mingw32/lib/libQt5Core.dll.a -lz -lpcre2-16 -liconv -lversion -lnetapi32 -luserenv -lole32 -luuid -lwinmm -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 /usr/i686-w64-mingw32/lib/libglu32.a /usr/i686-w64-mingw32/lib/libopengl32.a /usr/i686-w64-mingw32/lib/libgdi32.a /usr/i686-w64-mingw32/lib/libuser32.a -lmingw32 /usr/i686-w64-mingw32/lib/libqt5main.a -lshell32
As you can see the static flags are being passed to the compiler correctly, however I tried running the resulting exe in both WINE, and on a windows machine but in both cases it tells me that it failed to find the Qt dlls. The wine error log had more info so that's the one im providing
0009:err:module:import_dll Library Qt5Core.dll (which is needed by L"Z:\\home\\zee\\mapper\\release\\mapper.exe") not found
0009:err:module:import_dll Library Qt5Gui.dll (which is needed by L"Z:\\home\\zee\\mapper\\release\\mapper.exe") not found
0009:err:module:import_dll Library Qt5Widgets.dll (which is needed by L"Z:\\home\\zee\\mapper\\release\\mapper.exe") not found
0009:err:module:LdrInitializeThunk Importing dlls for L"Z:\\home\\zee\\mapper\\release\\mapper.exe" failed, status c0000135
I'm running on an Arch Linux machine with the latest qt5base aur package (5.13.1), and the latest mignw package (g++ 9.2.0)
Your compiler command line has both static and dynamic libraries. For instance: "/usr/i686-w64-mingw32/lib/libQt5Core.dll.a" is the import library for the dynamic "Qt5Core.dll". The right file to be linked in static mode would be "libQt5Core.a". Your problem looks similar to this report of the mingw project: https://github.com/msys2/MINGW-packages/issues/4970
Related
I'm trying to compile CUDA code using nvcc on Ubuntu. However, when I do, I get this output:
> make
/usr/local/cuda/bin/nvcc -m64 --ptxas-options="-v" -gencode arch=compute_11,code=sm_11 -gencode arch=compute_13,code=sm_13 -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -o main main.cu
gcc: No such file or directory
make: *** [main] Error 1
Even when I'm trying to compile a file with only a main function in it, it still doesn't work:
> /usr/local/cuda/bin/nvcc main.cu
gcc: No such file or directory
nvcc seems to respond to --version, so it's definitely there. I'm not sure why it's invoking gcc though.
nvcc is not a compiler in itself. It's a "compiler driver", orchestrating the entire process of compiling device code, host code and linking it together. On Linux, it uses gcc for compiling the host code.
To install gcc on Ubuntu:
$ sudo apt-get --yes install build-essential
I'm porting my Qt app to Linux for x86 architecture, and since the last official release for that platform is 5.5, I'm trying to do my own build of Qt 5.11.3. I want to use fontconfig to enable use of system fonts. My build platform is Centos 7.5, and I'm using a GCC toolchain which builds x86 binaries with -m32 switch.
The problem is, I can't get it to see the fontconfig library. I've installed it with the package fontconfig-devel-2.13.0-4.3.el7.i686
When running configure with the option -fontconfig, I get the following error message:
ERROR: Feature 'fontconfig' was enabled, but the pre-condition '!config.win32 && features.system-freetype && libs.fontconfig' failed.
My understanding from this is that I have to use -system-freetype and can't use -qt-freetype, but when I try that (also with -feature-freetype), I get this message:
ERROR: Feature 'system-freetype' was enabled, but the pre-condition 'features.freetype && libs.freetype' failed.
The relevant messages in config.log are:
looking for library freetype
Trying source 0 (type pkgConfig) of library freetype ...
pkg-config use disabled globally.
=> source produced no result.
Trying source 1 (type freetype) of library freetype ...
+ cd /home/myuser/qt-build/config.tests/freetype && /home/myuser/qt-build/qtbase/bin/qmake "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" -early "CONFIG += cross_compile" 'LIBS += -lfreetype' /home/myuser/qt-build/config.tests/freetype
+ cd /home/myuser/qt-build/config.tests/freetype && MAKEFLAGS= /usr/bin/gmake
> g++ -c -m32 -pipe -O2 -std=gnu++11 -w -fPIC -I. -I/home/myuser/qt-everywhere-src-5.11.3/qtbase/mkspecs/linux-g++-32 -o main.o main.cpp
> main.cpp:2:22: fatal error: ft2build.h: No such file or directory
> #include <ft2build.h>
> ^
> compilation terminated.
> gmake: *** [main.o] Error 1
=> source failed verification.
test config.qtbase_gui.libraries.freetype FAILED
Now, I do also get this message:
WARNING: Cross compiling without sysroot. Disabling pkg-config
which I understand is the source of the "source 0" failure. I have however tried to point configure manually point it to the freetype include directory, by passing FREETYPE_INCDIR=/usr/include/freetype2 to configure; however, as can be seen in the log file, the value does not seem to be used when detecting freetype.
Am I missing a trick here, or are the configure scripts broken? And if it's the latter, is there a way to work around this?
EDIT: For completeness, the environment for running configure:
CFLAGS=-m32
CXXFLAGS=-m32 --std=c++1x
Configure flags:
-opensource
-xplatform linux-g++-32
-nomake tests -nomake examples -nomake tools
-prefix /home/myuser/qt_install/
-qpa xcb
-no-use-gold-linker
-icu ICU_PREFIX=/home/myuser/icu_install ICU_LIBS="-licui18n -licuuc -licudata"
-no-opengl
-fontconfig -feature-freetype -system-freetype FREETYPE_INCDIR=/usr/include/freetype2
Try using the Freetype library that is included inside Qt's sources: when running configure use the flag "-qt-freetype"
I've found it's possible to work around this by setting CPATH (and LIBRARY_PATH to point at a specific build of Freetype which it turned out I needed as well). It looks like the fact that FREETYPE_* variables are ignored when detecting the presence of Freetype is indeed a bug in the config scripts.
I'm writing a QML application using Qt 5.7 on Ubuntu 14.04. I prefer to use an editor other than Qt Creator, so it makes it slightly cumbersome to launch Qt Creator and switch to it just to press Ctrl-R each time I want to run. I'd like to compile and launch my app from the command line.
Following this answer and then this answer I was able to install qmake and make it the default:
sudo apt-get install qt5-qmake
sudo apt-get install qt5-default
Following this answer I am copying the qmake build command listed by Qt Creator in the Project tab and successfully building the make file:
qmake qt-client.pro -r -spec linux-g++
However, when I run make (on my already-working-in-Qt-Creator code) I get:
phrogz#Slub:~/Code/rb3jay/qt-client$ make
g++ -c -pipe -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -I. -I/usr/include/qt5 -I/usr/include/qt5/QtQuick -I/usr/include/qt5/QtQml -I/usr/include/qt5/QtNetwork -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:6:36: error: ‘AA_EnableHighDpiScaling’ is not a member of ‘Qt’
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
^
make: *** [main.o] Error 1
I'm guessing that perhaps the version of Qt being picked up by qmake or g++ is not the 5.7 version Qt Creator is using, since AA_EnableHighDpiScaling was added in Qt 5.6.
The full generated Makefile includes
99 references to /usr/include/qt5 and 179 references to /usr/lib/x86_64-linux-gnu/qt5. Qt 5.7 is installed in /home/phrogz/Qt5.7.0. Obviously I need to modify something in the qmake command to get this pointing elsewhere.
How can I get this to work? Do I need to somehow remove an older version of qt libraries installed by Ubuntu? Point some configuration to the version of Qt 5.7 that's now installed (by the Qt Installer) in my home directory? Replace existing/old Qt directories with symlinks?
Or you can use CMake:
cmake_minimum_required (VERSION 2.8.11)
project(myproject)
find_package(Qt5 5.7.0 REQUIRED COMPONENTS
Core
Quick
Widgets
)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable(${PROJECT_NAME}
main.cpp
)
target_link_libraries(${PROJECT_NAME}
Qt5::Core
Qt5::Quick
Qt5::Widgets
)
I have MSYS installed and I am trying to compile Qt 4.8.0 as a set of static libraries on Windows 8. I've got the libraries built and unfortunately when building the Qt tools, I get this error:
$ g++ -Wl,-s -Wl,-subsystem,console -mthreads -o ../../../bin/uic3.exe object_s
cript.uic3.Release -L'd:/qt/lib' -L'd:/qt/lib' -lQt3Support -lQtSql -lQtXml -l
QtGui -lQtNetwork -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lms
img32 -lQtCore -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32
-lssleay32 -llibeay32
d:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/ld.exe: final link
failed: Permission denied
collect2: ld returned 1 exit status
For some strange reason, I'm getting a weird error about permissions - but I've double-checked that g++ has write access to the folder in question. I've tried creating the file uic3.exe in the output folder and sure enough, g++ deletes it and tries to create the file but fails again.
So I tried running MSYS under an administrator account - still it refused to compile. There is plenty of disk space, so I doubt any sort of disk problem is to blame. I tried running g++ with the -v option to get some more details, but there was no further information provided.
What could cause this error?
Edit: I've tried writing the output file to different locations (by modifying the -o parameter) and it still reports the same error.
Anti-virus software could cause this, including Microsoft Security Essentials. Disable them!
And, make sure you open MSYS console with administrator priviledges.
Let's say I have a library lib1.so created like that:
gcc 1.cpp -o lib1.so -shared
And I have another library lib2.so created in this way:
gcc 2.cpp -o lib2.so -shared -L. -l1
But linking against lib2.so
gcc main.cpp -o main -L. -l2
gives a warning:
warning: lib1.so, needed by lib2.so, not found (try using -rpath or -rpath-link)
But AFAIK the use of rpath is discouraged because then the library can not be moved to another location.
How do I link "main" against "lib2.so" without specifying "lib1.so" and rpath?
The RPATH header in the binary takes precedence so even if the library has no RPATH header, it will still be found IF you have copied it to the directory mentioned in -rpath