Developer Blog -
  • Skipper - The ORM Designer
  • VsBuilds - Parallel building
  • Pulpo - Free Skipper CLI

Tag: #C++

How to update gcc to 4.8.1 on any ubuntu

Everything is perfectly explained in this post:

List of commands

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update; sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
gcc --version
06 Feb 2015

Posted by: ludek.vodicka

Programming Linux #Linux #C++ #gcc

Debugging segmentation fault

22 Jan 2014

Posted by: ludek.vodicka

Linux #Linux #C++ #debugging #segmentationfault

How to compile FastCGI library in Visual Studio 2010 C++

FastCGI comes with Win32 project for VisualStudio6. Unfortunately when you try to open it in VisualStudio2010 the project will be corrupted. To correctly compile it for VS2010 it's necessary to download library sources, get patches from site and apply it.

Download library

Download latest version of Development Kit here and extract it to standalone directory.


Get and update patches

Download all five patches from Cybozu site. Now when you have patches it's necessary to convert all files to correct windows-ending format. This can be done for example in Notepad++.

Convert to windows EOL

Get patch.exe application

Now you need some application capable to apply the patches. Unfortunately windows doesn't contain any application for this task and also lot of comparing/merging applications can't do that.

The simplest way is to download windows conversion of linux patch.exe app. Get it from gnuwin32 site - patch for windows.

Apply patch to project files

Apply patches

Open directory with fastcgi library, copy all patch files to this directory and open command line. As next run patch command for all fives patches:

...\fcgi-2.4.1-SNAP-0311112127&gt;patch -Np1 &lt; 4-vc9.patch<br />
patching file Win32/FastCGI.sln<br />
patching file Win32/authorizer.vcproj<br />
patching file Win32/cgifcgi.vcproj<br />
patching file Win32/config_h.vcproj<br />
patching file Win32/echo-cpp.vcproj<br />
patching file Win32/echo.vcproj<br />
patching file Win32/echox.vcproj<br />
patching file Win32/libfcgi.vcproj<br />
patching file Win32/logdump.vcproj<br />
patching file Win32/size.vcproj<br />
patching file Win32/threaded.vcproj<br />

In case you will see following error message:

patching file Win32/FastCGI.sln<br />
Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354</p>
<p>This application has requested the Runtime to terminate it in an unusual way.<br />
Please contact the application's support team for more information.<br />

it's necessary to convert ALL patch files to correct Windows format (correct EOL) as mentioned in previous section.

More patches...

When you apply patches by cybozu it's time to apply my own patches ;-).

Manually updated rejected file

As first, it's probably that you will see following message:

1 out of 26 hunks FAILED -- saving rejects to file libfcgi/os_win32.c.rej<br />

It's because original patch is for older version of library and file os_win32.c  is slightly different. To fix that, edit this file at line 841 and manually update following line:

//original<br />
int len = p - bindPath + 1;</p>
<p>//updated line<br />
intptr_t len = p - bindPath + 1;<br />

Update VS project file

Now turn off generating the Map Files in project configuration. These files aren't necessary and it isn't possible to compile project correctly with this settings.

Turn off .map files


And that's all. Now you will be able to sucesfully compile fast-cgi library.

Compilation complete

External links

18 Nov 2013

Posted by: ludek.vodicka

Programming Windows #C++ #fastcgi #nginx

FastCGI c++ library for all platforms (Windows, Mac and Linux)

List of existing libraries


Stackoverflow articles


Other links

CGICC - how to update it for VS2010 COMPILATION

  •  **error C2668: 'cgicc::copy_if' : ambiguous call to overloaded function** - add cgicc:: to all cgicc::copy_if instances
  •  **error LNK2019: unresolved external symbol** - add compiled .lib path (...Debug\cgicc.lib) to all dependend projects
17 Nov 2013

Posted by: ludek.vodicka

Programming Linux Windows Mac OS #C++ #fastcgi #nginx

Error in RegEx (atlrx.h) in Visual Studio C++ 2003 and 2005

During our development we found that Microsoft RegEx (Regular expression) implementation contains a bug which caused crashes of our applications. The application module using RegEx passed all unit test, but sometimes under heavy usage the application crashed at our customer. Because we use **BugTrap **for error and crash notifications, we knew the error was in atlrx.h file.

