Build from source (Windows version, runtime library /MT, /MTd specification)

(G)When developing an RTC with multithread (/MT) and multithreading debug (/MTd) specified in the runtime library in Visual Studio, if the executable file of /MT, /MTd links with another DLL and processes it, heap It may end abnormally due to destruction or the like. If you want to specify multithreading (/MT) and multithreading debugging (/MTd), create a static library of OpenRTM-aist as follows.

  • Since I have not confirmed the operation confirmation almost, please do the following work at your own risk all.

Build OpenRTM-aist

(G)Obtaining OpenRTM-aist source code

Please obtain the OpenRTM-aist source code from the following.

Please download to appropriate place after downloading. In this example, place it in the following position.

 C:\openrtm_work\OpenRTM-aist

(G)Obtain omniORB

Please obtain binary package of omniORB from the following. Please select the one appropriate for the version of Visual Studio.

After downloading, please create and expand a folder named omniORB in the OpenRTM-aist folder.

 C:\openrtm_work\OpenRTM-aist\omniORB

(G)Editing various files

/MT, /MTd Edits various files for building.

(G)build.bat

Edit the following batch file called build.bat.

 C:\openrtm_work\OpenRTM-aist\build.bat

Please change the following places as appropriate depending on the environment.

 set RTM_ROOT=%~dp0
 set COIL_ROOT=%RTM_ROOT%\coil
 set OMNI_ROOT=%RTM_ROOT%\omniORB
 if not DEFINED ARCH       set ARCH=x86
 if not DEFINED VC_VERSION set VC_VERSION=12
 if not DEFINED PYTHON_DIR set PYTHON_DIR=c:\python27
 if not DEFINED RTM_VERSION set RTM_VERSION=1.1.2
 if not DEFINED OMNI_VERSION  set OMNI_VERSION=4.1.7
 if not DEFINED OMNITHREAD_VERSION set OMNITHREAD_VERSION=3.4

(G)libRTC_vc**.vcxproj、libcoil_vc**.vcxproj、libRTCSkel_vc**.vcxproj

Edit the following libRTC_vc12.vcxproj, libcoil_vc12.vcxproj, libRTCSkel_vc12.vcxproj project file. Please edit libRTC_vc11.vcxproj, libcoil_vc11.vcxproj, libRTCSkel_vc11.vcxproj etc. according to the version of Visual Studio.

  • C:\openrtm_work\OpenRTM-aist\rtm\libRTC_vc12.vcxproj
  • C:\openrtm_work\OpenRTM-aist\rtm\libcoil_vc12.vcxproj
  • C:\openrtm_work\OpenRTM-aist\rtm\idl\libRTCSkel_vc12.vcxproj

First, change the runtime library. Change MultiThreadedDebugDLL to MultiThreadedDebug as shown below. Whether editing is different depending on whether it is 32 bit or 64 bit, there is no problem even if both are changed.

 <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
arrow.png
 <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>

Likewise, change MultiThreadedDLL to MultiThreaded.

 <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
arrow.png
 <RuntimeLibrary>MultiThreaded</RuntimeLibrary>

Then change it to generate a static library instead of a dynamic library. Since libRTCSkel_vc12.vcxproj originally generates a static library, there is no need to change it.

Please change DynamicLibrary to StaticLibrary.

 <ConfigurationType>DynamicLibrary</ConfigurationType>
arrow.png
 <ConfigurationType>StaticLibrary</ConfigurationType>

Also change the output file name accordingly.

 <OutputFile>$(OutDir)\RTC$(rtm_dllver).dll</OutputFile>
arrow.png
 <OutputFile>$(OutDir)\RTC$(rtm_dllver).lib</OutputFile>

 <OutputFile>$(OutDir)\RTC$(rtm_dllver)d.dll</OutputFile>
arrow.png
 <OutputFile>$(OutDir)\RTC$(rtm_dllver)d.lib</OutputFile>

 <OutputFile>$(OutDir)\coil$(coil_dllver).dll</OutputFile>
arrow.png
 <OutputFile>$(OutDir)\coil$(coil_dllver).dll</OutputFile>

 <OutputFile>$(OutDir)\coil$(coil_dllver)d.dll</OutputFile>
arrow.png
 <OutputFile>$(OutDir)\coil$(coil_dllver)d.dll</OutputFile>

Also change the command to copy the file.

 <Command>copy &quot;$(OutDir)\\$(TargetName).lib&quot; &quot;$(SolutionDir)bin\\RTC$(rtm_dllver)d.lib&quot;&#x0D;&#x0A;copy &quot;$(OutDir)\\RTC$(rtm_dllver)d.dll&quot; &quot;$(SolutionDir)bin\\&quot;&#x0D;&#x0A;</Command>
