[CMake] How to static link with MinGW's libgcc and libstdc++

Alan W. Irwin irwin at beluga.phys.uvic.ca
Tue Sep 11 12:24:16 EDT 2012


On 2012-09-11 22:21+0800 Loaden wrote:

> Hi, list!
> I wan't use cmake + MSVC2010SP1 via wine on Linux (Ubuntu 12.04).
> In first step, I need compile CMake self on Linux, so the cross compilation
> is should to go.
> I edit the CMake 2.8.9's main CMakeLists.txt, added these line:
>
> if (MINGW)
>>     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc")
>>     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc
>> -static-libstdc++")
>>     set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS
>> "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static-libgcc -s")
>>     set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS
>> "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static-libgcc -static-libstdc++
>> -s")
>> endif()
>>
>
> and it works.
> But I thought it possible not correct.
> Because it's more complex.
>
> Does there exist a simply way to solve my problem?
> Thanks!

I think so.  From your first sentence I assume your purpose is to
build software under Wine on Linux. If that assumption is correct,
then you don't need to worry about cross-compilation.  Instead, just
use the Windows version of CMake to help do the build.  I have done
that in the past, and in fact redundantly built a Windows version of
CMake that way as a proof of concept.  I also built and tested a fair
amount of other software that way including PLplot and a number of its
library dependencies and also ephcom2 (part of the timeephem project).
My purpose in these cases was to test the cross-platform capabilities
of my software projects.  That is, I made sure my software projects
built and tested without problems with MinGW (the Windows version of
gcc), MSYS (the Windows version of make and bash and other useful
tools), and the Windows version of CMake on a Windows platform (Wine
under Linux) just like my software project built and tested without
issues with Linux versions of gcc, make and bash, and CMake on the
Linux platform.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list