g++ error: expected primary-expression before > token

For g++ compiler is sometimes necessary to specify more typename / template keywords than for Visual Studio. This is one of examples.

To the following code it’s necessary to add template keyword:

TMemoryManager & memMngr = GetMemoryManager();
m_pObject = 
  memMngr.CreateObject<TObject>(this, m_pContainerOwner);

use

TMemoryManager & memMngr = GetMemoryManager();
m_pObject = 
  memMngr.template CreateObject<TObject>(this, m_pContainerOwner);

MinGW and compilation 32/64bit libraries

Install MinGW-64

1) Download MinGW 64-bit and 32-bit

http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/

http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/

– Toolchains targetting Win64 / Toolchains targetting Win32
– Automated Builds
– mingw-w64-1.0-bin_i686-mingw_*.zip
– mingw-w32-1.0-bin_i686-mingw_*.zip

2) Download MSYS compatible with 64-bit MinGW

http://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20(Win64%20hosted)/MSYS%20(32-bit)/

3) Extract MinGW32, mingw64 and MSYS to one folder

MinGW-32, MinGW-64 and MSYS to folder MinGW64 (Bin folder from MinGW will be merged with bin folder from MSYS, etc.)

External links:

MSYS wiki
MinGW-64 wiki

How to parse Apache Log and insert data to MySQL database

#!/bin/bash

echo Generating new data from log
echo "#generated sql file" > data.sql

echo "truncate table log_data;" >> data.sql
echo "START TRANSACTION;" >> data.sql

FIND_PATTERN="\
\(\S*\)\s*\
\(\S*\)\s*\
\(\S*\s*\S*\)\s*\
[\x5B]\([^\x5D]*\)[\x5D]\s*\
\"\([^\"]*\)\"\s*\
\(\S*\)\s*\
\(\S*\)\s*\
\"\([^\"]*\)\"\s*\
\"\([^\"]*\)\"\s*\
";

REPLACE_PATTERN="\
INSERT INTO log_data \
(domain,ip,other,date,url,status,size,referral,clientstring) \
VALUES \
('\1','\2','\3','\4','\5','\6','\7','\8','\9');";

APACHE_FILE="other_vhosts_access.log";

if [ -f $APACHE_FILE.size ];
then
   ALREADY_PROCEED=`cat $APACHE_FILE.size`
   echo "Already proceed size ($APACHE_FILE): "$ALREADY_PROCEED;
else
   ALREADY_PROCEED=0;
   echo "New log file $APACHE_FILE";
fi

FILTER_PATTERN="\.css|\.ico|\.png|\.jpg|\.txt|\.js|\.gif|\.swf"

#echo $FIND_PATTERN"/"$REPLACE_PATTERN;

cat $APACHE_FILE |
tail -c +$ALREADY_PROCEED | #preskocime jiz zpracovane radky
#head -5000 | #debug
#head   -1128863 | #tail -2  |
#tail -n +1177103 | head -3 |
#sed -r "s/(\(.*\))//g" | #debug - odebere z clientstring (...)
#sed  "s/^[^+]*//g" | #debug - odebere pocatek stringu az do GET
#sed -r "s/Mozilla|Gecko|Firefox//g" | #debug odebere tyhle klicovy slova
sed -r "s/^(subdomain|www)\.//"   | #odebereme prefix subdomain. a www.
sed -r "s/^([^:]*)(:[0-9]*)/\1/"  | #odebereme port
sed -r -n "/^(orm-|inventic).*/p" | #exportujem jen nektere domeny
sed "s/\([\x5c][\x22]\)//g"       | #odebrani \" retezcu
sed "s/\([']\)//g"                | #odebrani apostrof ktery delaj pak bordel v$
sed -r "s/ \"GET ([\x2F].*) HTTP[\x2F][0-9.]*/ \"\1/" | #dame pryc GET a HTTP1.1
#sed -r -n  "/$FILTER_PATTERN/p" #| debug- vypise filtrovane .css/.png/...
sed -r "/$FILTER_PATTERN/d"       | #vyfiltrujeme pryc .css, .png atd
#sed  "/^$FIND_PATTERN$/d"        | #debug - toto lze pouzit na vypis radku kte$
sed -n "/^$FIND_PATTERN$/p"       | #vypiseme vsechny radky ktere jsou validni
sed "s/$FIND_PATTERN/$REPLACE_PATTERN/" >> data.sql

echo "COMMIT;" >> data.sql

#ulozime velikost zpracovaneho logu
stat -c"%s" $APACHE_FILE > $APACHE_FILE.size
#vlozime data do Mysql
echo Putting data to MySQL
mysql \
  --user=root \
  --password=1234 \
  --host=192.168.0.10 \
  --database=server_log < data.sql

Mount error(12): Cannot allocate memory

Problem

When mounting some windows samba drives, “mount error(12)” error can occurred. Problem is in windows samba server settings. Full linux error message:

mount error(12): Cannot allocate memory
Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)

and error message in windows event log:

Source: srv
Event ID: 2017
Level: Error
The server was unable to allocate from the system nonpaged pool because the server reached the configured limit for nonpaged pool allocations.

Solution

Update following registry:

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\LargeSystemCache = 1
HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size = 3

After you update these values, restart your computer.

More about this issue:

http://alan.lamielle.net

How to deploy Qt application on MacOs

Missing dylib libraries

If your application using some externals dynamic libraries (called .dylib in MacOs system), you have to provide all these libraries. The simplest way is to provide these libraries into the Application.app directory.

Find out which libraries are used

Qt provide really useful tool called “otool” which serves to lots of purpose. One of them is to detect which shared libraries are required by our application. For this purpose otool has parameter -L. The usage is following:

otool -L ./Test1.app/Contents/MacOS/Test1

Output could looks like this:

./Test1:
        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)
        libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)
        libboost_thread.dylib (compatibility version 0.0.0, current version 0.0.0)
        libboost_date_time.dylib (compatibility version 0.0.0, current version 0.0.0)
        libboost_regex.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/dev/dev/SharedLibraries/libiconv/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.0.0)
        /Users/dev/dev/ExternalLibraries/../SharedLibraries/libxml/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.8.0)
        /Users/dev/dev/ExternalLibraries/../SharedLibraries/libxslt/lib/libxslt.1.dylib (compatibility version 3.0.0, current version 3.26.0)
        /Users/dev/dev/ExternalLibraries/../SharedLibraries/libxslt/lib/libexslt.0.dylib (compatibility version 9.0.0, current version 9.15.0)
        /Users/dev/dev/ExternalLibraries/yaml-cpp-0.2.5/build/libyaml-cpp.0.2.dylib (compatibility version 0.2.0, current version 0.2.5)
        QtGui.framework/Versions/4/QtGui (compatibility version 4.7.0, current version 4.7.0)
        QtCore.framework/Versions/4/QtCore (compatibility version 4.7.0, current version 4.7.0)
        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)

Output from “otool” is simmilar to linux tool “ldd”.

The Mac Deployment Tool

Because manual copying and configuring all shared libraries to our application could be difficult, Qt have deployment tool which do all work for us. Tool is called “macdeployqt” and can be found in /Developer/Tools/Qt/macdeployqt.

 /Developer/Tools/Qt/macdeployqt ./GeneratedFilesMacOs/Debug/Test1.app

Note: Every time when you call macdeployqt tool, project have to be build from scratch. But is sufficient when whole result directory is removed and linked again:

rm -rf ./GeneratedFilesMacOs/Debug/Test1.app/
make

g++ template method problem

Quick post about problem which I already solved, but think that could be handy for someone else.

I have following code:

template<class T>
struct Test
{
	T val;
	template <class T2>
	void DoSomething( T2 &obj )
	{
		obj.FindByType<int>();
	}
};

When compiling under Visual studio, everything is ok. But when try the same code snippet under g++, have following error:

test.cpp: In member function ‘void Test<T>::DoSomething(T2&)’:
test.cpp:48: error: expected primary-expression before ‘int’
test.cpp:48: error: expected ‘;’ before ‘int’

This is because compiler doesn’t known FindByType method, because T2 is templated argument. The solution which I found is in adding keyword template before FindByType method name. So updated source code will look like this:

template<class T>
struct Test
{
	T val;
	template <class T2>
	void DoSomething( T2 &obj )
	{
		obj.template FindByType<int>();
	}
};

After this update, code will be compiled correctly under both compilers.

Git tips

Show files status

git status #show all files
git statis -u -s #show untracked in short listing

Commit with message

git commit -m"text"

Recursive add files by mask to git

git add *.mask -A

Linux-recursive remove some files

find -iname '*mask' | xargs rm

How to create global .gitignore file

git config --global core.excludesfile /file-path/.gitignore-global

TENG – c++ templating engine

Project site: http://teng.sourceforge.net/?page=home

External project documentation: http://teng.olmik.net/

Latest TENG source code: http://teng.cvs.sourceforge.net/teng/ (Note: Source code referenced from main site isn’t latest! )

How to compile TENG on windows

Compilation under Windows is possible only using MinGW and with few modifications in TENG code (because there is few glitch which didn’t meet c++ standards). If you want more information or updated TENG version, please let me know.

