Dear list,

for the archive I want to note some more important details when linking 
mingw-w64 against msvcr90. 

Reminder: I patched the MinGW-w64 installation of openSuse (GCC 4.7.2) to 
generate a libmoldname90.a and then set new GCC specs that link against 
moldname90 and msvcr90 instead of moldname and msvcrt according to 
http://sourceforge.net/mailarchive/message.php?msg_id=30556805 .

I strongly discourage to link against libgcc and libstdc++ statically.  

If you do link statically against any of these, you may get a dysfunctional 
exception handling in your own C++ code. In my case, any thrown exception was 
leading to an abnormal program termination because any try catch(…) block was 
ignored. 

Best regards
Sebastian





On Mar 4, 2013, at 4:42 PM, Sebastian Wolff wrote:

> Hello Kai,
> 
> 
>> The file can be generated via '<prefix>-dlltool moldname-msvcrt.def -U
>> --dllname msvcr90.dll'
> 
> Wonderful !!!!!!!  That did the trick.
> I did not manage to use this command directly ( it did not do anything on my 
> machine), but I finally was able to build liboldname90 and the application 
> works fine. Thank you very much for your help!
> 
> Although little off-topic, one questions remains to me: Is it allowed to 
> distribute proprietary software which links against libgcc statically?
> 
> 
> For the archive, I want to illustrate the steps that I did in detail:
> 
> 
> Using MingW-w64 for linking against libs compiled with VS2008/VC++9.0 
> 
> Modify the GCC specs file
> Modify the Makefiles of MingW-w64-CRT
> Recompile the Mingw-w64 CRT
> Compile the application with the new specs
> Put a manifest next to the executable
> 
> Modify the specs file
> 
> This is done with the following shell script. It dumps the specs and appends 
> some code which makes the specs more flexible. The modified specs still link 
> against msvcrt.dll. Then another specs file is created which re-defines some 
> variables in order to link against msvcr90.dll. The idea is: The standard 
> call of MingW-w64 will use the built-in specs while one must specify if one 
> wants to link against another runtime. 
> 
> CC="${M_ROOT}/cross/bin/${MINGW_TRIPLE}-gcc"
> $CC -dumpspecs > $M_ROOT/specs_dumped
> 
> echo "%rename cpp msvcrXX_cpp:" >> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> echo "%rename cc1plus msvcrXX_cc1plus:" >> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> 
> echo "*local_prefix:" >> $M_ROOT/specs_dumped
> echo "$M_CROSS/" >> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> echo "*local_includes:" >> $M_ROOT/specs_dumped
> echo "-I%(local_prefix)include -I$M_CROSS/include" >> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> echo "*local_lib_search:" >> $M_ROOT/specs_dumped
> echo "-L%(local_prefix)lib -L$M_CROSS/lib -L$M_CROSS/lib64" >> 
> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> echo "%rename link_libgcc link_libgcc_XX:" >> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> echo "*link_libgcc:" >> $M_ROOT/specs_dumped
> echo "%(link_libgcc_XX) %(local_lib_search)" >> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> 
> echo "*cpp:" >> $M_ROOT/specs_dumped
> echo "%(msvcrXX_cpp) %(msvcrt_version) %(local_includes)" >> 
> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> echo "*cc1plus:" >> $M_ROOT/specs_dumped
> echo "%(msvcrXX_cc1plus) %(msvcrt_version) %(local_includes)" >> 
> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> 
> 
> sed -i -e 's/-lmsvcrt/-l\%\(msvcrt\)/g' $M_ROOT/specs_dumped
> sed -i -e 's/-lmoldname/\%\(moldname\)/g' $M_ROOT/specs_dumped
> 
> echo "*msvcrt:" >> $M_ROOT/specs_dumped
> echo "msvcrt" >> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> echo "*msvcrt_version:" >> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> echo "*moldname:" >> $M_ROOT/specs_dumped
> echo "-lmoldname" >> $M_ROOT/specs_dumped
> echo "" >> $M_ROOT/specs_dumped
> 
> rm -f $M_ROOT/specs_msvcr90
> echo "*msvcrt:" >> $M_ROOT/specs_msvcr90
> echo "msvcr90" >> $M_ROOT/specs_msvcr90
> echo "" >> $M_ROOT/specs_msvcr90
> echo "*msvcrt_version:" >> $M_ROOT/specs_msvcr90
> echo "-D__MSVCRT_VERSION__=0x0900" >> $M_ROOT/specs_msvcr90
> echo "" >> $M_ROOT/specs_msvcr90
> echo "*moldname:" >> $M_ROOT/specs_msvcr90
> echo "-lmoldname90" >> $M_ROOT/specs_msvcr90
> echo "" >> $M_ROOT/specs_msvcr90
> 
> cp $M_ROOT/specs_dumped  
> $M_CROSS/lib/gcc/x86_64-w64-mingw32/$GCC_VERSION/specs
> cp $M_ROOT/specs_msvcr90 
> $M_CROSS/lib/gcc/x86_64-w64-mingw32/$GCC_VERSION/specs_msvcr90
> 
> SPECFILE="specs_msvcr90" 
> export CFLAGS_FOR_TARGET="-specs $SPECFILE $CFLAGS"
> export CXXFLAGS_FOR_TARGET="-specs $SPECFILE $CXXFLAGS"
> export LFLAGS_FOR_TARGET="-specs $SPECFILE $LFLAGS"
> The last lines prepare some exports for recompiling the Mingw-w64-CRT
> 
> 
> Modify the makefiles of MingW-w64-CRT
> 
> Change into the directory of the sources of the Mingw-w64 runtime, eg. 
> sources/mingw-w64/mingw-w64-crt .
> Add the following lines to the file Makefile.am:
> 
> lib32_LIBRARIES += lib32/libmoldname90.a
> lib32_libmoldname90_a_CPPFLAGS=$(CPPFLAGS32) $(extra_include) $(AM_CPPFLAGS)
> lib32_libmoldname90_a_SOURCES = $(src_libmoldname)
> lib32_libmoldname90_a_AR = $(DTDEF32) $(top_srcdir)/lib32/moldname-msvcrt.def 
> -U --dllname msvcr90.dll && $(AR) $(ARFLAGS)
> 
> lib64_LIBRARIES += lib64/libmoldname90.a
> lib64_libmoldname90_a_CPPFLAGS=$(CPPFLAGS64) $(extra_include) $(AM_CPPFLAGS)
> lib64_libmoldname90_a_SOURCES = $(src_libmoldname)
> lib64_libmoldname90_a_AR = $(DTDEF64) $(top_srcdir)/lib64/moldname-msvcrt.def 
> -U --dllname msvcr90.dll && $(AR) $(ARFLAGS)
> 
> Then rebuild the configure script  with autotools (still from the CRT source 
> directory)
> aclocal
> automake
> autoconf
> Then rebuild the runtime (call configure with specific options and make && 
> make install).
> 
> 
> Compile the application with the new specs
> 
> I used the following command to compile a single ANSI C source file and link 
> it against some libs:
> MINGW_TRIPLE="x86_64-w64-mingw32"
> CC="$HOME_PATH/cross/bin/${MINGW_TRIPLE}-gcc"
> $CC -Wl,-v -v -specs specs_msvcr90 -DMINGW_HAS_SECURE_API=1 \
>   -O2 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 \
>   --param=ssp-buffer-size=4 -mms-bitfields -fno-keep-inline-dllexport  \
>   -O2 -mthreads -Wall -frtti $SOURCES $LIBDIR $INCDIR  $MYLIB \
>   --static-libgcc -static-libstdc++ -static -o myapp.exe
> (I used GCC 4.7.2 on Fedora with Mingw-w64 from SVN trunk. )
> 
> 
> Put a manifest file next to the executable (on Vista and later)
> 
> Create the file  myapp.exe.manifest with the following contents:
> 
> for 64 Bit:
> 
> <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
> <assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
>   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
>     <security>
>       <requestedPrivileges>
>         <requestedExecutionLevel level='asInvoker' uiAccess='false' />
>       </requestedPrivileges>
>     </security>
>   </trustInfo>
>   <dependency>
>     <dependentAssembly>
>       <assemblyIdentity type='win32' name='Microsoft.VC90.CRT' 
> version='9.0.21022.8' processorArchitecture='amd64' 
> publicKeyToken='1fc8b3b9a1e18e3b' />
>     </dependentAssembly>
>   </dependency>
> </assembly>
> 
> for 32 Bit:
> 
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
>   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
>     <security>
>       <requestedPrivileges>
>         <requestedExecutionLevel level="asInvoker" 
> uiAccess="false"></requestedExecutionLevel>
>       </requestedPrivileges>
>     </security>
>   </trustInfo>
>   <dependency>
>     <dependentAssembly>
>       <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" 
> version="9.0.21022.8" processorArchitecture="x86" 
> publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
>     </dependentAssembly>
>   </dependency>
> </assembly>
> 
> 
> 
> Best regards
> Sebastian 
> 
> 
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_feb_______________________________________________
> Mingw-w64-public mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to