arrow.png
 <Command>copy &quot;$(OutDir)\\$(TargetName).lib&quot; &quot;$(SolutionDir)bin\\RTC$(rtm_dllver)d.lib&quot;&#x0D;&#x0A;</Command>

 <Command>copy &quot;$(OutDir)\\$(TargetName).lib&quot; &quot;$(SolutionDir)bin\\RTC$(rtm_dllver).lib&quot;&#x0D;&#x0A;copy &quot;$(OutDir)\\RTC$(rtm_dllver).dll&quot; &quot;$(SolutionDir)bin\\&quot;&#x0D;&#x0A;</Command>
arrow.png
 <Command>copy &quot;$(OutDir)\\$(TargetName).lib&quot; &quot;$(SolutionDir)bin\\RTC$(rtm_dllver).lib&quot;&#x0D;&#x0A;;</Command>

 <Command>copy &quot;$(OutDir)\\$(TargetName).lib&quot; &quot;$(SolutionDir)bin\\coil$(coil_dllver)d.lib&quot;&#x0D;&#x0A;copy &quot;$(OutDir)\\coil$(coil_dllver)d.dll&quot; &quot;$(SolutionDir)bin\\&quot;&#x0D;&#x0A;</Command>
arrow.png
 <Command>copy &quot;$(OutDir)\\$(TargetName).lib&quot; &quot;$(SolutionDir)bin\\coil$(coil_dllver)d.lib&quot;&#x0D;&#x0A;</Command>

 <Command>copy &quot;$(OutDir)\\$(TargetName).lib&quot; &quot;$(SolutionDir)bin\\coil$(coil_dllver).lib&quot;&#x0D;&#x0A;copy &quot;$(OutDir)\\coil$(coil_dllver).dll&quot; &quot;$(SolutionDir)bin\\&quot;&#x0D;&#x0A;</Command>
arrow.png
 <Command>copy &quot;$(OutDir)\\$(TargetName).lib&quot; &quot;$(SolutionDir)bin\\coil$(coil_dllver).lib&quot;&#x0D;&#x0A;</Command>

Because errors occur in OpenRTM-aist-1.1.2 and omniORB-4.1.7, please add RTM_OMNIORB_41 to PreprocessorDefinitions of libRTC_vc12.vcxproj. It is unnecessary in OpenRTM-aist-1.2.0 or omniORB-4.2.1.

 <PreprocessorDefinitions>LIBRARY_EXPORTS;WIN32;_DEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
arrow.png
 <PreprocessorDefinitions>LIBRARY_EXPORTS;WIN32;_DEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;RTM_OMNIORB_41;%(PreprocessorDefinitions)</PreprocessorDefinitions>

(G)rtm_config.props

Change omniORB's linked library. Please edit the following file called rtm_config.props.

 C:\openrtm_work\OpenRTM-aist\rtm_config.props

Change the following parts.

 <omni_lib>omniORB$(omni_dllver)_rt.lib;omniDynamic$(omni_dllver)_rt.lib;omnithread$(omnithread_dllver)_rt.lib</omni_lib>
 <omni_libd>omniORB$(omni_dllver)_rtd.lib;omniDynamic$(omni_dllver)_rtd.lib;omnithread$(omnithread_dllver)_rtd.lib</omni_libd>
arrow.png
 <omni_lib>omniORB4.lib;omniDynamic4.lib;omnithread.lib</omni_lib>
 <omni_libd>omniORB4d.lib;omniDynamic4d.lib;omnithreadd.lib</omni_libd>

(G)Build

When you start build.bat, it starts the build. When finished, check that the following files are generated in the bin folder.

  • libRTCSkel.lib
  • libRTCSkeld.lib
  • coil112_vc12.lib
  • coil112_vc12d.lib
  • RTC112_vc12.lib
  • RTC112_vc12d.lib

A lot of errors are generated by compiling sample components, rtcd, rtcprof, but ignore it as it is not necessary if you build your own RTC.

(G)Edit OpenRTMConfig.cmake

Because the library name to be linked by omniORB has changed and it is necessary to add a library to be newly linked, edit the following file.

  • C:\openrtm_work\OpenRTM-aist\cmake\OpenRTMConfig.cmake

 set(OMNIORB_LIBRARIES optimized;omniORB417_rt;
                       optimized;omniDynamic417_rt;
                       optimized;omnithread34_rt;
                       debug;omniORB417_rtd;
                       debug;omniDynamic417_rtd;
                       debug;omnithread34_rtd)
