Discussion:
[CMake] Problem with library prefix/suffix when cross compiling.
Peter Visser
2006-11-16 16:31:17 UTC
Permalink
Hi,

I have a working build under win32 with MSYS/MINGW, now I would like to
cross-compile code for win32 with mingw from linux with by using the same
CMakelists.txt files. It almost works, the problem is that the shared
libraries are not named "myex.dll" but "libmyex.so". By using the following
command for all the libraries it can be solved:

SET_TARGET_PROPERTIES(ex1
PROPERTIES PREFIX ""
SUFFIX ".dll"
)

However, now I have to change the CMakelist.txt in all the subdirectories
and lose the ability to compile natively for linux (without adding an
IF(UNIX) around the SET_TARGET_PROPERTIES).

Is there a global option to set the PREFIX and SUFFIX, set the BUILD_TARGET
to win32 or something alike?

I tried setting:

SET(UNIX FALSE)
SET(MINGW TRUE)
SET(WIN32 TRUE)

But that doesn't help.

Any help is appreciated,

Peter.
Eric Noulard
2006-11-16 16:46:48 UTC
Permalink
I am really interested in getting sample CMakeLists.txt
since I just wanted to do what you've done, i.e. cross-compiling
for win32 under linux.

You should know that CMake does not currently support cross-compiling.
See
http://www.cmake.org/pipermail/cmake/2006-September/010959.html
or
http://www.cmake.org/pipermail/cmake/2006-September/010946.html

For your "problem" I think you may try this in your
project CMakeLists.txt

IF (UNIX)
IF (CROSS_MINGW32)
SET(MY_TARGETLIB_PREFIX "")
SET(MY_TARGETLIB_SUFFIX ".dll")
ELSE (CROSS_MINGW32)
SET(MY_TARGETLIB_PREFIX "lib")
SET(MY_TARGETLIB_SUFFIX ".so")
ENDIF (CROSS_MINGW32)
ENDIF (UNIX)

I assume
OPTION(CROSS_MINGW32 "Cross compile Win32 using mingw32" OFF)

was set ON for mingw32 cross compiling
and OFF for Linux "native" compiling.

Then use your MY_TARGETLIB_xxx
in all other places:
SET_TARGET_PROPERTIES(ex1
PROPERTIES
PREFIX $(MY_TARGETLIB_PREFIX)
SUFFIX $(MY_TARGETLIB_SUFFIX)
)
Post by Peter Visser
Hi,
I have a working build under win32 with MSYS/MINGW, now I would like to
cross-compile code for win32 with mingw from linux with by using the same
CMakelists.txt files. It almost works, the problem is that the shared
libraries are not named "myex.dll" but "libmyex.so". By using the following
SET_TARGET_PROPERTIES(ex1
PROPERTIES PREFIX ""
SUFFIX
".dll"
)
However, now I have to change the CMakelist.txt in all the subdirectories
and lose the ability to compile natively for linux (without adding an
IF(UNIX) around the SET_TARGET_PROPERTIES).
Is there a global option to set the PREFIX and SUFFIX, set the BUILD_TARGET
to win32 or something alike?
SET(UNIX FALSE)
SET(MINGW TRUE)
SET(WIN32 TRUE)
But that doesn't help.
Any help is appreciated,
Peter.
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
--
Erk
Peter Visser
2006-11-16 18:30:14 UTC
Permalink
The great thing is that cross compiling was very simple with to setup with
CMake in my case, I didn't require a "special" CMakeLists.txt.

All I do is create a file e.g. "setmingw" with:

export CC=i586-mingw32msvc-gcc
export CXX=i586-mingw32msvc-g++
export LD=i586-mingw32msvc-ld
export AR=i586-mingw32msvc-ar
export AS=i586-mingw32msvc-as
export NM=i586-mingw32msvc-nm
export STRIP=i586-mingw32msvc-strip
export RANLIB=i586-mingw32msvc-ranlib
export DLLTOOL=i586-mingw32msvc-dlltool
export OBJDUMP=i586-mingw32msvc-objdump
export RESCOMP=i586-mingw32msvc-windres
export CFLAGS=

then a
% source setmingw
% cmake
% make

