How to compile a Qt program without installing sdk - c++

Can someone tell me if it's possible to compile a project that works with Qt but without installing the entire sdk ? I mean, something like recompile Qt source code and link the libraries or something like this.
I know my problem is weird but I work in special conditions : I am on a linux machine and I have to work on a windows project therefore I use a distant server on windows to compile but I can't install anything on this serveur. I need an idea to have a fully portable folder with Qt who can compile without installing anything.
I hope I was clear in my explications.
Thank you for your help.

I has combined comments in answer.
You need to install compiler (e.g minGW) and Qt Library (as needed version).
You should add into environment variable 'PATH' your path to qmake and compiler.
Start terminal and move to directory with your source code of Qt project.
Run qmake and then exec make (e.g. It, for minGW, is mingw32-make).
For your case, you may choosen 2 way:
Build static Qt Library from source code and use static linking with your project.
Install Qt Library and copy libraries near your project with dynamic linking (recomended).

Related

When using Qt Creator with CMake, why do I not have to manually link the MSVC libraries?

Whenever I want to use 3rd party library code in my Qt creator CMake project, I have to link the library to my executable in my CMakeLists.txt so that the code can be used.
However, if I want to use code from e.g, MSVC 2010, or the Windows 10 software development kit, all I have to do is download and install it, and if then the code is ready to use.
Why is this?
Thanks.
The default behavior while searching dependencies in Windows is to look in all the system locations first, then the current directory, and finally any user-defined paths. That is why you don't have to explicitly link the Windows 10 SDK libraries.

CMake "make install" or including a library in windows

I'm trying to create an Open Source C++ project. I want it to be as easy to build as possible, but at the same time cross platform.
I don't need gui or heavy libraries like boost or Qt, so I've settled on using GitHub, CMake, and LibSourcey.
My problem is, I can't find a way to make my project easy to build in windows, which is my development environment.
How can I "make install" a library in Windows for use in my project? Do I even have to install it in windows?
Is it possible to download, build, and link it automatically?
On windows, besides an installer, I also want to make a portable version, so don't want any hard coded library paths.
I assume, on some platforms, like Linux, libraries are built separably and packaged up by maintainers. So I shouldn't just bundle up my own copies.
So, my question is:
How can I set up a project that is cross platform and easy to build, and what are the best practices?
You can create git submodule in your git repo with path for example
contrib/LibSourcery and url to github repo of LibSourcery, because of LibSourcery uses cmake you just
need add such line into your CMakeLists.txt: add_subdirectory(contrib/LibSourcery)
So person who want to use your code, just do git clone --recursive url
to get all of your code and dependencies, after that it run cmake -G, to create project for IDE of his choice (including MSVC++ of course),
open project in IDE and press build button, that's all.
Use babun. It's a wrapper for cygwin and it works perfectly for everything I need, even compiling with cmake.
Alternatively, you could use premake, which uses lua as a config system and works fine on windows.
There is no elegant cross-platform way, since the idea of "make install" doesn't exist on Windows, therefore the use of cmake install is undefined there. For something which is supposed to help cross-platform, I feel this is a deficiency w cmake.
My solution is to write a custom _INSTALL which takes the same args as cmake install and then on Linux it just calls install, and on Windows it does an add_command which does a post-build copy to the install paths, which accomplishes the same thing. Basically, _INSTALL behaves the way you expect a cross-platform install command to behave. Can share my _INSTALL func if there is interest.
_INSTALL is placed nto a Helper.cmake, and included in all my CMakeList.txt for my projects, so all I need to do is call it and the generated lib/inc files magically appear for both win and linux.
You can use vcpkg, an open source package manager for c and c++. It allows to easily download and compile libraries and then use find_package from within CMake like you would on linux. It's very easy to use. It even provides hints as to how to alter your cmake file to use the libraries.
I started by installing packages with the command line, and then wondered why they wouldn't show up in visual studio. But I realized that it would download 32 bit libraries by default. Use .\vcpkg install <libname>:x64-windows if you need the 64 bit libraries.
After running the integrate command, you will need to delete any cmake caches to have MSVS use the new toolchain.

How to build Crypto++ library on Linux with MinGW?

