I've been doing some funny stuff in personal projects with Qt. I'm not an expert in this so if it's a dumb question (guess not I couldn't find anything useful) feel free to kill me.
Anyway, I'm in OSX and usually I compile the final versions against a static version of Qt using a shell script with this commands:
cd "project folder...";
PATH=/Users/TCB13/(...)/qt-source/bin:$PATH; --> Path to my static QT.
export PATH;
qmake -config release;
make;
make clean;
So far if I move the compiled binary to another computer without Qt installed everything works just fine! ;)
Yesterday I start to play around with a dynamic library provided by a company and I've included the dylib in my .pro file like this: (I've a copy of the dylib in the project folder)
#macx: LIBS += -L$$PWD/ -lwpsapi
#INCLUDEPATH += $$PWD/
#DEPENDPATH += $$PWD/
And when I compile it "statically" (using the commands above) and run it on the other computer I get:
dyld: Library not loaded: #executable_path/libwpsapi.dylib
Referenced from: /Users/TCB13/Desktop/dude111
Reason: image not found
Trace/BPT trap: 5
I noticed that the size of my compiled binary is the same with or without including the dylib so, I googled how to include and external lib and some people are saying that I need to add "CONFIG += static" to my .pro file. I did it and the size of the file increased but I still got the same error.
Hope someone can help me.
The error message is pretty clear, you need to distribute libwpsapi.dylib with your application. If you want to avoid that, consult the documentation of this third-party library to make it use the statically linked code. Note that the fact that you are telling the linker to link a static library, does not mean that the code is referenced. I suspect that there is some kind of preprocessor #define in the code (or defaulted) to use the dynamically loaded library.
Related
This Error pops up while I try to Compile the Project Map of Cartotype, I followed The Instruction on The Cartotype Documentation, but at this point I couldn't do any progress, help please !
:-1: error: No rule to make target 'G:/QT/Projects/cartotype-eval/CartoType-Public/src/apps/Maps/../../../../cartotype_windows_sdk_evaluation_5.10.7/CartoType/bin/15.0/x64/DebugDLL/libcartotyped.a', needed by 'debug/CartoTypeMaps.exe'. Stop.
My colleage tested same project on QT Linux - Ubuntu, and it worked smoothly !
I presume that you're using MinGW since the buildtool is looking for foo.a. You need to simply look at that error and understand what it means: a library it needs is missing. Until you provide that library, it won't build. That's the simple part. The hard part is that according to the SDK overview, CartoType comes with .lib libraries only, not .a libraries. But modern MinGW supports .lib files, so you only need to convince it to look for the .lib file, not .a file. Most likely, your build scripts have the reference to .a, or no full filename whatsoever.
If you're using QMAKE, you likely have something like:
LIBS += -LX:/cartotype_windows_sdk_evaluation_5.10.7/CartoType/bin/15.0/x64/DebugDLL cartotyped
Instead, you'd want:
LIBS += X:/cartotype_windows_sdk_evaluation_5.10.7/CartoType/bin/15.0/x64/DebugDLL/cartotyped.lib
Turns out static linking was working, but only for Qt libraries. My 3rd party library QtSerialPort is not linking statically. After some reasearch, I've found that I either have to build this library statically or I have to link directly to a .pri file in my .pro file.
I'm not sure how to do either since it seems QtSerialPort has not been designed for static linking.
The .pri method I really don't understand and has been vaguely described in these two links:
http://qt-project.org/forums/viewthread/15223
http://www.qtcentre.org/archive/index.php/t-54505.html
Does anyone have any adivce on how to get either of these methods to work? Or possibly another method?
Also, MSVCP100.dll is not linking statically if anyone could give me any advice on that.
==================================================================================
I am trying to get Qt to statically link libraries so that I can make a standalone application. I have followed various tutorials on how to build Qt statically then building a static application but I am not having much luck. I believe I have succesfully built Qt with static linking because the application has grown in size from 79KB to 7+MB but I am still getting errors saying QtCore4.dll and QtSerialPort.dll are missing. Also, another issue I'm having when using this static configuration, which isn't too serious, is that when I close my program Windows thinks it has crashed and gives me a window saying MyProgram.exe has stopped working...
I am on a Windows machine using MSVC 2010 with Qt 4.8.5 and am using the third party library QtSerialPort.
What I've done accoring to the guides I've been reading is:
Download and extract qt-everywhere-opensource-src-4.8.5.zip
Open /mkspec/mwin32-msvc2010/qmake.conf and change the follwing lines to
CONFIG += qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target
and
QMAKE_CLFAGS_RELEASE = -O2 -MT
I then open the MSVC2010 command prompt and cd to this . I then enter the commands
configure -static -release -platform win32-msvc2010
nmake sub-src
After this is done I open my project and add
CONFIG += static
to the .pro file. In QtCreator I then go into Projects, Manage Kits then to Qt Versions and browse to the qMake I just generated. I add a new Kit with this version of qMake. I then clean all and switch to this new kit and run qmake from QtCreator. I then use msvc2010 command prompt to go to the directory where the files are generated and then
nmake release
This generates a rather large .exe but like I said, it's still depending on a couple .dll's.
For static linking of external library one have a couple options, both have their pros and cons.
I. Compile the library for static linking yourself. Link to it.
Look for possible existing configuration switches for static linking. There can be something like QTSERIALPORT_STATIC = no, etc. in the library's .pro/.pri files. Just say yes for the library to compile for static linking and go to the step 4!
In .pro/.pri file replace CONFIG += dll with CONFIG += static.
Remove export declarations from the library. Typically Qt library symbols are declared with some definition like QTSERIALPORT_EXPORT which expands to Q_DECL_EXPORT/Q_DECL_IMPORT in shared library build / its header files usage when linking. You'll need to find where this QTSERIALPORT_EXPORT is defined and replace it with empty definition:
#define QTSERIALPORT_EXPORT // in source file
or
DEFINES += QTSERIALPORT_EXPORT # in .pro/.pri file
Build the library.
Link to the library .lib/.a file, use the library header files for symbol declarations in your project.
II. Include the library source files into your project and compile them within it (no linking at all).
Include all the source files of the library into your project (add to SOURCES in qmake project file)
Determine all the stuff the library depends on (other libraries, Qt options, etc.) and include it also into your .pro file.
OR
Include the proper .pri file into your .pro if the library author provides it for in-project compilation (i.e. include(QtSerialPort.pri) or something.)
Remove export/import declarations from the library source code — as described in the item 3 of part I.
Build your project.
I have a C++ project using Qt and I have it working as expected. However, the problem is when I copy
the executable to a standard installation of a OS (e.g. Windows or a Linux) upon execution I receive the QtWidgets or some other Qt libraries missing error.
I tried referencing the Qt Documentation but I am unable to find a solution or an example of what I am after. It has something to do with Static and Dynamic Building... but could not locate a good example or tutorial.
I looked at the tutorial http://www.qtcentre.org/wiki/index.php?title=Deploying_Qt_Applications but it is not quite the most efficient solution.
Basically I want the system to include the required Qt libraries along with the final compiled file. How can I pull it off?
What you can do is making a script which copies your DLLs (or .so* files) in the executable folder. Once you make it add an extra Makefile target in your project file :
theproject.pro:
OTHER_FILES += copy.script # Assuming your copy script is called "copy.script"
deploylibs.target = deploylibs
deploylibs.command = ./copy.script # Launching the script
QMAKE_EXTRA_TARGETS += deploylibs
Now you can deploy your libraries by using the (n)make deploylibs command.
NB: there is a very useful tool called "Dependency Walker" to find the DLLs you need. It is only for Windows. As for Linux and its *.so* files you can use the ldd command :
>$: ldd theexecutable
alib.so => /path/to/library/on/your/computer.so
...
First, Background info: Ubuntu 10.10, gcc 4.4.5, C++, Qt Creator 2.3.1, FLANN.
Problem: Every time I compile my code I get an error saying 'undefined reference to [function from FLANN]'.
Explanation: I've been working on a GUI in Qt Creator that will utilize a few classes I built that include references to the FLANN library (not necessarily that important to know). Everything was going smoothly until I incorporated these classes and their header files, of course. I added the library to the .pro file just in case, but that didn't solve my problem. I narrowed down the situation to how Qt is making the files as compared to how I was making the files when I was testing my classes with a Makefile:
My Makefile: g++ -g process_stuff.o driver.o -o test.exe /usr/local/lib/libflann_s.a
I'm appending this library to the end of the gcc command, and it works perfectly. Further, if I remove the /usr/local/lib/libflann_s.a I get the same error making it myself that I got out of Qt.
Question: What exactly am I doing by including the library at the end of my gcc calls, and what can I do to have this happen in Qt Creator? All help is appreciated, and thanks in advance.
The short answer to what you're doing by adding the library at the end of the gcc command is telling the build system where it can find the library and what library you want to link into your code. The -L part indicates the path to libraries and the -l is the name of the library you wish to link against. Both of which I suspect are not being included in your Qt Project file, which is why it isn't building when you're running it normally. You can add the two in the project as:
INCLUDEPATH += $$quote(/usr/local/include)
LIBS += $$quote(-lflann_cpp_s) \
$$quote(-L/usr/local/lib/)
External libraries are usually provided in two forms: static libraries and shared libraries. Static libraries are the ‘.a’ files . When a program is linked against a static library, the machine code from the object files for any external functions used by the program is copied from the library into the final executable.
But moments later.... unix:!macx:!symbian: LIBS += -L$$PWD/../../../../usr/local/lib/ -lflann_cpp_s Upon fixing that to: unix:!macx:!symbian: LIBS += -L$$PWD/../../../../usr/local/lib/ -lflann_s
The Qt library wizard decided to include the wrong file as the library. After changing the file, everything works.
I have developed an application with mac and for one month now, Im trying to link Qt with ImageMagick on windows.
I just cant find the files and the version of Imagemagick library that need to be linked to Qt in order to make my application work on windows.
I have tried most of the libraries from here
Thats the only thing I added to the .pro file while I was developing on a mac
INCLUDEPATH += . /opt/local/include/ImageMagick
LIBS += -L/opt/local/lib -lMagick++
When I add this to my .pro
INCLUDEPATH += C:/im6/include/ImageMagick
LIBS += C:/im6/lib/libMagickWand.a
LIBS += C:/im6/lib/libMagick++.a
LIBS += C:/im6/lib/libMagickCore.a
C:/im6/lib/libMagick++.a
I get 10.000 + simmilar errors to that:
(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4157: undefined reference to `__gxx_personality_sj0'
C:/im6/lib/libMagick++.a(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4157: undefined reference to `_Unwind_SjLj_Register'
C:/im6/lib/libMagick++.a(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4178: undefined reference to `_Unwind_SjLj_Unregister'
For more errors check this
Has anyone tried to build and deploy an ImageMagick application using qt on windows ?
Which files do I need to link while building and which files while deploying ?
The error message tells me that you
use mingw (with qtcreator). Your
library might not work with this
compiler. You need a mingw version
of the library, probably named
libmagick.a.
LIBS += -L$$quote(c:/Program Files/ImageMagick-6.6.5-Q16/lib) -lmagick
(see the documentation about qmake Project Files
I have found that the minGW tool set is very much treated as a "stepchild" in the Windows world. I know it doesn't help your particular situation, but we had numerous problems with third-party libs while trying to use Qt with minGW. There were always extra steps, or non-existent build instructions that we had to figure out or tweak.
Once we switched to the MSVC version, all of those problems went away. Note that this doesn't mean you have to use Visual Studio (you can still use Qt creator), it just means that the Visual Studio compiler is being used. You can get the compiler for free using the Platform SDK. If this is an option, you might save yourself a lot of pain by switching now. It's unfortunate, but that is just the current status quo, at least as we discovered.
Please go get ImageMagick source package.
I can’t give direct instructions how to work with MinGW of Qt Creator, but basically following. I prefer to use qtvars.bat that comes with binary distributions of Qt to set environment.
Open Windows cmd
Set PATH to have /path/to/mingw/bin and /path/to/qt/bin before other paths
Go to directory where you have extracted ImageMagick source
read README, INSTALL and such to compile the ImageMagick (most likely just ./configure ; mingw32-make, but never be sure)
Edit your .pro file with something like LIBS += -L$$quote(/path/to/imagemagick/lib/dir) -lmagick . The lib may be in bin dir or in lib dir. See hmuelner’s answer for more information.
At this point, the configuration should be ready. Compilation at Qt Creator should work, but you can as well use this cmd windows to compile your program: go to program directory, run “qmake” and “mingw32-make”.
You cannot link against a ImageMagick++ library built with MSVC, as mingw and MSVC DLLs are incompatible for C++ libraries. You can't link a MSVC-built C++ library into a mingw project, nor vice versa. C-only libraries work fine. Also, according to this fortum thread, using builds against old mingw-versions with current mingw versions doesn't work as the exception handling changed (as you get more errors than that, I wouldn't expect that to be the only problem though). If there is no binary package for your mingw version (and I don't see any on the imagemagick website), your only option is to use a source package, as Smar suggests.
Another option of course is to install Visual Studio, download Qt for MSVC and build your project with MSVC.