How to install and configure git with ssh key

  • Download git client depends on your OS platform
  • Open your .ppk key in PuTTY Key generator and export key to OpenSSH key:
  • Content of this OpenSSH key store to file ~/.ssh/id_dsa (copy exported key to ~/.ssh folder and rename it to id_dsa)
  • Now change security permissions on this file to 400 (chmod 400 ~/.ssh/id_dsa)
  • Now cal ssh-add to load id_dsa key

And it’s done. Now you can use your git. For example clone some repository:

git clone ssh://git@server/~/repository/example.git

Automatic ssh-key loading during startup:

TODO

Linux tips

Here is few tricks for Linuch which we needed during our exploration of this system 😉

How to change executable flag for scripts recursively

find -iname '*.sh' | xargs chmod 777

How to configure shared library path

Add file atomix.conf to directory /etc/ld.so.conf.d. To this file enter following:

# atomix libraries
/home/USER_NAME/dev/SharedLibraries/libs

and then run

sudo ldconfig

External link: http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

VIM cheat sheet

External link: http://www.tuxfiles.org/linuxhelp/vimcheat.html

How to resize partition

Use gparted

sudo apt-get install gparted

Measure disk write speed

time sh -c "dd if=/dev/zero of=ddfile bs=8k count=100000 && sync"

How to configure Linux for Qt programming.

How to configure script for automatic run after login

Create .bash_profile file in your home directory.

nano ~/.bash_profile

And enter following content to the new created file:

 # ~/.bash_profile
# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

How to configure new search path

If you want to have bin folder in your home directory, enter following code snippet to your .bash_profile file:

PATH=$PATH;/Users/thomas/bin

Conclusion & Note

It’s possible that all of these task can be done in simpler way, or can’t be done at all. All comments and tips are based on my current experience with my first Linux configuration in my life 😉

Qt correct setup for QMAKESPEC, QTDIR and PATH

When you want to use different configurations for different platforms in your .pro file, it’s necessary to correctly setup three variables: QMAKESPEC, QTDIR and PATH.

Here is how to configure for different platforms:

Microsoft Windows:

In SystemPropertes -> Enviroment variables add/update following values:

QTDIR = P:\QT\4.7.0
PATH = %QTDIR%\bin
QMAKESPEC=%QTDIR%\mkspecs\win32-msvc2005
LANG = en_US

Unix Bourne shell: (not tested)

QMAKESPEC=/usr/local/qt/mkspecs/linux-g++
PATH=$PATH:/local/qmake/bin
export QMAKESPEC PATH</pre>

Unix C shell: (not tested)

setenv QMAKESPEC /usr/local/qt/mkspecs/linux-g++
setenv PATH $PATH:/local/qmake/bin</pre>

Note

You can optionally use LANG variable to setup QtCreator language.

Old qt 3.0 guide: http://doc.trolltech.com/3.0/qmake-guide.html
How to configure enviroment: http://doc.qt.nokia.com/4.0/qmake-environment-reference.html

List of known issues and tips

This is list of all known issues and problems which we had to solve during our first Qt installation on Linux, Windows and Mac.

Known errors

Error: undefined interface

What to do when compilation of QT crash with message “Error: undefined interface”.
http://www.qtforum.org/article/31561/error-when-building-libraries.html
http://www.qtcentre.org/threads/26245-Qt-4.6-api/qscriptextensionplugin.h(43)-Error-Undefined-interface

make: g++: Command not found

it’s necessary to instal g++ support (sudo apt-get install g+)

Basic XLib functionality test failed!

it’s necessary to instal xlib(xorg??) support (sudo apt-get install xorg-dev)

*** [sub-corelib-make_default-ordered] Error 2

Probably mishmash on 32bit / 64bit  system and QT versions.