im trying to port a c++ project from visual studio 2013 to netbeans on ubuntu. The target is a windows executable, so far im able to compile windows exe files from netbeans using mingw as compiler.
The project needs the Crypto++ library and i only have the .lib version for visual studio. To include the library in netbeans i first need to build the Crypto++ library in the .a format.
Its not clear to me how should i do that.
Ive found informations on how to build the library for linux with mingw but not for cross compilation with mingw. The provided GNUmakefile does not work.
Should i set up a vm with windows and mingw and compile the library that way? Or maybe use the qmake "hack" as suggested here http://www.qtcentre.org/threads/28809-Compiling-amp-using-Crypto-with-mingw-version-of-Qt ? The last good Crypto++ version suggested there is quite old. This is confusing, porting the whole project is easier than having the required library.
Im open to any suggestion.
tldr: how to build libcryptopp.a on linux for the cross compilation of a windows exe project
edit:
for example if i cross compile something there are windows libraries in the /usr/i686-w64-mingw32/lib/ folder like libuser32.a. i need to make the equivalend libcryptopp.a.. sorry if is a bit unclear.
if i simply build using the steps in answer (and in the wiki) i end up with a libcryptopp.a file but i suspect is linux-only, cause if i link that library in netbeans in the .exe file im cross compiling i end up with undefined references to cryptopp stuff everywere. the paths are correct, i suspect the library needs to be replaced with the equivalent libcryptopp.a compatible with crosscompiling.
edit2: im trying to follow the answer down here, now im stuck here. after this command to build cryptopp.
make CXX=/usr/bin/i686-w64-mingw32-gcc INCLUDES="-I /usr/i686-w64-mingw32/include" LIBS="-L /usr/i686-w64-mingw32/lib" CXXFLAGS="-std=c++0x"
and many variations of it i always end up with this error
trap.h:26:25: fatal error: Windows.h: No such file or directory
# include
which makes me think its using the right compiler to make a .a lib file for cross compiling the windows .exe with the lib.
however i dont understand whats going on now with the missing header..:(
Also if i try to link the lib file (used with visual studio) i get a lot of linking errors, undefined reference to cryptopp stuff.
ill offer a symbolic beer (a couple of $ of Bitcoins) if someone finds out how to do it.
Inspired by http://wiki.amule.org/wiki/Cross-compilation_for_windows_with_mingw:
sudo apt-get install mingw-w64
git clone https://github.com/weidai11/cryptopp
cd cryptopp
export TARGET=i686-w64-mingw32
CXX=$TARGET-g++ RANLIB=$TARGET-ranlib AR=$TARGET-ar LDLIBS=-lws2_32 make -f GNUmakefile
I've found informations on how to build the library for linux with mingw but not for cross compilation with mingw.
Its relatively easy...
Get Crypto++ ZIP into MinGW.
Unpack Crypto++ ZIP.
Change directories.
Build the library.
Verify All tests passed.
(1) and (2) can be tricky because Cygwin and MinGW are missing a lot of tools. So curl https://www.cryptopp.com/cryptopp563.zip -o cryptopp563.zip may not work.
For (2), I seem to recall ZIP is missing, so unzip -aoq cryptopp563.zip -d cryptopp-5.6.3 may not work.
At step (4), just perform make static dynamic test and be sure it finished with All tests passed.
I do a lot of testing with Cygwin and MinGW. I have a script that copies Crypto++ into the environments from my Desktop. I have not been able to figure out a way to automate it. A recent question on automating it was closed, so no one can supply an answer (see How to automate software testing for Cygwin and MinGW).

Compiling a static QT application on Windows

I am new to QT and I am enjoying the experience except for the fact I cannot manage to statically link the QT library to the output binaries. When I run the output file outside of the QT directory, I get The program can't start beacuse QtCored4.dll is missing. Obviously QT is dynamically linking their libraries and requesting a .dll I do not have. Is there a way to statically compile QT's libraries into a static binary so none of QT's dlls are required? I ask this because I am already up to 11 .dlls for my project, and I would really like to cut down the amount of files that have to be distributed with my software. Size is not a problem for me. Thanks.
I have tried adding CONFIG += static to the .pro file, but to no avail.
First off, you can't statically link Qt unless you've bought a commercial license. To do so would put you in violation of the LGPL license under which the non-commercial version is distributed. I feel your pain, I've got many, many DLL's to go with my software.
Thankfully, you probably do have the DLL's if you used the installer: you don't need to build from source, that should have been done automatically. You'll find them in Qt\Version\bin, where Qt is the directory you installed Qt, and version is the version of Qt you installed. For example, mine is found in G:\Libraries\Qt\4.7.1\bin.
I did, however, have some issues with not having one of the DLL's built - one for working with OpenGL - and performed a rebuild to do so. I've also done so when I've switched versions of Visual Studio. I think it's handy to be able to do so, it's easy, Open a terminal in the Qt directory, and execute:
configure.exe -platform XXX'
Where XXX denotes the type of build you want to perform. Valid options include win32-msvc2005, win32-msvc2008, win32-msvc2010. So I use:
configure.exe -platform win32-msvc2010'
Other options are detailed here. These instructions apply if you've downloaded the source code, however you might have to add the current directory to the path variable like so:
set PATH=%cd%\bin;%PATH%
The whole procedure should take about an hour.
You need to download the source packet of QT and compile it. It takes some time but is not really complicated.
Download and unzip QT source
Start a compiler shell (Visual Studio or mingw)
Execute configure in the QT source directory - add a flag for static compile here
execute make (Visual Studio nmake)
Wait some hours depending on the speed of your machine

Qt C++ Stand alone executable in Windows

I want to make my Qt C++ program a stand alone single application. By the way, I am using Qt creator 2.2.1 which is based on Qt 4.7.4. I followed the instructions from http://www.formortals.com/how-to-statically-link-qt-4/ to statically link the libraries. I did not know where to find the configure.exe in the QtSDK folder so I downloaded "qt-everywhere-opensource-src-4.7.3" and followed the instructions.
I was unsure in Step 4 because the windows Qt options do not look similar. Its not a path to a folder but rather a path to qmake location and I am not sure what to choose for that option.
If anyone knows how to create the program as a stand alone without needing any dlls and can help me out, I would really appreciate it.
Thanks
Regarding the step 4 you mentioned, in QtCreator you need to point the qmake executable you will find it in the build tree (where you built Qt statically) in the bin folder.
I guess if you have problems on step 4 you should have built the static version of Qt, you've done 95% of the work !
The moment QtCreator will accept the qmake you made, you will just have to select this version use any wizard to get you first app, then add CONFIG += static to you .pro file.
Here some Qt tutorial just in case.