COMPILATION OF APPLICATIONS QT LINUX

The Qt library allows you to do cross-platform applications. Once written code can be compiled under most operating systems. But the problem is in the word "compile" because It implies that you must reboot for the target system, be it a customized development environment installed and configured libraries zoo. Saves cross-compiling - compilation, generating executable code for a platform other than the one in which executed.

Cross compilation for Windows 64

Typically, one of the most popular problems is to build Windows-based version of its application, originally developed for Linux. An example of the solution to this problem can be seen here or in Russian. You must create a mkspecs-configuration, Qt putting files in the appropriate directory and all. Compile Qt in this case is not necessarily, you can download the binaries from the official site.

This approach has several disadvantages: 1) QtCreator an installed so the library does not know anything; 2) The official build Qt for Windows x64 exist. And if the first problem still somehow possible to fight against the second compilation only help ...

Before cross-compilation do not forget to put directly the cross-compiler (package manager is sought in the title «mingw»). And download the source qt-everywhere from the official site. The directory mkspecs unpacked archive copy the folder win32-g ++ in win64-x-g ++ and adjust the contents of the file the qmake.conf . I got the following:

In fact only the paths were replaced in the specification file.

I performed configure the following parameters:

./configure -xplatform win64-x-g++ CROSS_COMPILE=x86_64-w64-mingw32- -prefix /usr/local/qt4win64 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast -nomake demos -nomake examples -nomake tools -device-option -little-endian -qt-zlib -qt-libpng -qt-libjpeg -openssl-linked -no-fontconfig -no-3dnow -no-ssse3 -continue

Here gather the minimum version of Qt without webkit, phonon, multimedia, etc. A full list of options can be viewed on command ./configure -help

Accordingly, in such an assembly package must be installed g ++ - mingw-w64-the x86-64 , containing in itself the x86_64-w64-mingw32- g ++ (in the Ubuntu package must be put separately).

Next, the make && sudo the make the install . In the first stage of compilation uses native compiler system, it collects the necessary tools for linux, which will be used for the assembly have windows-binaries.

After the installation in my / usr / local / qt4win64 / bin lie PE32 + DLL and several ELF 64-bit LSB executable, including: by qmake, by uic, the moc, rcc . Here they are then useful for QtCreator!

After installation do not remove the unpacked directory - it is used.

Cross compilation for Windows 32

Similar to compile for Win64. Except for the fact that there is an official assembly, and do not need to compile the library itself! Enough to collect by qmake, by uic, the moc, rcc .

configure:

qmake.conf

Cross-compilation for Mac OS X

Cross-compilation for poppy is also very similar, except that it will be necessary to collect and compiler. I compiled under this instruction. It took a full day of time and a lot of nerves. In the process of working will need Mac OS X (at least in a virtual machine) with installed XCode, there intending to take the necessary files. When compiling their Qt-applications running Mac OS X is not needed.

configure:

qmake.conf:

Remember, in Mac OS X to link with the library .a -files not needed.

Setting QtCreator

First you need to add to the list all the installed compilers. Tools - Options - Building and running - Toolkit:

QtCreator usually determines the normal ABI, but it is better to double-check. You can also notice that the system x64 GCC in linux is able to generate 32-bit applications. However, this does not negate the fact that also needed 32-bit versions of the libraries.

After compilers can add profiles Qt:

That's when you add a profile and handy previously collected by qmake, by uic, the moc, rcc , because you need to select the directory by qmake . A yellow icon with an exclamation point to the left of the profile means a warning, but QtCreator can use this profile Qt. But if a red icon, the profile of a non-working. This can happen due to improper directory structure. Or if you delete the directory where you have compiled Qt.

The following settings must be done for each project to create.

To add a specific Qt profile should be the active project, go to the tab "Projects» (Ctrl + 5):

By default, the list of "Change the build configuration" is the only system profile Qt. But in the list of buttons "Add" has all profiles Qt, added to the build options.

The main assembly of the settings you need to check a couple of library compiler. So both were on the same operating system.

Assembly steps «qmake» and «Build» QtCreator puts default. But the special stages «upx» and «dmgbuild» I've added manually to the project. Stage "upx" runs every time when you click on "Build project." However, if the executable file was not changed, the upx will return an error that it has already processed the file. In case of error the next stage is not caused, i.e. dmg-file is updated only if upx worked successfully.

Read more:   HOW TO CREATE A two accounts on Skype

To work stage upx it must be installed in the system. However, even working in linux-environment and delivered from the package manager upx can compress application: linux32 / 64, win32, macos32 / 64. Not for all upx-compression project is really necessary, stage shows rather an example.

For stage «dmgbuild» I took the script make_dmg. He needs the right root , so the script is added to the file / etc / sudoers

Changes in the project file and the use of third-party libraries

In my project uses libusb , but this is not part of Qt. Also, it was necessary to include platform-specific implementation of the HID. The lines have been added to the project file:

macx {
INCLUDEPATH += $$PWD/libusbx/
SOURCES += BootLoader/HIDAPI/mac/hid.c
LIBS += -framework IOKit -framework CoreFoundation -lusb-1.0
ICON = AqPicFlash.icns
}

win32: {
INCLUDEPATH += $$PWD/libusbx/
LIBS += -lsetupapi -lole32
SOURCES += BootLoader/HIDAPI/windows/hid.cpp
RC_FILE = WinIcon.rc
}

win32: !win64-x-g++ {
LIBS += -L$$PWD/libusbx/ -lusb-1.0-32.dll
}

win64-x-g++ {
LIBS += -L$$PWD/libusbx/ -lusb-1.0-64.dll
}

unix: !macx {
CONFIG += link_pkgconfig
PKGCONFIG += libusb-1.0
SOURCES += BootLoader/HIDAPI/linux/hid-libusb.c
}

In Mac OS X, and Linux linkuemsya systemic libusb, in Windows, depending on the bit linkuemsya with libusb-1.0-32.dll.a or libusb-1.0-64.dll.a . Remember that .a -file can be renamed, but depend on the application anyway will be on libusb-1.0.dll . In Linux, libusb parameters to take over the system utility pkgconfig. Besides libusb connect to each operating system required system libraries, and icons.

Conveniently smash the resulting files for different operating systems on directories. This can be done as follows:

macx {
DESTDIR = mac
OBJECTS_DIR = mac
MOC_DIR = mac
UI_DIR = mac
RCC_DIR = mac
}

unix: !macx {
DESTDIR = linux
OBJECTS_DIR = linux
MOC_DIR = linux
UI_DIR = linux
RCC_DIR = linux
}

win32 {
DESTDIR = windows/release
OBJECTS_DIR = windows
MOC_DIR = windows
UI_DIR = windows
RCC_DIR = windows
}

win64-x-g++ {
DESTDIR = win64/release
OBJECTS_DIR = win64
MOC_DIR = win64
UI_DIR = win64
RCC_DIR = win64
}

The purpose of win64-x-g ++ refers to win32 , but there is a project file and overwrite the last setting.

Result

Now to build the application under a particular operating system, just select the type of assembly, as shown in the first screenshot, and press the "Build project"

QT COMPILATION FROM WINDOWS ON LINUX

Hello.

Projects under the QT realized in QTCReator'e. While that worked under Windows, it is now necessary to re-create my program under Linux. How to do it right?

The simplest thing that came to mind - is to put a Linux QtCreator, and a Windows machine, where I originally programmed, move my project on a Linux machine, open it in the Linux version QTCreator'a, simply recompile. On a simple project proekperementiroval - generally turned out (of course, under Linux had to create your custom assembly, such as the profile of the QT, compiler settings, etc. But what is not beautiful at all times with a source daddy back and forth to carry.

How to organize cross-platform work with the project for QT, using QTCReator? And especially for the development team?

Hello, Grizzli, you wrote:

G> How to organize cross-platform work with the project for QT, using QTCReator? And especially for the development team?

Yuzayte some svn or something. Checkout or update and build.

Hello, Brice Tribbiani, you wrote:

BT> Hello, Grizzli, you wrote:

G >> How to organize cross-platform work with the project for QT, using QTCReator? And especially for the development team?

