How to link DDS shared libraries on Windows with MinGW

This solution describes steps to compile a program in Windows using MinGW and link the shipped RTI Connext DDS libraries which are compiled with Visual Studio.

Basic tests have been done on C language. We have performed those basic tests compiling 32 bits and 64 bits applications using RTI Connext DDS 5.2.0 and packages i86Win32VS2013 and x64Win64VS2013. It is our understanding that C++ libraries is not supported due to different C++ name mangling in Visual Studio and MinGW (see http://www.mingw.org/wiki/Interoperability_of_Libraries_Created_by_Different_Compiler_Brands). Therefore, the basic tests were performed on C language only. Since we have not run the full suite of test, RTI does not claim full support of it.

The procedure is as follows:

Step 1: Download and install MinGW.

We have used MinGW on https://sourceforge.net/projects/mingw-w64/  When installing you can select whether you want to compile 32 or 64 bits applications. Select Architecture = i686 to compile 32bits applications or Architecture = x86_64 to compile 64 bits applications. Also select win32 as threads system.

We have changed the default installation directory to C:\mingw-w64\<...> to avoid whitespace characters in the path, although we are not sure whether this would be a problem.

Step 2: Fix a few definitions in <NDDSHOME>\include\ndds\log\log_dll.h

In file <NDDSHOME>\include\ndds\log\log_dll.h, _declspec( dllexport ) and _declspec( dllimport ) are defined using only 1 _ at the beginning. The correct form is with 2 leading _. Looks like these definitions are correct for Visual Studio but the mingw I am using was throwing an error. This will be fixed in a future version of RTI Connext DDS.

log_dll.h must be edited using administrator privileges if RTI Connext DDS is installed in the default path.

Step 3: Generate a HelloWorld application using code generator.

E.g. I have used the following command:

rtiddsgen -example i86Win32VS2013 -language C HelloWorld.idl

Use x64Win64VS2013 instead of i86Win32VS2013 to generate a 64 bits application.

Step 4: Generate .a files

MinGW is able to link function calls by using the .lib libraries provided with RTI Connext DDS, but it cannot link references to variables in the RTI Connext DDS DLLs. To solve this problem it is needed to generate .a libraries. Using files nddsc.def and nddscore.def in the attached zip file, run commands

c:\mingw-w64\i686-5.3.0-win32-dwarf-rt_v4-rev0\mingw32\bin\dlltool.exe -k -d nddsc.def -l libnddsc.a

c:\mingw-w64\i686-5.3.0-win32-dwarf-rt_v4-rev0\mingw32\bin\dlltool.exe -k -d nddscore.def -l libnddscore.a

Files libnddsc.a and libnddscore.a are generated.

With the previous command, .a libraries for 32 bits program compilation are generated. Use the correct dlltool program to generate .a libraries to compile 64bits programs..

Step 5: Fix compiler error.

Our header files are using type __int64 but some source files can not find it when compiling with MinGW. Add #include <stdio.h> at the beginning of files generated by RTI Code Generator or where you find this error.

Step 6: Copy library files

Copy libraries nddsc.lib and nddscore.lib in directory <NDDSHOME>\lib\i86Win32VS2013 (you can find different folders depending on the architectures that you have installed) to the HelloWorld application folder and modify their files names to start with lib, so names would be libnddsc.lib and libnddscore.lib

Step 7: Copy DLLs

Copy DLLs nddsc.dll and nddscore.dll in directory <NDDSHOME>\lib\i86Win32VS2013 (again you can find different folders depending on the architectures that you have installed) to HelloWorld application folder.

Step 8: Compile the applications using commands:

c:\mingw-w64\i686-5.3.0-win32-dwarf-rt_v4-rev0\mingw32\bin\gcc.exe -I <NDDSHOME>\include -I <NDDSHOME>\include\ndds -I .\ -DRTI_WIN32 -DNDDS_DLL_VARIABLE -L .\ HelloWorld.c HelloWorld_publisher.c HelloWorldPlugin.c HelloWorldSupport.c -lnddsc -lnddscore -llibnddsc -llibnddscore -o HelloWorld_publisher.exe

c:\mingw-w64\i686-5.3.0-win32-dwarf-rt_v4-rev0\mingw32\bin\gcc.exe -I <NDDSHOME>\include -I <NDDSHOME>\include\ndds -I .\ -DRTI_WIN32 -DNDDS_DLL_VARIABLE -L .\ HelloWorld.c HelloWorld_subscriber.c HelloWorldPlugin.c HelloWorldSupport.c -lnddsc -lnddscore -llibnddsc -llibnddscore -o HelloWorld_subscriber.exe

Note that default RTI Connext DDS installation folder is located under “c:\program files\” and gcc cannot handle spaces in the path string, so probably you will need to wrap your -I include path with quotes; e.g. -I "C:\Program Files\rti_connext_dds-5.2.0\include”

Step 9: Run applications

cd to HelloWorld application folder and run publisher or subscriber normally, e.g. HelloWorld_publisher.exe 58 (this would run the publisher in domain 58).

Step 10: Generate 64 bits applications

In case you want to compile a 64 bits application, you just need to use the 64 bits version of gcc.exe and dlltool.exe, in my test I could find it on C:\mingw-w64\x86_64-5.3.0-win32-sjlj-rt_v4-rev0\mingw64\bin and of course you will need also to use the 64 bits DSS libraries, which can be found on <NDDSHOME>\lib\x64Win64VS2013.

Step 11: Use the script 

In the attached zip file, a .bat file can be found which will guide you through step 3 to 10. The only parameter needed is x64Win64VS2013 to generate a 64 bits application or i86Win64VS2013 to generate a 32 bits application.
 
Tags:
Attachments: