How to distribute a GtkAda application under Windows? - ada

I'm having troubles distributing a GtkAda application on Windows. I made an executable (with Windows native compiler) and tried using it on another Windows computer. However, I get errors about dlls missing.
I tried distributing with my .exe three folders.
bin including the dlls installed by GtkAda,
etc including fonts, gtk-3.0 and pango,
lib including gtk-3.0 with dlls too.
This is what I read from the GtkAda documentation
I think I maybe forgot to specify something in the project file
Here my GPS project file
with "C:\GNAT\GTK\lib\gnat\gtkada";
project Logfilter is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Exec_Dir use "exec";
for Main use ("log_filter_main.adb");
package Builder is
for Executable ("main.adb") use "Logs_Filter";
end Builder;
package Compiler is
for Switches ("ada") use ("-Wl,--subsystem,windows");
end Compiler;
end Logfilter;
I'm using a glade (gtk 3.14) file and GtkAda 2019.
Thank you.

Where did you put the main executable (log_filter_main.exe)? What libraries are missing?
When I create a directory structure using the batch program below (change the variables GTKADA_INSTALL_DIR and TARGET_DIR to match your situation), and then copy my executable (a simple GtkAda program) into %TARGET_DIR%\bin, then this executable runs just fine. It's important that the application resides in the bin folder such that the correct GTK runtime libraries will be found during startup.
create_standalone.bat
SET GTKADA_INSTALL_DIR=C:\GNAT\2019\GtkAda
SET TARGET_DIR=C:\Test
xcopy /s /i %GTKADA_INSTALL_DIR%\bin\*.dll %TARGET_DIR%\bin\
xcopy /s /i %GTKADA_INSTALL_DIR%\etc\*.* %TARGET_DIR%\etc\
xcopy /s /i %GTKADA_INSTALL_DIR%\lib\gtk-3.0\*.* %TARGET_DIR%\lib\gtk-3.0\
REM Copy your GtkAda application (.exe and other dependencies if applicable)
REM to %TARGET_DIR%\bin\
Regarding the project file: first, it's not completely clear why the Builder package is needed, but I might lack some project specific knowledge/requirements here. Second, if you want to get rid of the console window popping up when starting the GUI application, then you might want to use
package Linker is
for Switches ("ada") use ("-mwindows");
end Linker;
instead of
package Compiler is
for Switches ("ada") use ("-Wl,--subsystem,windows");
end Compiler;
Note:
Small additional note beyond the scope of the question (you may already have thought of it): please do not forget to quit the GTK main application when you close the main window. Define (for example):
procedure Destroy_Event_Callback
(Widget : access Gtk.Widget.Gtk_Widget_Record'Class)
is
begin
Gtk.Main.Main_Quit;
end Destroy_Event_Callback;
and then register it as a callback when the main window is initialized:
Main_Window.On_Destroy (Destroy_Event_Callback'Access);
If the Gtk.Main.Main_Quit call is omitted, then the program (process) will keep running after you close the main window (at least when you use the -mwindows linker option).

Related

How install qt libraries near to executable file

There was such a problem: using cmake to install the compiled executable in a certain directory, along with all the dependent libraries (qt), so that later this folder could be simply transferred to another computer, with the same architecture (and installed packages, like built-essential). And do it on two systems: linux & windows. And there are two problems:
what are the dependencies of Qt libraries and how to identify them with cmake (if it possible)?
when using install(FILES $<TARGET_FILE:Qt5::some_packet> DESTINATION bin) on Linux, the following libraries will be copied: libQt5some_packet.so.5.11.1 and when you try to start the program, it will immediately declare that it cannot find the corresponding libraries. And the command export LD_LIBRARY_PATH=/install path/bin haven't any result.
UDP i find how fix problem 2:
install(FILE $<TARGET_SONAME_FILE:Qt::some_package> DESTINATION bin)
but first problem (for windows) is open.
You can use Dependency Walker to get the complete list of dll dependencies

gprbuild/gprinstall doesn't respect encoding

Building Ada sources for multiple projects, with installing the libraries and sources after each project build, works fine for gnatmake and a gnat.adc containing
pragma Wide_Character_Encoding(UTF8);
but not for gprbuild, no matter what I try.
package Compiler is
for Default_Switches ("ada") use ("-gnatW8");
end Compiler;
or
package Builder is
for Global_Configuration_Pragmas use "gnat.adc";
--The same I used with gnatmake just fine
end Builder;
Am I missing something? When I run a program with projects build with gprbuild I get bracket encoding output instead of the Unicode characters.
The build even has -gnatW8 on the command line. In fact, the command line args during each build are identical, but they produce notably different output when a program is run.
Progress:
Upon noticing the generated files for stand-alone libraries were not built with -gnatW8, I removed all interface declarations for the gpr files, and build standard shared libraries. Programs built with these respect Unicode, and do not output bracket encoded text. So now, the question is why stand-alone libraries aren't obeying the character encoding pragma or flag.

Setup of Qt Creator to debug into Qt classes

I want to setup Qt Creator (3.0) in a way, that I can debug into the Qt classes. So I download the corresponding src code (http://gitorious.org/qt/qt5) and install it in a directory (e.g. c:\Qt5\src).
Then I have my own project. Where do I need to set the source code path of Qt (c:\Qt5\src), so I can debug my code, but also into a Qt class where necessary.
-- Edit:Pavel's comment --
Pavel has given a good hint: But I am using a precompiled version of Qt/Qt Creator. So I am basically looking for a solution which does not require me to compile from source. Nevertheless a useful hint. Thanks.
If you are using a prebuilded version just remap the source code location as described in http://doc.qt.io/qtcreator/creator-debugger-engines.html
Mapping Source Paths
To enable the debugger to step into the code and display the source
code when using a copy of the source tree at a location different from
the one at which the libraries where built, map the source paths to
target paths:
Select Tools > Options > Debugger > General > Add.
In the Source path field, specify the source path in the debug information of the executable as reported by the debugger.
In the Target path field, specify the actual location of the source tree on the local machine.
To get "the source path in the debug information of the executable as reported by the debugger", you can activate the "Use Tooltips in Stack-View when Debugging" option by right-clicking in the Stack View and move the mouse over a specific function call.
If you look into the tooltips, you will see references to /Users/qt/work, the Mac deployed debug symbols are pointing there. Of course, this is not documented, as these folks want you to buy enterprise.
If you create the /Users/qt/work directory (as root), then make a soft link to your source directory named qt, everything will work. No need to build anything from source (under Mac that would result in tens of gigs wasted). Same considerations about plugins
Example:
sudo -s
mkdir /Users/qt
cd /Users/qt
mkdir work
cd work
ln -s /Users/your_user_name/Qt/your_qt_release/Src qt
Everything will work. Any source mapping failed here, so leave those alone.
Hope this helps
With Xcode, before you step into the Qt library the first time, enter the following command in the LLDB window:
settings set target.source-map /Users/qt/work/qt /path/to/Qt/5.10.1/Src
(Obviously you'll want to change the version number, as relevant).
But suppose Trolltech changes its build directory, what to do then? (Or, how did the community wiki that gave the /Users/qt/work/qt path find it?) You can guess what the path needs to be by editing /path/to/Qt/5.10.1/clang_64/lib/QtCore.framework.dSYM/Contents/Resources/DWARF/QtCore_debug (or any other Qt library) and searching for some paths. "/Users" seems like a good guess. About 2% into the library you'll start seeing sections with a lot of paths like:
../../include/QtCore/../../src/corelib/kernel^#../../include/QtCore
/../../src/corelib/tools^#global^#/Users/qt/work/qt/qtbase/src/corelib
/../../include/QtCore/../../src/corelib/arch^#/Applications/Xcode.app
/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/<etc>
Look for an absolute path that looks like it could be writable. (/Applications/... would not be a likely build path, for example)
In recent Qt creator (v 4.11) press button "Add Qt Sources"
in Tools > Options > Debugger > General
and select Qt sources file.
Qt5 should be installed by online installer with checked "Qt Debug Information files".
Follow the instructions from Qt here:
"In the run configuration, select Use debug version of frameworks."

how to recompile Qt statically?

I searched whole internet for this problem.
I want compile Qt statically to run my program without any DLL.
I read several instructions in the internet.that they all told me sth like this:
cd %qtdir%
configure -static -[other option]
make sub-src
but when I use make in cmd,I get this error :
'make' is not recognized as an internal or external command,operable program or batch file.
and I tried nmake and mingw32-make too. I don't know in what qt directory I must do this.
I wanna a very simple instruction...
In Linux the default compiler is g++, which provices "make". If you are on Windows, and you want to use "make", you need to install the mingw distribution[1].
As pointed out by Dídac Pérez, if you want to use the MSVC compiler[2], you should use the visual studio command prompt, that sets all the environmental variables for you by calling a bat file.
Therefore the instructions would be:
open a visual studio command prompt and navigate to your Qt source
directory
type "make confclean" to remove traces from a previous compilation
setup a static configuration, by passing the adequate flag (e.g.:
"configure -static ")
type "nmake" to call the visual studio compiler
get a cup of coffee and wait a couple of hours (depending on your
processor(s) :-))
[1]http://www.mingw.org/
[2]http://www.visualstudio.com/en-us/downloads#d-2010-express

run a "source" bash shell script in qmake

I want to use the intel compiler for Qt, but using the intel compiler implies running the script
$ source /opt/intel/bin/compilervars.sh intel64
Of course, I could add this to ~/.bashrc, but this would not run it in QtCreator, where it still complains about missing icpc. So I want it to be a part of the main mkspec qmake file.
How can I execute that full bash command in qmake?
Short Answer: Using QMAKE_EXTRA_TARGETS and PRE_TARGET_DEPS, you can execute source /opt/intel/bin/compilersvars.sh intel64, but simply sourcing them will not solve your issue.
Long Answer: The QMake file is converted into a Makefile. Make then executes the Makefile. The problem you will run into is that Make executes each command in its own shell. Thus, simply sourcing the script will only affect one command, the command that executes the script.
There are a couple of possible ways to make things work:
Execute the script before starting Qt-Creator. I've actually done this for some projects where I needed to have special environment variables setup. To make my life easier, I created a shell command to setup the environment and then launch Qt-Creator.
Within Qt-Creator, modify the Build Environment for the project I've also used this trick. In your case, simply look at the environment setup by the script and change the "Build Environment" settings under the project tab for your project to match those setup by the script.
It might also be possible to modify QMake's compiler commands, but I am not sure you can make it execute two commands instead of one (source the script then execute the compiler). Further more, this will make the project very un-transportable to other systems.
You can create a shell script that does more or less the following:
#! /usr/bin/env sh
# Remove the script's path from the PATH variable to avoid recursive calls
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PATH=${PATH/$SCRIPT_DIR:/}
# Set the environment up
source /opt/intel/bin/compilervars.sh intel64
# Call make with the given arguments
make "$#"
Save it into a file named "make" in an empty directory somewhere, make it executable, then change the build environment in QT Creator to prepend PATH with the script's directory:
PATH=[dir-of-make-script]:${Env:PATH}
You can do this either in the project settings or once and for all in the kit settings.
Like this, QT Creator will be fooled into calling your make script which sets up your environment before calling the actual make binary. I use a similar technique under Windows with Linux cross-toolchains and it has been working well so far.

Resources