[CMake] Cross-compiling - Avoiding libraries

Svenskmand svenskmand at gmail.com
Wed Jul 18 17:41:06 EDT 2012


Hello :)

I am one of the developers of OpenDungeons a FOSS RTS game inspired by
Dungeon Keeper. I am trying to cross-compile our game on Ubuntu 12.04 for
Windows (XP, Vista and 7), but I have run into some trouble.

I following these guides:
http://www.cmake.org/Wiki/CMake_Cross_Compiling
http://www.cmake.org/Wiki/CmakeMingw

I use the following external libraries:

Ogre SDK 1.7.2 (MingW)
https://sourceforge.net/projects/ogre/files/ogre/1.7/OgreSDK_mingw_v1-7-2.exe/download
CEGUI SDK 0.7.5 (MingW)
https://sourceforge.net/projects/crayzedsgui/files/CEGUI%20Mk-2/0.7.5/CEGUI-SDK-0.7.5-mingw.zip/download
SFML 1.6 (MingW)
https://sourceforge.net/projects/sfml/files/sfml/1.6/SFML-1.6-dev-windows-mingw.zip/download

and have made the following toolchain file (Toolchain.cmake):

# this one is important
SET(CMAKE_SYSTEM_NAME Windows)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
SET(CMAKE_C_COMPILER   /usr/bin/i686-w64-mingw32-gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/i686-w64-mingw32-g++)
SET(CMAKE_RC_COMPILER  /usr/bin/i686-w64-mingw32-windres)

SET(BOOST_ROOT         ${CROSS_DIR}/OgreSDK_mingw_v1-7-2/boost)
SET(CEGUIOGRE_LIBRARY  ${CROSS_DIR}/OgreSDK_mingw_v1-7-2/lib/release)
SET(CEGUI_LIBRARY      ${CROSS_DIR}/CEGUI/lib)
SET(CEGUI_INCLUDE_DIR  ${CROSS_DIR}/CEGUI/cegui/include)
SET(OPENAL_LIBRARY     ${CROSS_DIR}/SFML-1.6/lib)

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH  ${CROSS_DIR}/OgreSDK_mingw_v1-7-2
${CROSS_DIR}/SFML-1.6 ${CROSS_DIR}/CEGUI)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Which I use when I call cmake as follows:

export CROSS_DIR="`pwd`"
cd opendungeons*
cmake -DCROSS_DIR="$CROSS_DIR"
-DCMAKE_TOOLCHAIN_FILE="$CROSS_DIR/Toolchain.cmake" .

Running cmake goes almost fine (I get the following warnings)

ckr at ckr-laptop:~/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir$ ./CrossCompile.sh
...
-- Configuring done
WARNING: Target "OpenDungeons" requests linking to directory
"/home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/SFML-1.6/lib".  Targets may
link only to libraries.  CMake is dropping the item.
WARNING: Target "OpenDungeons" requests linking to directory
"/home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/CEGUI/lib".  Targets may link
only to libraries.  CMake is dropping the item.
WARNING: Target "OpenDungeons" requests linking to directory
"/home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/lib/release".
Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "OpenDungeons" requests linking to directory
"/home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/SFML-1.6/lib".  Targets may
link only to libraries.  CMake is dropping the item.
WARNING: Target "OpenDungeons" requests linking to directory
"/home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/CEGUI/lib".  Targets may link
only to libraries.  CMake is dropping the item.
WARNING: Target "OpenDungeons" requests linking to directory
"/home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/lib/release".
Targets may link only to libraries.  CMake is dropping the item.
-- Generating done
-- Build files have been written to: /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/opendungeons-0.4.9

Which I am not sure are important or not (but that is not my question for
now).

When I then compile our game with make I get the following error:

ckr at ckr-laptop:~/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/opendungeons-0.4.9$ make
Scanning dependencies of target OpenDungeons
[  0%] Building CXX object
CMakeFiles/OpenDungeons.dir/dependencies/angelscript/angelscript/source/as_atomic.cpp.obj
...
[ 44%] Building CXX object
CMakeFiles/OpenDungeons.dir/source/ASWrapper.cpp.obj
In file included from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/boost_1_44/boost/thread/detail/thread_heap_alloc.hpp:15:0,
                 from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/boost_1_44/boost/thread/tss.hpp:10,
                 from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/include/OGRE/Threading/OgreThreadHeadersBoost.h:29,
                 from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/include/OGRE/Threading/OgreThreadHeaders.h:30,
                 from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/include/OGRE/OgreStdHeaders.h:110,
                 from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/include/OGRE/OgrePrerequisites.h:315,
                 from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/include/OGRE/Ogre.h:31,
                 from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/opendungeons-0.4.9/source/CameraManager.h:11,
                 from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/opendungeons-0.4.9/source/ASWrapper.cpp:27:
/home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/boost_1_44/boost/thread/win32/thread_heap_alloc.hpp:59:40:
warning: inline function ‘void*
boost::detail::allocate_raw_heap_memory(unsigned int)’ declared as
dllimport: attribute ignored [-Wattributes]
/home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/OgreSDK_mingw_v1-7-2/boost_1_44/boost/thread/win32/thread_heap_alloc.hpp:69:39:
warning: inline function ‘void boost::detail::free_raw_heap_memory(void*)’
declared as  dllimport: attribute ignored [-Wattributes]
In file included from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/opendungeons-0.4.9/source/ODFrameListener.h:16:0,
                 from /home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/opendungeons-0.4.9/source/ASWrapper.cpp:35:
/home/ckr/Documents/OD
SVN/mediaSource/ODLinuxBuildScripts/build_dir/opendungeons-0.4.9/dependencies/pthreads/include/pthread.h:307:8:
error: redefinition of ‘struct timespec’
/usr/lib/gcc/i686-w64-mingw32/4.6/../../../../i686-w64-mingw32/include/sys/timeb.h:85:8:
error: previous definition of ‘struct timespec’
make[2]: *** [CMakeFiles/OpenDungeons.dir/source/ASWrapper.cpp.obj] Error 1
make[1]: *** [CMakeFiles/OpenDungeons.dir/all] Error 2
make: *** [all] Error 2

So the file pthread.h is imported twice, once from the external libraries
that I want it to be imported from, but also from
/usr/i686-w64-mingw32/include/sys/pthread.h which I do not want to to
import it from. I have used the variable CMAKE_FIND_ROOT_PATH in my
toolchain, and expected Cmake to only look here for external libraries, but
it also looks in /usr/i686-w64-mingw32/include/sys. Am I doing something
wrong in my toolchain file or what do I do fix this problem?

PS: I am pretty new to cmake, I am currently only doing the building and
packaging of our game and not programming on it, so I do not deal with
Cmake on a regular basis. This is my first time cross-compiling.

Thanks for any help :)
Best regards
Casper :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120719/8a8645e4/attachment-0001.htm>


More information about the CMake mailing list