Unfortunately the command SET_TARGET_PROPERTIES( ...) doesn't solve the
library problem, linking against the library will result in
"cannot find -lexample.dll"
(here the dll suffix is to much)
The thing that works is renaming the libraries e.g. libexample.so to
example.dll

I wasn't aware that CMake does not support cross-compiling. Apart from
linking against the library with the correct prefix/suffix it works in my
case. Also I didn't know the option CROSS_MINGW32, however it setting the
option doesn't solve the problem.

Thanks for your help,

Peter.
Post by Eric Noulard
I am really interested in getting sample CMakeLists.txt
since I just wanted to do what you've done, i.e. cross-compiling
for win32 under linux.
You should know that CMake does not currently support cross-compiling.
See
http://www.cmake.org/pipermail/cmake/2006-September/010959.html
or
http://www.cmake.org/pipermail/cmake/2006-September/010946.html
For your "problem" I think you may try this in your
project CMakeLists.txt
IF (UNIX)
IF (CROSS_MINGW32)
SET(MY_TARGETLIB_PREFIX "")
SET(MY_TARGETLIB_SUFFIX ".dll")
ELSE (CROSS_MINGW32)
SET(MY_TARGETLIB_PREFIX "lib")
SET(MY_TARGETLIB_SUFFIX ".so")
ENDIF (CROSS_MINGW32)
ENDIF (UNIX)
I assume
OPTION(CROSS_MINGW32 "Cross compile Win32 using mingw32" OFF)
was set ON for mingw32 cross compiling
and OFF for Linux "native" compiling.
Then use your MY_TARGETLIB_xxx
SET_TARGET_PROPERTIES(ex1
PROPERTIES
PREFIX $(MY_TARGETLIB_PREFIX)
SUFFIX $(MY_TARGETLIB_SUFFIX)
)
Post by Peter Visser
Hi,
I have a working build under win32 with MSYS/MINGW, now I would like to
cross-compile code for win32 with mingw from linux with by using the
same
Post by Peter Visser
CMakelists.txt files. It almost works, the problem is that the shared
libraries are not named "myex.dll" but "libmyex.so". By using the
following
Post by Peter Visser
SET_TARGET_PROPERTIES(ex1
PROPERTIES PREFIX ""
SUFFIX
".dll"
)
However, now I have to change the CMakelist.txt in all the
subdirectories
Post by Peter Visser
and lose the ability to compile natively for linux (without adding an
IF(UNIX) around the SET_TARGET_PROPERTIES).
Is there a global option to set the PREFIX and SUFFIX, set the
BUILD_TARGET
Post by Peter Visser
to win32 or something alike?
SET(UNIX FALSE)
SET(MINGW TRUE)
SET(WIN32 TRUE)
But that doesn't help.
Any help is appreciated,
Peter.
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
--
Erk
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
Alexander Neundorf
2006-11-16 22:26:53 UTC
Permalink
Post by Peter Visser
The great thing is that cross compiling was very simple with to setup with
CMake in my case, I didn't require a "special" CMakeLists.txt.
export CC=i586-mingw32msvc-gcc
export CXX=i586-mingw32msvc-g++
export LD=i586-mingw32msvc-ld
export AR=i586-mingw32msvc-ar
export AS=i586-mingw32msvc-as
export NM=i586-mingw32msvc-nm
export STRIP=i586-mingw32msvc-strip
export RANLIB=i586-mingw32msvc-ranlib
export DLLTOOL=i586-mingw32msvc-dlltool
export OBJDUMP=i586-mingw32msvc-objdump
export RESCOMP=i586-mingw32msvc-windres
export CFLAGS=
For eCos I set the variables from withtin the cmake files, you could do this too:
SET(CMAKE_C_COMPILER i586-mingw32msvc-gcc)
And you probably have to set some more variables, e.g. I also need to set CMAKE_CXX_LINK_EXECUTABLE() and CMAKE_C_LINK_EXECUTABLE().
Did you already have a look at some of the platform files ?

Bye
Alex
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
Eric Noulard
2006-11-16 23:05:11 UTC
Permalink
Post by Peter Visser
The great thing is that cross compiling was very simple with to setup with
CMake in my case, I didn't require a "special" CMakeLists.txt.
export CC=i586-mingw32msvc-gcc
[...]

