15. December 2011

How to define C++ macro with string content and pass it to MSbuild

Imagine that we have C++ project e.g. for Visual Studio 2008. It is possible to build this project just by msbuild command:

msbuild MyProject.vcproj /p:Configuration="Release"

Let say that we want to use #define in the source code. It is necessary to define it in Configuration Properties > C++ > Command Line:

/DSIMPLE_DEFINE

This just pass SIMPLE_DEFINE as flag.

How to deal with string define which should behave like string? E.g.:

#define URL "https://georgik.rocks"

The trick is in escaping quotes. We can add following define to Command Line:

/DURL=\"https://georgik.rocks\"

It will transform into .vcproj file:

AdditionalOptions="/DURL=\"https://georgik.rocks\""

Let’s make one more step.

How to acquire such a define from environment variable? E.g. with following build.bat file:

set URL="https://georgik.rocks"
msbuild MyProject.vcproj /p:Configuration="Release"

It requires only small modification of .vcproj file:

AdditionalOptions="/DURL=\"$(URL)\""

;-)

Small recap of flow: set env variable – pass it to XML – pass it compiler – pass it to code

23. November 2011

Mintty – resizable terminal for Windows

Update 4.11. 2012: Mintty/Cygwin Termina; has also support for transparency.

Update 31.12. 2011: new version of Mintty (see discussion).

Cygwin is great tool for Windows.

E.g. You can create shell script to access windows share via //computer/share_name. This saves a lot of time when you’re domain admin and you need to maintain many computers.

The only BIG drawback of Cygwin for Windows was terminal window. When you work on Mac or Linux you can resize terminal window as you need. Terminal (CMD) for Windows sucks. In default installation you can resize just in one direction. The other option would be to mix Cygwin with PowerShell, but then many things are not working at all.

Good news! Great news! There is new terminal window in Cygwin 1.7.x. It’s application mintty.

Installer will create link to this app with name Cygwin Terminal. It will launch mintty process and you can resize window without problem.

It works fantastic! After so many yeaars it is now possible to use full power of Windows and Linux together in one bundle. (Yes, I know about other terminals like rxvt or X-based stuff, but it required always some extra steps).

Some computers were complaining that /Cygwin-Terminal.ico was not found and I was not able to launch terminal. Solution was easy. Right click on launcher icon and remove icon parameters from Target. The result target command should look like: C:\cygwin\bin\mintty.exe

Hooray! BIG thank you goes to authors of mintty for Windows.

Follow Mintty T.

14. October 2011

_ITERATOR_DEBUG_LEVEL’: value ‘0’ doesn’t match value ‘2’

Update 16.10. 2011: new information added to article.

I was trying to compile an application with Visual Studio 2010 which has some dependency on GDAL open source library.

Everything went ok. GDAL compiled without problem from VS and also from command line:

nmake -f makefile.vc MSVC_VER=1600 DEBUG=1

Compilation of application based on GDAL was also ok. The only problem was when I switched project from Release mode to Debug mode. Linker was throwing a lot of messages like this:

'error LNK2038: mismatch detected for _ITERATOR_DEBUG_LEVEL': 
value '0' doesn't match value '2' in vrtizer.obj

I found some explanation that new version of VS has _ITERATOR_DEBUG_LEVEL set to 2 in Debug mode. It means that there are some extra security controls over iterators to detect memory leaks and other problematic stuff with iterators.

After longer research I came to realization that GDAL is compiled with /MD switch and my application wasn’t. The solution was easy. I just added /MD and Debug mode of app start working like a charm.

Quote from MSDN about /MD compiler switch:

Defines _MT and _DLL so that both multithread- and DLL-specific versions of the run-time routines are selected from the standard .h files. This option also causes the compiler to place the library name MSVCRT.lib into the .obj file.
Applications compiled with this option are statically linked to MSVCRT.lib. This library provides a layer of code that allows the linker to resolve external references. The actual working code is contained in MSVCR71.DLL, which must be available at run time to applications linked with MSVCRT.lib.

Update 16.10. 2011

/MD solved problem, but there was another warning: Command line warning D9025: overriding ‘/MDd’ with ‘/MD’.

To solve Iterator issue for GDAL you need to compile DEBUG version of gdal.lib with switch /MDd instead of default /MD.

Just open nmake.opt file and replace /MD in lines with DEBUG definition by /MDd.

There are two lines with MD:

OPTFLAGS= $(CXX_ANALYZE_FLAGS) /nologo /MDd /EHsc /Zi /W4 /D_CRT_SECURE_NO_DEPRECATE 
/D_CRT_NONSTDC_NO_DEPRECATE /Fd$(GDAL_ROOT)\gdal$(VERSION).pdb /DDEBUG
OPTFLAGS=   /nologo /MDd /EHsc /GR /Zi /W4 /Fd$(GDAL_ROOT)\gdal$(VERSION).pdb  /DDEBUG

Then rebuild GDAL:

nmake -f makefile.vc clean
nmake -f makefile.vc MSVC_VER=1600 DEBUG=1

29. August 2011

Managing LDAP with Apache Directory Studio

One of key downsides of LDAP in past was lack of cross-platform tools for managing directory structure.

Recently I found very good implementation of LDAP management tool based on Eclipse. It is Apache Directory Studio.

It is possible to connect it also to Microsoft Active Directory. Good work!