undefined reference to `QEventDispatcherGlib::versionSupported()’

Probably missing libglib2.0-dev on your system. (sudo apt-get install libglib2.0-dev).

Undefined reference to QSslSocket::*

Missing OpenSSL library on your system. (sudo apt-get install libssl-dev)

gtk/gtk.h: No such file or directory

Missing gtk package. (sudo apt-get install libgtk2.0-dev ). After that its necessary to update db (sudo updatedb).

if system can’t find file gtk/gtk.h because gtk is stored in gtk-2.0 directory, add -I (capitalised i) param to configure with gtk path:

./configure -opensource -I /usr/include/gtk-2.0

cups/cups.h: No such file or directory

install libcups2. (sudo apt-get install libcups2-dev)

gst/gst.h: No such file or directory

install gstreamer 0.10. (sudo apt-get install libgstreamer0.10-dev)

Missing Include/glibconfig.h

it’s because this file isn’t in /usr/include/glib-2.0, but in /usr/lib/glib-2.0. So you have to include also this /usr/lib path or copy file to include/glib-2.0

Hints and tips

How to create symbolic link to directory

create symbolic link using ln -nsf /usr/include/gtk-2.0/gtk /usr/include/gtk

Minimal required libraries

List of libraries required by Qt:

  • libfontconfig1-dev
  • libfreetype6-dev
  • libx11-dev
  • libxcursor-dev
  • libxext-dev
  • libxfixes-dev
  • libxft-dev
  • libxi-dev
  • libxrandr-dev
  • libxrender-dev

And other which are required by some modules of Qt:

To install all required on Linux, use following commands

sudo apt-get install libfontconfig1-dev libfreetype6-dev libx11-dev libxcursor-dev libxext-dev libxfixes-dev libxcups/cups.h: No such file or directory ft-dev libxi-dev libxrandr-dev libxrender-dev

sudo apt-get install bison flex libqt4-dev libqt4-opengl-dev libphonon-dev libicu-dev libsqlite3-dev libxext-dev libxrender-dev gperf libfontconfig1-dev libphonon-dev

If error doesn’t disappear after installing correct library

Sometimes it’s necessary to reconfigure Qt using make confclean

How to find where is missing header file located on disk

Use find /path -iname xxx.h command

How to find package which contains missing header file

use apt-file application with following syntax:

apt-file search gdk/gdk.h

Useful links about instalation Qt on linux

List of links about installation:
Building Qt on Linux

Qt configuration for succesfull build

This is currently my latest configure command to compile Qt on my Ubuntu 10.10.

Compilation fixes

This is necessary when search path for following libraries isn’t entered to configure.

sudo ln -nsf /usr/include/gstreamer-0.10/gst /usr/include/gst

Todo

Figure out how works pkg-config (pkg-config –cflags gstreamer-0.10)

Qt installation and configuration

This is our company step-by-step guide to install and configure Qt on our developer machines.

How to install Qt

Link to Qt download site: http://qt.nokia.com/downloads

Windows (VS2005)

Download VS 2008 distribution from download site. When 2008 distribution is downloaded, it’s necessary to reconfigure and rebuild it for VS 2005 using next steps.

Linux

Download linux/x11 distro from Qt page. Download 32/64bit distro package. Setup downloaded files as executables:

chmod +x qt-sdk-linux-x86-opensource-2009.01.bin
chmod +x qt-creator-linux-x86-opensource-1.0.0.bin

Install Qt sdk to default directory and begin with configuration.

MacOS

Download latest Qt SDK distribution and latest XCode developer pack from apple site. Then install both.

How to configure Qt

Qt configuration is done via Configure script/executable on all platforms.

Windows

Run “Start menu->Visual studio->Tools-> Visual studio command prompt”
Then go to “c:\Qt\Qt_Version\Qt” and run “configure” with additional params.

Our current configuration:

configure -debug-and-release -opensource -shared -platform win32-msvc2005 -incredibuild-xge -openssl

Clean configurations

run nmake confclean and nmake distclean to remove all previous version of QT compilations.

SSL support

For SSL Support add -openssl switch to configure.

Note!

: configure param HAVE TO be executed from Visual studio command prompt!

Linux

Enter Qt directory and enter following configure param:

./configure -opensource -I /usr/include/gtk-2.0 -L /usr/lib/gt-2.0 -I  /usr/include/gstreamer-0.10 -L /usr/lib/gstreamer-0.10 -I /usr/include/glib-2.0 -L /usr/lib/glib-2.0 -I /usr/include/libxml2 -fast

Clean configurations

run make confclean and then configure.

MacOS

How to compile Qt

Windows

Compile Qt using command prompt:

  • Run Visual studio command prompt.
  • And run nmake to build a whole library

Second option is open projects.sln located in p:/Qt/4.7.1/ using Visual Studio IDE  and compile it.

Linux

  • As first thing, use configure to setup Qt settings.
  • As next, run make to build a whole library
  • After a while when everything is compiled, use make install. This will install library to /usr/local/Trolltech/Qt-4.7.0

MacOS

Currently not tested, using default compilation.

How to compile application

When we have prepared Qt library, it’s time to compile our application.

MacOS

When using  qmake without additional params, qmake generate xcode project from .pro instad makefile for g++. To generate makefile, use following params:

qmake -spec macx-g++
make

Deploying application

Windows

Not testes.

External link: http://doc.trolltech.com/4.5/deployment-windows.html

Linux

Not testes.

MacOS

Not testes.