How to create .DEB package for Unix Debian-like systems

This guide isn’t complete. Create valid .DEB file is a much harder than I thought. So I will create .DEB file (and update this article) when I will have a more free time.

This is how now looks lintian result ;-( :

dev@user-virtual-machine:~/dev/Applications/AtomixDevelopment/DeployInfo/Ubuntu$ lintian ormdesigner.deb 
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/OrmDesigner2
E: orm-designer: unstripped-binary-or-object usr/share/orm-designer/OrmDesigner2
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libQtCore.so.4
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libQtGui.so.4
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libboost_chrono.so
E: orm-designer: unstripped-binary-or-object usr/share/orm-designer/libs/libboost_chrono.so
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libboost_chrono.so.1.49.0
E: orm-designer: unstripped-binary-or-object usr/share/orm-designer/libs/libboost_chrono.so.1.49.0
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libboost_date_time.so.1.49.0
E: orm-designer: unstripped-binary-or-object usr/share/orm-designer/libs/libboost_date_time.so.1.49.0
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libboost_filesystem.so.1.49.0
E: orm-designer: unstripped-binary-or-object usr/share/orm-designer/libs/libboost_filesystem.so.1.49.0
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libboost_iostreams.so.1.49.0
E: orm-designer: unstripped-binary-or-object usr/share/orm-designer/libs/libboost_iostreams.so.1.49.0
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libboost_regex.so.1.49.0
E: orm-designer: unstripped-binary-or-object usr/share/orm-designer/libs/libboost_regex.so.1.49.0
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libboost_system.so.1.49.0
E: orm-designer: unstripped-binary-or-object usr/share/orm-designer/libs/libboost_system.so.1.49.0
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libboost_thread.so.1.49.0
E: orm-designer: unstripped-binary-or-object usr/share/orm-designer/libs/libboost_thread.so.1.49.0
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libexslt.so.0
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libxml2.so.2
E: orm-designer: embedded-library usr/share/orm-designer/libs/libxml2.so.2: libxml2
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libxslt.so.1
E: orm-designer: arch-dependent-file-in-usr-share usr/share/orm-designer/libs/libyaml-cpp.so.0.2
E: orm-designer: unstripped-binary-or-object usr/share/orm-designer/libs/libyaml-cpp.so.0.2
W: orm-designer: unknown-control-file control~
E: orm-designer: control-file-has-bad-permissions postinst 0775 != 0755
E: orm-designer: control-file-has-bad-owner postinst dev/dev != root/root
W: orm-designer: unknown-control-file postinst~
E: orm-designer: control-file-has-bad-permissions postrm 0775 != 0755
E: orm-designer: control-file-has-bad-owner postrm dev/dev != root/root
W: orm-designer: unknown-control-file postrm~
E: orm-designer: no-copyright-file
W: orm-designer: extended-description-line-too-long
W: orm-designer: package-relation-with-self breaks: orm-designer (<< 2.0.1)
E: orm-designer: wrong-file-owner-uid-or-gid usr/ 1001/1001
W: orm-designer: non-standard-dir-perm usr/ 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/ 1001/1001
W: orm-designer: non-standard-dir-perm usr/share/ 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/ 1001/1001
W: orm-designer: non-standard-dir-perm usr/share/orm-designer/ 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/OrmDesigner2 1001/1001
W: orm-designer: non-standard-executable-perm usr/share/orm-designer/OrmDesigner2 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/ 1001/1001
W: orm-designer: non-standard-dir-perm usr/share/orm-designer/libs/ 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libQtCore.so.4 1001/1001
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libQtGui.so.4 1001/1001
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libboost_chrono.so 1001/1001
W: orm-designer: non-standard-executable-perm usr/share/orm-designer/libs/libboost_chrono.so 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libboost_chrono.so.1.49.0 1001/1001
W: orm-designer: non-standard-executable-perm usr/share/orm-designer/libs/libboost_chrono.so.1.49.0 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libboost_date_time.so.1.49.0 1001/1001
W: orm-designer: non-standard-executable-perm usr/share/orm-designer/libs/libboost_date_time.so.1.49.0 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libboost_filesystem.so.1.49.0 1001/1001
W: orm-designer: non-standard-executable-perm usr/share/orm-designer/libs/libboost_filesystem.so.1.49.0 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libboost_iostreams.so.1.49.0 1001/1001
W: orm-designer: non-standard-executable-perm usr/share/orm-designer/libs/libboost_iostreams.so.1.49.0 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libboost_regex.so.1.49.0 1001/1001
W: orm-designer: non-standard-executable-perm usr/share/orm-designer/libs/libboost_regex.so.1.49.0 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libboost_system.so.1.49.0 1001/1001
W: orm-designer: non-standard-executable-perm usr/share/orm-designer/libs/libboost_system.so.1.49.0 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libboost_thread.so.1.49.0 1001/1001
W: orm-designer: non-standard-executable-perm usr/share/orm-designer/libs/libboost_thread.so.1.49.0 0775 != 0755
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libexslt.so.0 1001/1001
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libxml2.so.2 1001/1001
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libxslt.so.1 1001/1001
E: orm-designer: wrong-file-owner-uid-or-gid usr/share/orm-designer/libs/libyaml-cpp.so.0.2 1001/1001
W: orm-designer: maintainer-script-ignores-errors postinst
W: orm-designer: maintainer-script-ignores-errors postrm~
W: orm-designer: maintainer-script-ignores-errors postrm
W: orm-designer: maintainer-script-ignores-errors postinst~
E: orm-designer: shlib-with-executable-bit usr/share/orm-designer/libs/libboost_chrono.so 0775
E: orm-designer: shlib-with-executable-bit usr/share/orm-designer/libs/libboost_chrono.so.1.49.0 0775
E: orm-designer: shlib-with-executable-bit usr/share/orm-designer/libs/libboost_date_time.so.1.49.0 0775
E: orm-designer: shlib-with-executable-bit usr/share/orm-designer/libs/libboost_filesystem.so.1.49.0 0775
E: orm-designer: shlib-with-executable-bit usr/share/orm-designer/libs/libboost_iostreams.so.1.49.0 0775
E: orm-designer: shlib-with-executable-bit usr/share/orm-designer/libs/libboost_regex.so.1.49.0 0775
E: orm-designer: shlib-with-executable-bit usr/share/orm-designer/libs/libboost_system.so.1.49.0 0775
E: orm-designer: shlib-with-executable-bit usr/share/orm-designer/libs/libboost_thread.so.1.49.0 0775

Prerequisities

sudo apt-get install build-essential autoconf automake autotools-dev dh-make debhelper devscripts fakeroot xutils lintian pbuilder

Commands

#creates .deb file
dpkg -b ormdesigner-2.0.1 ormdesigner.deb

#validate .deb file
lintian ormdesigner

How to add screenshot to .DEB file

http://screenshots.debian.net/
http://stackoverflow.com/questions/4776624/how-to-create-deb-package-with-screenshot-for-ubuntu

Errors

E: orm-designer: wrong-file-owner-uid-or-gid usr/ 1001/1001
...

External links

http://www.ibm.com/developerworks/linux/library/l-debpkg/index.html
How to create DEB from source files
How to remove some litian errors

How to create nice MacOS DMG installer

In this article I will show how to create DMG installer in reusable way. The most of things and ideas presented here are ideas from several articles mentioned on the end of this article.

1) As first step we need to create our DMG template with link to Applications.
2) Next we have to modify the visual representation of DMG file.
3) Next we store created DMG as template
4) Now mount copied template as directory, fill DMG with real files
5) Detach mounted DMG, pack DMG
6) Distribute app 😉

More detailed info about all these steps you will find in articles mentioned below. Here is a short script I wrote for three-phase deploying (1) create template, 2) pack template, 3)fill template with real data and compress it)

#! /bin/bash

TEMPLATE_DMG=atomix-development-template.dmg
VOLUME_NAME="Atomix Development"
APPLICATION_FILE_NAME="AtomixDevelopment.app"

if [ "$1" = "create-template" ]
then
  echo Create DMG template
  mkdir template
  cd template
  mkdir $APPLICATION_FILE_NAME
  touch $APPLICATION_FILE_NAME/fake
  ln -s /Applications/ Applications
  cd ..
  rm $TEMPLATE_DMG
  rm $TEMPLATE_DMG.bz2
  hdiutil create -fs HFSX -layout SPUD -size 100m "$TEMPLATE_DMG" -srcfolder template -format UDRW -volname "$VOLUME_NAME" -quiet
  rm -rf template
elif [ "$1" = "zip-template" ]
then
  echo Zipping DMG template
  bzip2 "$TEMPLATE_DMG"
elif [ "$1" = "create-dmg" ]
then
  echo Creating DMG file from template and data

  #unzip template
  rm $TEMPLATE_DMG
  bunzip2 -k $TEMPLATE_DMG.bz2

  #create pack path and attach DMG
  PACK_PATH=`pwd`/dmg-pack
  mkdir $PACK_PATH
  hdiutil attach "$TEMPLATE_DMG" -noautoopen -quiet -mountpoint "$PACK_PATH"

  #copy new content to DMG
  cp -r "$2" "$PACK_PATH"
  rm $PACK_PATH/$APPLICATION_FILE_NAME/fake

  #detach DMG, remove mount path
  hdiutil detach "$PACK_PATH" -force -quiet
  rm -rf $PACK_PATH

  #compress DMG
  hdiutil convert -format UDZO -o tmp-packer-output.dmg "$TEMPLATE_DMG" -imagekey zlib-level=9
  rm ./$TEMPLATE_DMG
  mv ./tmp-packer-output.dmg $TEMPLATE_DMG

  #rm $TEMPLATE_DMG
