[CMake] set ranlib/ar in toolchain file

Eric Noulard eric.noulard at gmail.com
Wed Jul 4 16:19:49 EDT 2012


2012/7/4 Yngve Inntjore Levinsen <yngve.levinsen at gmail.com>:
> Hi,
>
> I try to set up my toolchain file for building Windows executables in a Linux
> environment. I started with the example from
> http://www.cmake.org/Wiki/CmakeMingw
>
> The only thing I noticed was that I needed to use "ar" and "ranlib" from MinGW
> as well, for creating the archives. I can do this by manually editing the file
> CMakeFiles/CMakeCXXCompiler.cmake after cmake has run. Code compiles
> successfully.
>
> I then tried to add the following two lines to the toolchain file:
> SET(CMAKE_AR i486-mingw32-ar)
> SET(CMAKE_RANLIB i486-mingw32-ranlib)

You shouldn't need to set CMAKE_AR or CMAKE_RANLIB yourself.
Could you try the toolchain file I uploaded here
http://www.cmake.org/Wiki/images/c/c2/Toolchain-cross-mingw32-linux.cmake

(refered on the very same page you used: http://www.cmake.org/Wiki/CmakeMingw)

If you SET(COMPILER_PREFIX "i486-mingw32")
it should work out of the box.

> (yes, the prefix for my MinGW install is different from the example)
>
> Sadly, that makes the initial compiler test fail. For fortran it actually
> still works, but the test fails for c and c++. I have tried to search for a
> while without finding out what I do wrong. Please tell me. Or ask if something
> is unclear.

What is the exact command line you used when invoking CMake with you
Toolchain file ?

Did you try from a pristine build tree?

Using the provided toolchain, after you updated with the proper prefix
if you put the toolchain file at the root of your source tree, then you can do:

cd sourcedir
mkdir build-win32
cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-cross-mingw32-linux.cmake ..

should work as expected without tweaking AR or RANLIB.

-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org


More information about the CMake mailing list