After several hours of testing and searching we found the bug. The crash didn't occur after first code execution, but we had to run thousand iterations of the same code over and over. The bug is located in file atlrx.h at line 708.

Original file looks like this:

  case RE_ADVANCE:
    sz = CharTraits::Next(szCurrInput);
    szCurrInput = sz;
    if ( sz == NULL || *sz == '
      goto Error;
    ip = 0;
    pContext->m_nTos = 0;

Problem is, that variable szCurrInput have in some circumstances NULL value and this causes the crashes.

**Updated file with bug fix:**

  case RE_ADVANCE:
    if( szCurrInput == NULL || *szCurrInput == '
' )
      goto Error;
    sz = CharTraits::Next(szCurrInput);
    szCurrInput = sz;
    if ( sz == NULL || *sz == '
      goto Error;
    ip = 0;
    pContext->m_nTos = 0;

We change the first two lines. It is necessary to test szCurrInput variable for NULL and empty string value. If szCurrInput is NULL or empty string, it's necessary to stop processing RegEx. Otherwise stack overflow during processing string occurs.


Some time later we had other problems with Microsoft RegEx implementation and non-standard RegEx syntax. So we left MS RegEx parser and moved to Boost.Regex which is really nice piece of code (as well as other libraries of the Boost pack) and supports Perl and POSIX regular expressions. Whole Boost library is carefully unit test and can be relied on.

28 Aug 2013

Posted by: ludek.vodicka

Programming #C++ #visual studio #regex #bug #atl

List of C++ profilers for windows (commercial and non-commercial)

24 Oct 2012

Posted by: ludek.vodicka

Programming Windows #C++ #development

Problem with compiling Boost

Warning: &quot;using python&quot; expects a two part (major, minor) version number; got %d.%d\nplatform=%s\nprefix=%s\nexec_prefix=%s\nexecutable=%s' % (version_info[0],version_info[1],platform,prefix,exec_prefix,executable))&quot;  instead<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\feature.jam:276: in implied-feature from module featureerror: &quot;version_info[1]&quot; is not an implicit feature value<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\feature.jam:355: in expand-subfeatures-aux from module featureQ:/ExternalLibraries/boost_trunk/tools/build/v2/build\feature.jam:424: in feature.expand-subfeatures from module feature<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\property.jam:186: in property.expand-subfeatures-in-conditions from module property<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\property-set.jam:407: in property-set.create-from-user-input from module property-set<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\property-set.jam:461: in property-set.refine-from-user-input from module property-set<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\targets.jam:1580: in targets.main-target-requirements from module targets<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/tools\builtin.jam:532: in lib from module builtin<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/tools\python.jam:680: in declare-libpython-target from module python<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/tools\python.jam:925: in configure from module python<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/tools\python.jam:110: in python.init from module python<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\toolset.jam:41: in using from module toolset libs\python\build\Jamfile.v2:16: in modules.load from module Jamfile&lt;Q:\External<br />
Libraries\boost_trunk\libs\python\build&gt;<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\project.jam:311: in load-jamfile from module project<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\project.jam:64: in load from module project<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\project.jam:89: in load-used-projects from module project<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\project.jam:75: in load from module project<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2/build\project.jam:145: in project.find from module project<br />
Q:/ExternalLibraries/boost_trunk/tools/build/v2\build-system.jam:552: in load from module build-system<br />
Q:\ExternalLibraries\boost_trunk\tools\build\v2/kernel\modules.jam:289: in import from module modules<br />
Q:\ExternalLibraries\boost_trunk\tools\build\v2/kernel/bootstrap.jam:139: in boost-build from module<br />
Q:\ExternalLibraries\boost_trunk\boost-build.jam:17: in module scope from module<br />

The problem was that boost build helper run my python.bat instead of correct python.exe from %PATH% directory.

To check which python is used enter following param:

b2 --debug-configuration:<br />
notice: [python-cfg] Configuring python...<br />
notice: [python-cfg] Registry indicates Python 2.7 installed at &quot;C:\Python27\&quot;<br />
notice: [python-cfg] Checking interpreter command &quot;python&quot;...<br />
notice: [python-cfg] running command 'python -c &quot;from sys import *; print('version=%d.%d\nplatform=%s\nprefix=%s\nexec_prefix=%s\nexecutable=%s' % (version_info[0],version_info[1],platform,prefix,exec_prefix,executable))&quot; 2&gt;&amp;1'<br />
notice: [python-cfg] ...does not invoke a working interpreter<br />
notice: [python-cfg] Checking interpreter command &quot;C:\Python27\python&quot;...</p>
<p>####HERE####<br />
notice: [python-cfg] running command 'DIR /-C /A:S &quot;C:\Python27\python.exe&quot; 2&gt;&amp;1'<br />
<p>notice: [python-cfg] running command 'C:\Python27\python -c &quot;from sys import *;print('version=%d.%d\nplatform=%s\nprefix=%s\nexec_prefix=%s\nexecutable=%s' % (version_info[0],version_info[1],platform,prefix,exec_prefix,executable))&quot; 2&gt;&amp;1'<br />
notice: [python-cfg] ...requested configuration matched!<br />
notice: [python-cfg] Details of this Python configuration:<br />
notice: [python-cfg]   interpreter command: &quot;C:\Python27\python&quot;<br />
notice: [python-cfg]   include path: &quot;C:\Python27\Include&quot;<br />
notice: [python-cfg]   library path: &quot;C:\Python27\libs&quot;<br />
notice: [python-cfg]   DLL search path: &quot;C:\Python27&quot;<br />

08 Sep 2012

Posted by: ludek.vodicka

Windows #C++ #boost #extrnal libraries

Linux - problem with gdb

How to solve problem with gdb: "ptrace: operation not permited"

sudo chmod +s /usr/bin/gdb<br />
21 Mar 2012

Posted by: ludek.vodicka

Linux #Linux #C++

Qt application crash when compiled for 64-bit VS2010


&gt;	QtGui4.dll!00000000652f071f()<br />
 	[Frames below may be incorrect and/or missing, no symbols loaded for QtGui4.dll]<br />
 	QtGui4.dll!00000000652f07ae()<br />
 	QtGui4.dll!0000000065326821()<br />
 	QtGui4.dll!0000000065327f30()<br />
 	QtGui4.dll!00000000653284ba()<br />
 	QtGui4.dll!000000006532a5f5()<br />
 	QtGui4.dll!00000000652f4792()<br />
 	QtGui4.dll!000000006532f701()<br />
 	QtGui4.dll!000000006535be71()<br />
 	QtCore4.dll!0000000059a0ab9f()<br />
 	QtGui4.dll!0000000065306eb9()<br />
 	QtCore4.dll!00000000599f7903()<br />
 	QtGui4.dll!0000000064eaffa2()<br />
 	QtGui4.dll!0000000064eb2e56()<br />
 	QtCore4.dll!00000000599f7792()<br />
 	QtGui4.dll!0000000064eec2a3()<br />
 	QtGui4.dll!0000000064eee85e()<br />
 	QtGui4.dll!0000000064eec265()<br />
 	QtGui4.dll!0000000064eee85e()<br />
 	QtGui4.dll!0000000064eec265()<br />
 	QtGui4.dll!0000000064eee85e()<br />
 	QtGui4.dll!0000000064efa870()<br />
 	QtGui4.dll!0000000065208727()<br />
 	QtGui4.dll!000000006527a082()<br />
 	QtGui4.dll!0000000064eaffb6()<br />
 	QtGui4.dll!0000000064eb2e56()<br />
 	QtCore4.dll!00000000599f7792()<br />
 	QtGui4.dll!0000000064ef264c()<br />
 	QtGui4.dll!0000000064ef26c7()<br />
 	QtGui4.dll!0000000064ef26c7()<br />
 	QtGui4.dll!0000000064ef26c7()<br />
 	QtGui4.dll!0000000064efe30c()<br />
 	OrmDesigner2.exe!000000013f95a2cf()<br />
 	OrmDesigner2.exe!000000013f95dce2()<br />
 	kernel32.dll!000000007794652d()<br />
 	ntdll.dll!0000000077c8c521()<br />

The bug is probably caused by wrong alignment or incorrect VS2010 compiler optimalization.

Found resources:


First way - Update VS2010 mkspec for Qt

go to $QTDIR/mkspecs/win32-msvc2010/qmake.conf and replace -02 with -01 (ie. reducing the optimzation level).Also /Ob0 could be used.

Microsoft hotfix for VS
File patch name VS10-KB2268081-x86.exe

Install Visual Studio 2010 SP1

Service pack could also contains required fix.

22 Nov 2011

Strange "no matching function for call to ..." error on MacOS

Error appear when using BOOST::fusion::map<....>

Error message:

In file included from axOrm/ormObject/ormObject.test.cpp:5:<br />
axOrm/ormObject/testObjects/objContactAndAddress.h: In member function 'void Atomix::Orm::Tests::CBaseOrmContact::SetName(XString)':<br />
axOrm/ormObject/testObjects/objContactAndAddress.h:92: error: no matching function for call to 'Atomix::Orm::Tests::CBaseOrmContact::GetPropertyHolder()'<br />

Invalid source code

template &lt;class TNameParam&gt; typename fus::result_of::at_key&lt; TmapAssociations,TNameParam&gt;::type &amp; GetAssociationHolder()<br />
{ return fus::at_key&lt;TNameParam&gt;(m_mapAssociations); }<br />

for fix simply change result_of::at_key to result_of::value_at_key

template &lt;class TNameParam&gt; typename fus::result_of::value_at_key&lt;TmapAssociations,TNameParam&gt;::type &amp; GetAssociationHolder()<br />

After fixing this error, you can achieved problem with const modifier. Correct syntax for const definition is:

template <typename TNameParam> typename fus::result_of::value_at_key<const TmapProperties,TNameParam>::type const & GetPropertyHolder() const
{ return fus::at_key<TNameParam>(m_mapProperties); }

28 Jun 2011

Posted by: ludek.vodicka

Programming Mac OS #MacOs #C++ #g++

C++ - unpack sub-type from template structure only for specified object type

#include &lt;assert.h&gt;<br />
#include &lt;typeinfo&gt;</p>
<p>struct CTreeObject1<br />
{<br />
<p>/************************************************************************/<br />
/* Nammed structs - for using one type more than once in SinglesCont.   */<br />
/************************************************************************/<br />
template&lt; class TObject, class TName&gt;<br />
struct NammedObject : public TObject, public TName<br />
{<br />
        typedef TObject object_type;<br />
<p>struct stFirst{};<br />
struct stSecond{};</p>
<p>template &lt;typename T&gt;<br />
struct UnpackObjectType<br />
{<br />
        typedef T TT;<br />
<p>template&lt;typename T, typename U&gt;<br />
struct UnpackObjectType&lt; NammedObject&lt;T, U&gt; &gt;<br />
{<br />
        typedef T TT;<br />
<p>int main()<br />
{<br />
        typedef NammedObject&lt;CTreeObject1,stFirst&gt;  T1;<br />
        typedef NammedObject&lt;CTreeObject1,stSecond&gt;  T2;<br />
        typedef CTreeObject1                        T3;</p>
<p>        UnpackObjectType&lt;T1&gt;::TT d1;<br />
        UnpackObjectType&lt;T2&gt;::TT d2;<br />
        UnpackObjectType&lt;T3&gt;::TT d3;</p>
<p>        //required<br />
        assert( typeid(d1) == typeid(d2));<br />
        assert( typeid(d2) == typeid(d3));</p>
<p>        return 0;<br />
}<br />
10 Jun 2011

Posted by: ludek.vodicka

Programming #C++ #templates

g++ error: conversion from XTestObjectA to non-scalar type XTestObjectBase requested

//error<br />
XTestObjectBase objTestObjectBase1 = objTestObjectA;</p>
<p>//ok<br />
XTestObjectBase objTestObjectBase2(objTestObjectA);</p>
<p>//ok<br />
XTestObjectBase objTestObjectBase3; objTestObjectBase3 = objTestObjectA;<br />

cite from:

The problem is that the number of user-defined conversions that are invoked implicitly is limited (to 1) by the Standard.

B ob = a;
implies two user conversions:

on a: Wrap::operator A*() should be called
on the result: B::B(A*) should be called

The solution is to use explicit conversion

//now ok<br />
XTestObjectBase objTestObjectBase1 = XTestObjectBase(objTestObjectA);<br />
07 Jun 2011

Posted by: ludek.vodicka

Programming Linux #Linux #C++ #g++

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 &amp; memMngr = GetMemoryManager();<br />
m_pObject =<br />
  memMngr.CreateObject&lt;TObject&gt;(this, m_pContainerOwner);<br />


TMemoryManager &amp; memMngr = GetMemoryManager();<br />
m_pObject =<br />
  memMngr.template CreateObject&lt;TObject&gt;(this, m_pContainerOwner);<br />

07 Jun 2011

Posted by: ludek.vodicka

Programming Linux #Linux #C++ #g++ #templates

MinGW and compilation 32/64bit libraries

Install MinGW-64

1) Download MinGW 64-bit and 32-bit

- 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

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

30 Jan 2011

Posted by: ludek.vodicka

Programming Linux Windows #Linux #C++ #Windows #cygwin

Collection of links about ORM, Datamapper and design patterns

12 Jan 2011

Posted by: ludek.vodicka

Programming #C++ #orm

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 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 ./<br />

Output could looks like this:

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

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/<br />

**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/<br />
make<br />
13 Dec 2010

Posted by: ludek.vodicka

Programming Qt Linux #Qt #MacOs #Linux #C++ #Programming

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&lt;class T&gt;
struct Test
	T val;
	template &lt;class T2&gt;
	void DoSomething( T2 &amp;obj )

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&lt;T&gt;::DoSomething(T2&amp;)’:
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&lt;class T&gt;
struct Test
	T val;
	template &lt;class T2&gt;
	void DoSomething( T2 &amp;obj )
		obj.template FindByType&lt;int&gt;();

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

03 Dec 2010

How to change DLL default load address (MSVC linker)

Sometimes happened that two DLL libraries wants to be loaded in same address. These DLL libraries can be found in "Modules" window with small red exclamation mark. When you need to change this address, you have to update your linker settings adding the /BASE: parameter.

link.exe &amp;lt;other_praams&amp;gt; /BASE:0x11000000<br />
21 Nov 2010

Posted by: ludek.vodicka

Programming #C++ #Windows

Using Crypto++ stream processing

How to load specific part of file and run several Crypto++ streams


External links:

****CryptoPP FAQ****

**How do I use the Filter class?**

****How do I use a stream cipher?****

17 Nov 2010

Posted by: ludek.vodicka

Programming #C++ #Crypto++

TENG - c++ templating engine

Project site:

External project documentation:

Latest TENG source code: (**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.

15 Nov 2010

Posted by: ludek.vodicka

Programming MinGW Linux #MacOs #Linux #C++ #Windows

How to show all defines for compiler

Sometime it's useful to know what defines are available on specific platform and compiler. Here is command which shows these defines:

touch test.export<br />
g++ -dM -E test.export<br />
15 Nov 2010

Posted by: ludek.vodicka

Programming Linux #Linux #C++

List of usefull links for Visual Studio

How to customize autoexp.dat in Visual Studio 2005

Example visualizator for XString

String::CStringSmart&lt;String::malloc_string_trait&lt;String::string_trait&lt;char&gt; &gt; &gt;{<br />
  preview([$c.m_pszData,s])<br />
  stringview([$c.m_pszData,sb])<br />
<p>String::CStringSmart&lt;String::malloc_string_trait&lt;String::string_trait&lt;wchar_t&gt; &gt; &gt;{<br />
  preview([$c.m_pszData,su])<br />
  stringview([$c.m_pszData,sub])<br />
}<br />

How to configure STEP-INTO for Visual Studio 2005

External links:
Google group

Example how to setup ingoring step-into for MFC CString for VS2005

Windows Registry Editor Version 5.00<br />
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\NativeDE\StepOver]<br />
&quot;\&quot;20\&quot;&quot;=&quot;\\scope:CString.*\\:\\:.*=NoStepInto&quot;<br />
&quot;\&quot;21\&quot;&quot;=&quot;\\scope:CSmartObjPtr.*\\:\\:.*=NoStepInto&quot;<br />

Example how to setup ingoring step-into for MFC CString for VS2010 on 64bit system

Windows Registry Editor Version 5.00</p>
<p>[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0_Config\NativeDE\StepOver]<br />
&quot;22&quot;=&quot;.*CStringSmart.*=NoStepInto&quot;<br />

10 Nov 2010

Posted by: ludek.vodicka

Programming #C++ #visual studio

Simple iconv (libiconv) example

Here is a simple example how to use the iconv library.

#include &lt;iostream&gt;<br />
#include &lt;fstream&gt;<br />
#include &lt;iconv.h&gt;</p>
<p>int main(int argc, char *argv[])<br />
{<br />
	char src[] = &quot;abcčde&quot;;<br />
	char dst[100];<br />
	size_t srclen = 6;<br />
	size_t dstlen = 12;</p>
<p>	fprintf(stderr,&quot;in: %s\n&quot;,src);</p>
<p>	char * pIn = src;<br />
	char * pOut = ( char*)dst;</p>
<p>	iconv_t conv = iconv_open(&quot;UTF-8&quot;,&quot;CP1250&quot;);<br />
	iconv(conv, &amp;pIn, &amp;srclen, &amp;pOut, &amp;dstlen);<br />
<p>	fprintf(stderr,&quot;out: %s\n&quot;,dst);<br />
}<br />

During my attempts with libiconv library I encountered two different problems:

Converting function returns 0, but pOut is empty

This is because iconv function modify pOut ptr during string processing. When you need to access output buffer after **iconv()** function finish its work, you have to access it via different pointer than one passed to this function. In my code I'm using *dst and pOut ptrs;

Conversion between different character sets returns strange results

Check if have correct order of parameters in your **iconv_open()** and **iconv()** function. Function **iconv_open()** has as its first parameter OUTPUT encoding, and as second parameter INPUT encoding. While **iconv()** function has as first parameters INPUT variables, and as second parameters OUTPUT variables. This inconsistency is really confusing.


Official libiconv site:

Official libiconv documentation:

08 Nov 2010

Posted by: ludek.vodicka

Programming #C++ #libiconv

How to compile open-source libraries under Windows using MinGW

Lots of open source libraries (like libiconv, libintl, ...) doesn't have MSVC project files or makefiles. Only supported way how to compile given library under Window is using MinGW and MSYS compiler tools.

Here is step-by-step guide how to download, install and compile libraries using MinGW.

Step one download MinGW

From MinGW home web site download "Automated MinGW Installer". Current version could be downloaded here: MinGW Installer

Step two installing

Run downloaded executable. As install directory leave C:\MinGW. It's recommended not to change this path.  On component screen select C compiler, C++compiler, MSYS Basic System and MinGW Developer Toolkit.

After that select next,next,next, finish ;-). After that installer downloads all necessary files. This could take a few minutes.

When installation is done, as next step is necessary to setup PATH variable to c:\MinGW. Installer doesn't modify it automatically. (more info about modifying PATH variable) .

Installing additional gcc compiler and make support

These two packages isn't listed in available components. If you wish to install it, use mingw-get-inst. In c:\MinGW\bin directory run following commands:

mingw-get install gcc g++ mingw32-make msys-base

Step three compiling

Compiling from windows shell

Launch cmd tool, go to directory with source code and use g++.

g++ test.cpp

Compiling from MinGW console

Launching MinGW console

Laung MinGW from startmenu or msys.bat from %INSTALL_PATH%\MinGW\msys\1.0\msys.bat.

How to compile libiconv library

As first, download latest libiconv source files from And extract whole package somewhere on your disk.

Launch MinGW console and go to the extracted directory. When you extracted directory to the path:


Type following command to MinGW console:

cd /p/DependentLibrariesWhole/libiconv-1.13.1

after that, run **configure** with required library params (in our case we want static and dynamic version of library)**:**

configure --enable-static --enable-shared

and than run make


Compiled libraries are located in directory "libiconv-1.13.1\lib\.libs". There is  additional information about building libiconv library on stackoverflow.

Additional How to guides

This list is compilation of answer to questions and informations how to solve some problems which I had during my installations.

How to get list of available parameters for configure script?

Use **"configure --help"** command.

08 Nov 2010

Posted by: ludek.vodicka

Programming MinGW #C++ #MinGW #compile #Windows