else
  echo Missing parameter
  echo "create-dmg [create|zip-template|create-dmg Path/Application.app]"
fi

So, it looks like that DMG file for ORM Designer2 is ready 😉

Another tools to create DMG package

External links

http://codevarium.gameka.com.br/how-to-create-your-own-beautiful-dmg-files/
http://el-tramo.be/guides/fancy-dmg/
http://stackoverflow.com/questions/96882/how-do-i-create-a-nice-looking-dmg-for-mac-os-x-using-command-line-tools
http://stackoverflow.com/questions/8680132/creating-nice-dmg-installer-for-mac-os-x
http://stackoverflow.com/questions/2104364/how-to-install-a-qt-application-on-a-customers-system

How to deploy Qt application on MacOS – part II

In first part of this article I introduced a manual way how to deploy MacOS application. Because doing all these stuff manually was a lot of hand work, Qt introduced small tool called macdeployqt.

This utility looks very good, but also have some drawbacks. As first I will show you how utility works:

macdeployqt Application.app

That’s all ;-). This command should do all the hard work for you. But in some cases it didn’t.

ERROR: no file at "/usr/lib/libboost_iostreams.dylib"
ERROR: no file at "/usr/lib/libboost_filesystem.dylib"
ERROR: no file at "/usr/lib/libboost_system.dylib"
ERROR: no file at "/usr/lib/libboost_thread.dylib"
ERROR: no file at "/usr/lib/libboost_date_time.dylib"
ERROR: no file at "/usr/lib/libboost_regex.dylib"
ERROR: no file at "/usr/lib/libboost_chrono.dylib"
ERROR: no file at "/usr/lib/libyaml-cpp.0.2.dylib"

The problem is that libraries mentioned in the previous list doesn’t has included absolute path. If you inspecit this library, you will se this:

otool -L libboost_regex.dylib
libboost_regex.dylib:
	libboost_regex.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

And this is the problem. Inner path in library is only filename without full path, so when we link library with our executable, our executable also has only relative path. And when macdeployqt try to find this library, automatically try to search in /usr/lib.

One possible solution is copy libraries to /usr/lib. Second solution is update paths in libraries to absolute paths. The third way is fix library linker to include full paths in libraries.

I found out that the simplies way how to fix it is call install_name_tool after library compilation and fix the path (don’t forget to update library paths inside other library paths!)

  install_name_tool -id "$SHL_PATH/boost/lib/libboost_chrono.dylib" $SHL_PATH/boost/lib/libboost_chrono.dylib
  install_name_tool -id "$SHL_PATH/boost/lib/libboost_date_time.dylib" $SHL_PATH/boost/lib/libboost_date_time.dylib
  ...
  install_name_tool -change "libboost_system.dylib" "$SHL_PATH/boost/lib/libboost_system.dylib" $SHL_PATH/boost/lib/libboost_chrono.dylib
  install_name_tool -change "libboost_system.dylib" "$SHL_PATH/boost/lib/libboost_system.dylib" $SHL_PATH/boost/lib/libboost_filesystem.dylib

So, now when we have updated all libraries, we can try to create application bundle again

macdeployqt AtomixDevelopment.app/

And if we did everything correctly, now we should have a working app ;-).

Troubleshooting

In some cases you can get error “Permission defined”, “Bad file descriptor” or other similar errors when using macdeployqt.

ERROR: "install_name_tool: can't open input file: OrmDesigner2.app/Contents/Frameworks//libssl.1.0.0.dylib for writing (Permission denied)
install_name_tool: can't lseek to offset: 0 in file: OrmDesigner2.app/Contents/Frameworks//libssl.1.0.0.dylib for writing (Bad file descriptor)
install_name_tool: can't write new headers in file: OrmDesigner2.app/Contents/Frameworks//libssl.1.0.0.dylib (Bad file descriptor)
install_name_tool: can't close written on input file: OrmDesigner2.app/Contents/Frameworks//libssl.1.0.0.dylib (Bad file descriptor)