Ok now I see what you did.
Post by Peter Visser
Also I didn't know the option CROSS_MINGW32, however it setting the
option doesn't solve the problem.
I (wrongly) assumed that you had set such kind of OPTION
in order to handle cross-compiling.

I was wrong.
CROSS_MINGW32 was an example not a standard CMake option.
Post by Peter Visser
Post by Eric Noulard
I am really interested in getting sample CMakeLists.txt
since I just wanted to do what you've done, i.e. cross-compiling
for win32 under linux.
You should know that CMake does not currently support cross-compiling.
See
http://www.cmake.org/pipermail/cmake/2006-September/010959.html
Post by Eric Noulard
or
http://www.cmake.org/pipermail/cmake/2006-September/010946.html
Post by Eric Noulard
For your "problem" I think you may try this in your
project CMakeLists.txt
IF (UNIX)
IF (CROSS_MINGW32)
SET(MY_TARGETLIB_PREFIX "")
SET(MY_TARGETLIB_SUFFIX ".dll")
ELSE (CROSS_MINGW32)
SET(MY_TARGETLIB_PREFIX "lib")
SET(MY_TARGETLIB_SUFFIX ".so")
ENDIF (CROSS_MINGW32)
ENDIF (UNIX)
I assume
OPTION(CROSS_MINGW32 "Cross compile Win32 using mingw32" OFF)
was set ON for mingw32 cross compiling
and OFF for Linux "native" compiling.
Then use your MY_TARGETLIB_xxx
SET_TARGET_PROPERTIES(ex1
PROPERTIES
PREFIX $(MY_TARGETLIB_PREFIX)
SUFFIX $(MY_TARGETLIB_SUFFIX)
)
Post by Peter Visser
Hi,
I have a working build under win32 with MSYS/MINGW, now I would like to
cross-compile code for win32 with mingw from linux with by using the
same
Post by Eric Noulard
Post by Peter Visser
CMakelists.txt files. It almost works, the problem is that the shared
libraries are not named "myex.dll" but " libmyex.so". By using the
following
Post by Eric Noulard
Post by Peter Visser
SET_TARGET_PROPERTIES(ex1
PROPERTIES PREFIX ""
SUFFIX
Post by Eric Noulard
Post by Peter Visser
".dll"
)
However, now I have to change the CMakelist.txt in all the
subdirectories
Post by Eric Noulard
Post by Peter Visser
and lose the ability to compile natively for linux (without adding an
IF(UNIX) around the SET_TARGET_PROPERTIES).
Is there a global option to set the PREFIX and SUFFIX, set the
BUILD_TARGET
Post by Eric Noulard
Post by Peter Visser
to win32 or something alike?
SET(UNIX FALSE)
SET(MINGW TRUE)
SET(WIN32 TRUE)
But that doesn't help.
Any help is appreciated,
Peter.
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
--
Erk
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
--
Erk
Peter Visser
2006-11-17 17:45:18 UTC
Permalink
Hi,

I now have a working example to cross compile the CMake example (
http://www.cmake.org/HTML/Examples.html) with MINGW under linux for windows.
Unfortunately it requires a "small" replace in a build.make file, I wasn't
able to figure it out completely in CMake.

To get the example working I changed the CMakelists.txt in the Hello subdir
to the following:
add_library (Hello SHARED hello.cxx)
SET_TARGET_PROPERTIES(Hello
PROPERTIES SUFFIX ".dll"
)

The problem when building this example is that by adding the suffix for some
reason (probably intended behaviour) the linker options are changed from
"-lHello" to "-llibHello.dll" which cannot be found.

By changing it back to "-lHello" in Demo/CMakeFiles/helloDemo.dir/build.make
the example builds ok and runs ok.

I took a brief look at the platfrom files but could not find where the
libraries suffixes and prefixes are set. (I probably don't know what to look
for exactly.)

For now, I'll write a small replace script that replaces the "-llibxxx.dll"
with "-lxxx" in the build.make files and add a "IF (CROSS_MINGW32)" as
suggested. Thanks for pointing out that CROSS_MINGW32 is an example option.
(I misread the example probably due to wishful thinking and lack of coffee.)



Thanks for the help and suggestions,

Peter.

Loading...