BT> Yuzayte some svn or something. Checkout or update and build.

This is understandable, but I was especially annoying myself neobhodiomost separate assembly on different computers (in windose - under windose on linux - sootvestvennos under Linkous). It is impossible to organize the assembly centrally?

G> It is clear, but I was especially annoying myself neobhodiomost separate assembly on different computers (in windose - under windose on linux - sootvestvennos under Linkous). It is impossible to organize the assembly centrally?

Unfortunately not!

Hello, Werther, you wrote:

G >> It is clear, but I was especially annoying myself neobhodiomost separate assembly on different computers (in windose - under windose on linux - sootvestvennos under Linkous). It is impossible to organize the assembly centrally?

Read more:   INSTALL RUSSIAN VERSION muff

B> Unfortunately, no!

I've met on the internet article (older) people to put linux mingw, and set in toolcheyn QTCReatore, to compile a windose. somebody with this stalikvalsya personally? it makes sense to bother?

Hello, Grizzli, you wrote:

G> I've met on the internet article (older) people to put linux mingw, and set in toolcheyn QTCReatore, to compile a windose. somebody with this stalikvalsya personally? it makes sense to bother?

I not personally experienced, but not sure that it makes sense to bother. I'm not good at issue, described hereafter simply a flight of thought:

For example, you want out under linux compile under win, linux, mac.

Linux - everything is clear

Win - it is necessary to put mingw, who will be able to pick up Windows SDK (and if you want to use msvc)

Mac - the same (there under him as sdk goes?)

We have, in practice, on each platform 1 time configurable environment, as well as the build system using CMake. Those. there was no practical need for the project is the support for specific platform.

ASSEMBLY AND COMPILATION ON LINUX

All computer programs are a set of CPU instructions, which consist of a specific set of bits. These commands several hundred and with them all the actions performed on your computer. But to write programs directly from these teams is difficult. Therefore, it was invented a variety of programming languages ​​that are easier to read man.

To prepare a program to implement a special program collects it from the source code in a programming language into machine code - CPU team. This process is called compilation. Linux - is free software, and therefore the program source code is available to everyone. If the program is not in the repositories, or do you want to do something outside the box, you can compile the program.

In this article we look at how you compile Linux programs like the compilation process takes place, as well as look at how flexibly you can set up all.

Preparing the system

We will compile programs written in C or C ++, as this is the language used for programs that need to be compiled. We have already discussed this topic a bit in the article Installation of the tar.gz in Linux, but that article is aimed more at beginners, who need not only to understand how to get the finished program.

In the same article, the topic discussed in more detail. As you can imagine, for the conversion of the source code in the command processor you need special software. We will use the GCC compiler. To install it, and all the necessary tools in Ubuntu follow:

sudo apt install build-essential manpages-dev git automake autoconf

compiling6

Then you can verify the installation and the version of the compiler:

 gcc --version

compiling5

But before moving on to the most compile programs consider in more detail the components of this process.

How do I compile?

Compiling Linux software - it is quite a complicated process. Still more difficult, because the program code is not contained in a single file or even all files of its source. Each program uses a lot of system libraries that contain standard features. In addition, the same code should work in a variety of systems containing different versions of libraries.

In the first stage, even before the start itself compilation, a special tool has to check whether your system is compatible with the program, as well as whether there are all the necessary libraries. If anything is not present, the error will be issued and you will have to fix the problem.

Next comes the parsing and transforming the source code into object code, without this step, it would be possible to do, but it is necessary that the compiler can perform various optimizations to make the size of the final program is smaller and more efficient CPU instructions.

Then, all the object files collected into a single program, communicate with system libraries. Upon completion of this phase of the program can only be installed in the file system and all. These are the main phases of the compilation of the program, and now move closer to practice.

Compiling Linux software

The first thing we need - is the source of the program. In this example, we will collect the latest version of vim. This is quite neutral program is quite simple and necessary for everyone, so it is perfect for an example.

Getting source code

The first thing we need is the original program codes which are available at GitHub. You can find the source code for most Linux programs on GitHub. In addition, there have assembly instructions:

Read more:   How to download the program WORD EXEL

compiling7

Let's download the the sources of our program with git utility:

git clone https://github.com/vim/vim

compiling8

Also, you can file was downloaded from the website, and then extract it to a folder, but it will be more convenient. The utility will create a folder with the name of the program, we need to make it working:

cd vim

Setting configure

Next we need to run a script that will check our program to be compatible with the system and configure the compilation options. He called configure and comes with the developers of the program source. The entire compilation process is described in the Makefile, it will create the utility.

If configure is not in the source folder, you can try to run these scripts to create it:

./bootstrap

$ ./autogen.sh

Also, to create a script that you can use the automake tool:

aclocal

$ autoheader

$ automake --gnu --add-missing --copy --foreign

$ autoconf -f -Wall

Utility automake and other of its set of necessary files to generate Mackefile.am file basis. This file is required to exist in most of the projects.

Once you've got configure, we can proceed to configure. One of the great advantages of manual assembly programs is that you can choose which options to collect the program, where it will be placed and what additional features should include. All this is configured using the configure. Full range of options can be viewed by doing:

./configure --help

compiling1

Consider the most commonly used standard for all option programs:

  • PREFIX = -prefix - folder to install the program, instead of /, for example, can be / usr / local /, then all the files will be distributed not by the underlying file system and / usr / local;
  • DIR = -bindir - folder for placing the executable files should be located in the PREFIX;
  • DIR = -libdir is - folder for placing and searching the default library, too PREFIX;
  • DIR = -includedir - folder for placing man pages;
  • -Disable-opportunity - to turn off this possibility;
  • -Enable-opportunity - the opportunity to play;
  • -With-library - like enable activates the specified library or header file;
  • -Without-library - like disable disables the use of the library.

You can execute configure with no options to use the default values, but can also manually specify the correct path. In our case, there ./configure, and we can use it:

./configure

compiling2

During the setup utility will check whether there are all the necessary libraries in the system, and if not, you will have to install them, or turn this feature off, if possible. For example, there may be such a mistake: the no terminal for checking library found! Tgetent () ... the configure: error: the NOT FOUND is!

compiling3

In this case, we need to install the required library. For example, the program offers the ncurses, so we put:

sudo apt install libncurces-dev

The prefix lib is always added to the library, and -dev - means that we need a library with all the header files. After satisfaction of all the dependencies setup is successful.

assembly program

When the setting is complete and the Makefile is ready, you can go directly to the assembly program. In this step the source code directly into the machine transformation. make utility-based Makefile will do all the necessary steps:

make

compiling4

Then it remains to establish the program itself, if you used the prefix option to not install the program into the main file system, it is possible to apply the standard option make:

make install

The program will be installed in the folder you specified, and you can use it. But the more correct way - to create a package to install the program, this is done using checkinstall utility, it allows you to create both the deb, or rpm packages can therefore be used not only in Ubuntu. Instead, make install, run:

checkinstall

Then just install the resulting package using dpkg:

sudo dpkg install vim.deb

After that, the assembly program is fully completed and installed, so you can move on to full use.

If you installed the program using make install, then you can remove it by doing the same folder, the reverse command:

sudo make uninstall

Will remove all files that have been copied to the file system.

In this article we looked at how you compile Linux programs. This process can be difficult for beginners, but in general, everything is possible, if you take to solve the problem for several hours. If you have any questions, ask in the comments!

At the end of the video that is compiler and interpreter:

Read in other languages

 BelorussianEnglish Deutsch Spanish French Italian Portuguese Turkish Arab Ukrainian Swedish Hungarian Bulgarian Estonian Chinese (Simplified) Vietnamese Romanian Thai Slovenian Slovak Serbian Malay Norwegian Latvian Lithuanian Korean Japanese Indonesian Hindi Hebrew Finnish Greek Dutch Czech Danish Croatian Chinese (Traditional) Philippine Urdu Azeybardzhansky ArmenianPolish Bengal Georgian Kazakh Catalan Mongolski Russian Tadzhitsky Tamilʹskij telugu Uzbetsky

Add a comment

Your e-mail will not be published. Required fields are marked *