The reason is insufficient permissions for modifying copied libraries. Simple execute

sudo macdeployqt

and everything should work ok. Another workaround for this issue is using newer version of Qt. I figured out that on MacOS I wrongly use Qt 4.7.4. When I correct this to version Qt 4.8.2 this issue was solved.

DMG file

If you want to create simply DMG file, simply call macdeployqt with param –dmg. But this dmg doesn’t look so good:

This will need more investigation how to make DMG files nicer ;-).

Notes

  • Everytime you run macdeployqt run it on clean folder. The best way is to call rm -rf Application, compile app and than run macdeployqt

Notes to bug in macdeployqt

The problem is caused by invalid permissions. Copied libraries have the same permissions like in the source location. There are three different solutions:

  1. Use sudo and execute macdeployqt with root permissions
  2. Update external libraries permissions to rw, so also copies will have a correct permissions
  3. Update macdeployqt script. In file shared.cpp on line 91 is method copyFilePrintStatus. Here is a necessary to update copied files permissions to correct rw

In my case the problem was in file liblzma.5.dylib

Frameworks/liblzma.5.dylib is not writable (Permission denied)

Orinal library is located in path:

/usr/local/Cellar/xz/5.0.4/lib

How to hack HOME and END keys on MacOS to behave like on Windows

It’s really annoying that HOME and END on MacOS behaves differently than on Windows. If you want to remap all these keys, use tool called KeyRemap4MacBook.

Not working solution 😉

Here is simply way how to change it (copied from evansweb):

I have found a way to “fix” this problem by editing the default keybindings file,~/Library/KeyBindings/DefaultKeyBinding.dict. Create the directory and / or the file if they’re not already there, and make it look like this:

{
        /* Remap Home / End to be correct :-) */
        "\UF729"  = "moveToBeginningOfLine:";                   /* Home         */
        "\UF72B"  = "moveToEndOfLine:";                         /* End          */
        "$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
        "$\UF72B" = "moveToEndOfLineAndModifySelection:";       /* Shift + End  */
}

External source:
http://lifehacker.com/225873/mac-switchers-tip–remap-the-home-and-end-keys
http://evansweb.info/2005/03/24/mac-os-x-and-home-end-keys
http://soodev.wordpress.com/2011/07/04/mac-os-x-remapping-home-and-end-keys/

How to deploy Qt application on MacOS – part I

As I wrote yesterday, I found the way how to proceed deployment on the Linux system. Today I have to manage it the same on the MacOS systems.

Note: the simplest way is introduced in the second part of this article.

The first usefull command for tracking dependencies between your application and other shared libraries is otool:

#path to executable, not .App directory!
otool -L Application.app/Contents/MacOS/AppExecutable

Now we can see paths to our libraries. The bad news is that MacOS doesn’t have any -RPATH and $ORIGIN. The good news is utility install_name_tool and variable @executable_path which works similar like $ORIGIN.
Note: For newer versions of MacOS there are more variables like @executable_path. On version 10.4 was introduced @loader_path and on version 10.5 apple introduce @rpath variable.

The step-by-step solution

As first step it’s necessary to upload all dependent libraries directly to the Application.app/Contents/MacOS/. For list all required files use otool:

cd Application.app/Contents/MacOS
otool -L AppExecutable

When we have copied all libraries, we need to change paths for and in all libraries.

Here is example how to set libxml2 library. As first step we will check how is library referred.

$user otool -L AtomixDevelopment

AtomixDevelopment:
	libboost_iostreams.dylib (compatibility version 0.0.0, current version 0.0.0)
	libboost_filesystem.dylib (compatibility version 0.0.0, current version 0.0.0)
	/Users/User/dev/SharedLibraries/libxml/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.8.0)
	/Users/User/dev/SharedLibraries/libxslt/lib/libxslt.1.dylib (compatibility version 3.0.0, current version 3.26.0)
	/Users/User/dev/SharedLibraries/libxslt/lib/libexslt.0.dylib (compatibility version 9.0.0, current version 9.15.0)

And Library:

User$ otool -L libxml2.2.dylib
libxml2.2.dylib:
	/Users/User/dev/SharedLibraries/libxml/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.8.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
	/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)

When we checked libxml2.2.dylib library with otool, we can see that library has hardocoded our development path. This isn’t good ;-). So we now change this value to path relative to the executable and again verify this inner path.

install_name_tool -id "@loader_path/libxml2.2.dylib" libxml2.2.dylib
otool -L libxml2.2.dylib
libxml2.2.dylib:
	@loader_path/libxml2.2.dylib (compatibility version 10.0.0, current version 10.8.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
	/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)