arrow.png
 set(OMNIORB_LIBRARIES optimized;omniORB4;
                       optimized;omniDynamic4;
                       optimized;omnithread;
                       debug;omniORB4d;
                       debug;omniDynamic4d;
                       debug;omnithreadd)

 set(OPENRTM_LIBRARIES optimized;RTC112_vc12;
                       optimized;coil112_vc12;
                       optimized;omniORB4_rt;
                       optimized;omniDynamic4_rt;
                       optimized;omnithread4_rt;
                       optimized;advapi32;
                       optimized;ws2_32;
                       optimized;mswsock;
                       debug;RTC112_vc12d;
                       debug;coil112_vc12d;
                       debug;omniORB4_rtd;
                       debug;omniDynamic4_rtd;
                       debug;omnithread4_rtd;
                       debug;advapi32;
                       debug;ws2_32;
                       debug;mswsock)
arrow.png
 set(OPENRTM_LIBRARIES optimized;RTC112_vc12;
                       optimized;coil112_vc12;
                       optimized;omniORB4;
                       optimized;omniDynamic4;
                       optimized;omnithread;
                       optimized;advapi32;
                       optimized;ws2_32;
                       optimized;mswsock;
                       optimized;libRTCSkel;
                       optimized;rpcrt4;
                       debug;RTC112_vc12d;
                       debug;coil112_vc12d;
                       debug;omniORB4d;
                       debug;omniDynamic4d;
                       debug;omnithreadd;
                       debug;advapi32;
                       debug;ws2_32;
                       debug;mswsock;
                       debug;libRTCSkeld;
                       debug;rpcrt4)

Please note that this file will be overwritten if you build OpenRTM - aist again.

(G)Build RTC

Next, set /MT, /MTd and edit the RTC file you want to build. Edit CMakeLists.txt in the src folder. By adding the following description, set the runtime library to /MT, /MTd.

 set(CMAKE_CXX_FLAGS_RELEASE "/MT")
 set(CMAKE_CXX_FLAGS_DEBUG "/MTd")

Next, set the OpenRTM-aist and omniORB to be used for the build to the one that was built previously and build RTC. From the command prompt, enter the following command to set the variable.

 set RTM_ROOT=C:\openrtm_work\OpenRTM-aist
 set VC_VERSION=12
 set OMNI_ROOT=C:\openrtm_work\OpenRTM-aist\omniORB
 set OpenRTM_DIR=C:\openrtm_work\OpenRTM-aist\cmake

Please change accordingly depending on the version of Visual Studio etc. Finally it is done by building with the following command.

 cmake .
 cmake --build . --config Debug

(G)On the cause of the error

If the /MT executable file is linked with some sort of DLL, the following error message may be displayed.

 Expression: _pFirstBlock == pHead

Or releasing the memory allocated on the executable file side on the DLL side.

  • DLL side

  1. __declspec(dllexport) void deleteData(char* v)
  2. {
  3. delete v;
  4. }

  • Executable file side

  1. void deleteData(char* v);
  2.  
  3. int main(void)
  4. {
  5. char *v = new char[1000];
  6. deleteData(v);
  7. }

This seems that when /MT, /MTd is specified in the runtime library, heap destruction may occur because the heap area is created separately in the executable file and the DLL. However, it does not occur reliably, for example if you put a print statement before executing the deleteData function, it will not happen why. In this case, since it falls at a place not related at all afterwards, it becomes very difficult to identify the cause.

On the other hand, if /MD, /MDd is specified in the runtime library, this problem does not occur because the heap area is shared.

Basically, you should use /MD, /MDd for the runtime library because it is impossible to check and fix where abnormality occurs in OpenRTM-aist or omniORB.

If you really want to set /MT, /MTd in the runtime library, create a static library using the above method.

Although RTC specified by /MT, /MTd can be operated by the above method, omniORB and coil are linked to a library named advapi32.dll, and advapi32.dll is /MD's runtime library ( MSVCRT), we do not know what will happen here.

Download

latest Releases

For Begginers

Windows msi(installer) package (only trying samples)

C++,Python,Java,
Toolsを含む
1.2.1-RELEASE

Development environment is required for RT-Component development. See download page for details.

Number of Projects

Choreonoid

Motion editor/Dynamics simulator

OpenHRP3

Dynamics simulator

OpenRTP

Integrated Development Platform

AIST RTC collection

RT-Components collection by AIST

TORK

Tokyo Opensource Robotics Association

DAQ-Middleware

Middleware for DAQ (Data Aquisition) by KEK