As you can see, now is path (first line) set up to reffer @loader_path/libxml2.2.dylib. It’s correct now. As second step we have to update path in our executable, because also there is path hardcoded to our library repository.

install_name_tool -change "/Users/User/dev/ExternalLibraries/../SharedLibraries/libxml/lib/libxml2.2.dylib" "@loader_path/libxml2.2.dylib" AtomixDevelopment

otool -L AtomixDevelopment
AtomixDevelopment:
	libboost_iostreams.dylib (compatibility version 0.0.0, current version 0.0.0)
	libboost_filesystem.dylib (compatibility version 0.0.0, current version 0.0.0)
	@loader_path/libxml2.2.dylib (compatibility version 10.0.0, current version 10.8.0)
        ...

So, now we have changed also path in our executable. And now we need to do all these steps for all libraries….. ;-).

 

Notes

To follow the MacOS application convention it’s better to place libraries to folder Application.app/Contents/Frameworks. Here is a directory schema for Qt example application plugAndPaint.

External links

Why is compiled Linux executable so large?

Today I encountered another issue when compiling my Qt application http://www.orm-designer.com/ under Linux. The size of final executable was about 400MB.
The first thought was that there is some static libraries compiled to application. But the problem was elsewhere.

Unlike to Windows compilation where linker creates .exe and .pdb file, linux linker creates only one final file. So this file includes also lot of additional symbols useful for debugging and post-mortem bugs finding. But it is not so usefull for distribution your application. To strip all these symbols, use following command

strip --strip-unneeded /path/to/application

Strip command have a lot of switches, but after a short testing it seems that the results are the same. Maybe I’m doing something wrong or simply my executable doesn’t contain any additional infos for stripping.

The most easiest way how to deploy Qt linux Application

I found solution also for the problem with executing application form in-app directory!!, Look to text bellow.
Warning: This solution has one big disadvantage ;-(. It’s necessary to execute application only from app-dir. In other cases system doesn’t find required libraries.
The solution could be run patchelf on the client computer with final installation path

Today I start working on deploying my http://www.orm-designer.com/ Qt application on linux platform.

I read a lot of articles about deploying applications but all of the suggested methods was impractical, too complex or unusable. Here is a list of them:

  • Using qt.conf in Qt resource or application dir. Usefull for Qt libraries, but not third party libraries
  • Installing Qt and third-party libraries in one of the system library path. This method need root permission for app users
  • Using startup script for setting correct LD_LIBRARY_PATH. Really? It’s too complicated for maintenance and users
  • Using -rpath to specify predetermined path. This method requires the users have this directory and have the full access to this directory

Another solution, the simplest one

I’m not sure why this solution isn’t mentioned in Qt forums or anywhere else. Maybe this solution isn’t so clean and perfect for Linux gurus, but it’s perfect for me.

The solution is in simply changing the search path in already compiled application to “.” (current directory) current application location by using $ORIGIN variable, so application will search all libraries in application directory first. It’s simple, it’s clean. All libraries distributed with application will be isolated in application directory and app-loader will not load any other library by mistake.

Updated: The keyword $ORIGIN do the trick, that you can run application from anywhere on your computer. $ORIGIN is absolute path to your executable.

And how to do this change? As first, you need to download small utility called PatchELF. With this application you can change -rpath in app to anything you need.

patchelf --set-rpath '$ORIGIN' ./ApplicationExecutable

And it is. Now you can copy all required libraries to directory with your application and everything will works correctly.

Installation

Download Ubuntu 32/64bit package from site http://hydra.nixos.org/release/patchelf/patchelf-0.6

Note

Maybe there is a way how to set rpath directly in the linking proces by using -rpath linker param. But I didn’t manage it to work.

If you want to display list of shared libraries used by your application, use this command:

ldd ./ApplicationExecutable

External links

Linux find usage


#syntax
#find [SETTINGS] PATH [EXPR]

#write all files
find

#write all files in specified diretory
find /usr/dev

#write files with extension .pro
find /usr/dev -name "*.pro"

#write "file"
find /usr/dev -name "*.pro" | echo file

#wite file followed by all files in ONE row
find /usr/dev -name "*.pro" | xargs echo file

#write found file to specified position in echo command (char $ can be raplaced by anything else, for examle {} )
find /usr/dev -name "*.pro" | xargs -I $ echo file: $

#change date time in all *.pro files 
find /usr/dev -name "*.pro" | xargs -I $ touch -t 201208131010 $

#find specified texts in files
grep "text" *.pro

#find texts and write also a file name
grep -H "text" *

#write only file names (really don't know how it works ;-) )
grep -h "text" * | cut -d: -f1

#change privileges for files with content
grep -h "text" * | cut -d: -f1 | xargs -I $ chmod 777 $

Problem with Qt 4.8.2 QWebkit compilation under Ubuntu

The error message is following:

In file included from /usr/include/glib-2.0/glib/gasyncqueue.h:34:0,
                 from /usr/include/glib-2.0/glib.h:34,
                 from /usr/include/glib-2.0/gobject/gbinding.h:30,
                 from /usr/include/glib-2.0/glib-object.h:25,
                 from /usr/include/glib-2.0/gio/gioenums.h:30,
                 from /usr/include/glib-2.0/gio/giotypes.h:30,
                 from /usr/include/glib-2.0/gio/gio.h:28,
                 from wtf/gobject/GOwnPtr.cpp:24:
/usr/include/glib-2.0/glib/gthread.h:51:16: error: ‘union’ tag used in naming ‘struct _GMutex’ [-fpermissive]
/usr/include/glib-2.0/glib/gthread.h:58:7: error: ‘union’ tag used in naming ‘struct _GMutex’ [-fpermissive]
make[2]: *** [.obj/release-static/GOwnPtr.o] Error 1
make[2]: Leaving directory `/home/honza/qt-everywhere-opensource-src-4.8.2/src/3rdparty/webkit/Source/JavaScriptCore'
make[1]: *** [sub-JavaScriptCore-JavaScriptCore-pro-make_default-ordered] Error 2
make[1]: Leaving directory `/home/honza/qt-everywhere-opensource-src-4.8.2/src/3rdparty/webkit/Source'
make: *** [sub-webkit-make_default-ordered] Error 2

the reason is because of incompatibility between Qt 4.8.2 and glib-2.0.

The solution is described in this (not commited) bug fix:

https://codereview.qt-project.org/#patch,sidebyside,25069,1,src/3rdparty/webkit/Source/JavaScriptCore/wtf/gobject/GTypedefs.h

Simply edit following file

Qt/src/3rdparty/webkit/Source/JavaScriptCore/wtf/gobject/GTypedefs.h

and modify following line

55: typedef struct _GMutex GMutex;

to

55: typedef union _GMutex GMutex;

that’s it.

Qmake 4.8.2 unresolved external symbol QSystemLocale

So, after updating my Qt version to 4.8.2 I encounter another compilation problems (as usual 😉 ).

As first, this is my linker output:

qlocale.obj : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QSystemLocale::query(enum QSystemLocale::QueryType,class QVariant)const " (?query@QSystemLocale@@UBE?AVQVariant@@W4QueryType@1@V2@@Z)
1>qlocale.obj : error LNK2001: unresolved external symbol "public: virtual class QLocale __thiscall QSystemLocale::fallbackLocale(void)const " (?fallbackLocale@QSystemLocale@@UBE?AVQLocale@@XZ)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString & __cdecl decimalForm(class QChar,class QChar,class QChar,class QString &,int,unsigned int,enum PrecisionMode,bool,bool)" (?decimalForm@@YAAAVQString@@VQChar@@00AAV1@HIW4PrecisionMode@@_N3@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString & __cdecl exponentForm(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,class QString &,int,unsigned int,enum PrecisionMode,bool)" (?exponentForm@@YAAAVQString@@VQChar@@00000AAV1@HIW4PrecisionMode@@_N@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "char * __cdecl qdtoa(double,int,int,int *,int *,char * *,char * *)" (?qdtoa@@YAPADNHHPAH0PAPAD1@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString __cdecl qulltoa(unsigned __int64,int,class QChar)" (?qulltoa@@YA?AVQString@@_KHVQChar@@@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::longLongToString(class QChar,class QChar,class QChar,class QChar,__int64,int,int,int,unsigned int)" (?longLongToString@QLocalePrivate@@SA?AVQString@@VQChar@@000_JHHHI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString __cdecl qlltoa(__int64,int,class QChar)" (?qlltoa@@YA?AVQString@@_JHVQChar@@@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::longLongToString(class QChar,class QChar,class QChar,class QChar,__int64,int,int,int,unsigned int)" (?longLongToString@QLocalePrivate@@SA?AVQString@@VQChar@@000_JHHHI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "bool __cdecl removeGroupSeparators(class QVarLengthArray<char,256> *)" (?removeGroupSeparators@@YA_NPAV?$QVarLengthArray@D$0BAA@@@@Z) referenced in function "public: bool __thiscall QLocalePrivate::numberToCLocale(class QString const &,enum QLocalePrivate::GroupSeparatorMode,class QVarLengthArray<char,256> *)const " (?numberToCLocale@QLocalePrivate@@QBE_NABVQString@@W4GroupSeparatorMode@1@PAV?$QVarLengthArray@D$0BAA@@@@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "double __cdecl qstrtod(char const *,char const * *,bool *)" (?qstrtod@@YANPBDPAPBDPA_N@Z) referenced in function "public: static double __cdecl QLocalePrivate::bytearrayToDouble(char const *,bool *,bool *)" (?bytearrayToDouble@QLocalePrivate@@SANPBDPA_N1@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "__int64 __cdecl qstrtoll(char const *,char const * *,int,bool *)" (?qstrtoll@@YA_JPBDPAPBDHPA_N@Z) referenced in function "public: static __int64 __cdecl QLocalePrivate::bytearrayToLongLong(char const *,int,bool *,bool *)" (?bytearrayToLongLong@QLocalePrivate@@SA_JPBDHPA_N1@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "unsigned __int64 __cdecl qstrtoull(char const *,char const * *,int,bool *)" (?qstrtoull@@YA_KPBDPAPBDHPA_N@Z) referenced in function "public: static unsigned __int64 __cdecl QLocalePrivate::bytearrayToUnsLongLong(char const *,int,bool *)" (?bytearrayToUnsLongLong@QLocalePrivate@@SA_KPBDHPA_N@Z)
1>..\bin\\qmake.exe : fatal error LNK1120: 11 unresolved externals

The reason for this is missing two definitions in qmake.pri.

First is system-dependent qlocale_win.cpp / qlocale_unix.cpp. For fixing it you have to update these to files to unix{} and win32{}

 unix {
        SOURCES += qfilesystemengine_unix.cpp qfilesystemiterator_unix.cpp qfsfileengine_unix.cpp qlocale_unix.cpp #<<---- HERE
        mac {
          SOURCES += qfilesystemengine_mac.cpp
          SOURCES += qcore_mac.cpp qsettings_mac.cpp
          QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4 #enables weak linking for 10.4 (exported)
          LIBS += -framework ApplicationServices
        }
    } else:win32 {
        SOURCES += qfilesystemengine_win.cpp qfsfileengine_win.cpp qfilesystemiterator_win.cpp qsettings_win.cpp \
            qsystemlibrary.cpp qlocale_win.cpp #<<--------- AND HERE
        win32-msvc*:LIBS += ole32.lib advapi32.lib
        win32-g++*:LIBS += -lole32 -luuid -ladvapi32 -lkernel32
    }

If you update .pri like this, you will gain another cute unresolved external:

qlocale.obj : error LNK2019: unresolved external symbol "class QString & __cdecl decimalForm(class QChar,class QChar,class QChar,class QString &,int,unsigned int,enum PrecisionMode,bool,bool)" (?decimalForm@@YAAAVQString@@VQChar@@00AAV1@HIW4PrecisionMode@@_N3@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString & __cdecl exponentForm(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,class QString &,int,unsigned int,enum PrecisionMode,bool)" (?exponentForm@@YAAAVQString@@VQChar@@00000AAV1@HIW4PrecisionMode@@_N@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "char * __cdecl qdtoa(double,int,int,int *,int *,char * *,char * *)" (?qdtoa@@YAPADNHHPAH0PAPAD1@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::doubleToString(class QChar,class QChar,class QChar,class QChar,class QChar,class QChar,double,int,enum QLocalePrivate::DoubleForm,int,unsigned int)" (?doubleToString@QLocalePrivate@@SA?AVQString@@VQChar@@00000NHW4DoubleForm@1@HI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString __cdecl qulltoa(unsigned __int64,int,class QChar)" (?qulltoa@@YA?AVQString@@_KHVQChar@@@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::longLongToString(class QChar,class QChar,class QChar,class QChar,__int64,int,int,int,unsigned int)" (?longLongToString@QLocalePrivate@@SA?AVQString@@VQChar@@000_JHHHI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "class QString __cdecl qlltoa(__int64,int,class QChar)" (?qlltoa@@YA?AVQString@@_JHVQChar@@@Z) referenced in function "public: static class QString __cdecl QLocalePrivate::longLongToString(class QChar,class QChar,class QChar,class QChar,__int64,int,int,int,unsigned int)" (?longLongToString@QLocalePrivate@@SA?AVQString@@VQChar@@000_JHHHI@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "bool __cdecl removeGroupSeparators(class QVarLengthArray<char,256> *)" (?removeGroupSeparators@@YA_NPAV?$QVarLengthArray@D$0BAA@@@@Z) referenced in function "public: bool __thiscall QLocalePrivate::numberToCLocale(class QString const &,enum QLocalePrivate::GroupSeparatorMode,class QVarLengthArray<char,256> *)const " (?numberToCLocale@QLocalePrivate@@QBE_NABVQString@@W4GroupSeparatorMode@1@PAV?$QVarLengthArray@D$0BAA@@@@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "double __cdecl qstrtod(char const *,char const * *,bool *)" (?qstrtod@@YANPBDPAPBDPA_N@Z) referenced in function "public: static double __cdecl QLocalePrivate::bytearrayToDouble(char const *,bool *,bool *)" (?bytearrayToDouble@QLocalePrivate@@SANPBDPA_N1@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "__int64 __cdecl qstrtoll(char const *,char const * *,int,bool *)" (?qstrtoll@@YA_JPBDPAPBDHPA_N@Z) referenced in function "public: static __int64 __cdecl QLocalePrivate::bytearrayToLongLong(char const *,int,bool *,bool *)" (?bytearrayToLongLong@QLocalePrivate@@SA_JPBDHPA_N1@Z)
1>qlocale_win.obj : error LNK2001: unresolved external symbol "__int64 __cdecl qstrtoll(char const *,char const * *,int,bool *)" (?qstrtoll@@YA_JPBDPAPBDHPA_N@Z)
1>qlocale.obj : error LNK2019: unresolved external symbol "unsigned __int64 __cdecl qstrtoull(char const *,char const * *,int,bool *)" (?qstrtoull@@YA_KPBDPAPBDHPA_N@Z) referenced in function "public: static unsigned __int64 __cdecl QLocalePrivate::bytearrayToUnsLongLong(char const *,int,bool *)" (?bytearrayToUnsLongLong@QLocalePrivate@@SA_KPBDHPA_N@Z)
1>qlocale_win.obj : error LNK2001: unresolved external symbol "unsigned __int64 __cdecl qstrtoull(char const *,char const * *,int,bool *)" (?qstrtoull@@YA_KPBDPAPBDHPA_N@Z)
1>..\bin\\qmake.exe : fatal error LNK1120: 9 unresolved externals

Also this linker error is caused by missing file in SOURCE definition. In this case add qlocale_tools.cpp to SOURCE in bootstrap { #Qt code


bootstrap { #Qt code
   DEFINES+=QT_NODLL QT_NO_THREAD
   SOURCES+= \
        qbitarray.cpp \
        qbuffer.cpp \
        qbytearray.cpp \
        qbytearraymatcher.cpp \
        qcryptographichash.cpp \
        qdatetime.cpp \
        qdir.cpp \
        qdiriterator.cpp \
        qfile.cpp \
        qabstractfileengine.cpp \
        qfileinfo.cpp \
        qfilesystementry.cpp \
        qfilesystemengine.cpp \
        qfsfileengine.cpp \
        qfsfileengine_iterator.cpp \
        qglobal.cpp \
        qnumeric.cpp \
        qhash.cpp \
        qiodevice.cpp \
        qlist.cpp \
        qlinkedlist.cpp \
        qlocale.cpp \
        qlocale_tools.cpp \  #<< ----- HERE

Now re-call qmake and recompile it. Everything should works ok. The question is, why no-one in Qt didn’t find this error.

Linux c++ linker – “ld terminated with signal 9”

The linker error “ld terminated with signal 9” is caused by low amount of memory for link process. There are two ways how to fix it.

  • First way is increase computer / virtual machine memory.
  • Second way is by increasing swap file size.

How to increase swap file size

#create new swap file 512x1M size filled with zeros
sudo dd if=/dev/zero of=/extraswap bs=1M count=512

#setup file as a swap file
sudo mkswap /extraswap

#enable created swapfile
sudo swapon /extraswap

If you want to use this swap file also after your computer reboot, you have to do also following steps:

#edit fstab
sudo nano /etc/fstab

#add following line to /etc/fstab
/extraswap           swap                    swap    defaults        0 0

[/sourcecode]

Additional swap-file commands

Here is a list of additional commands which can be useful when working with swap file


#show memory information in KB
free -k

#show existing swap file sizes in KB
swapon -s

External articles about this subject:

http://www.thegeekstuff.com/2010/08/how-to-add-swap-space/

https://www.linux.com/learn/tutorials/442430-increase-your-available-swap-space-with-a-swap-file

http://www.saicharan.in/blog/2009/06/30/ld-terminated-with-signal-9/