[cfe-dev] Cross compiling for windows with clang

Stephen Kelly steveire at gmail.com
Sat May 18 08:08:46 PDT 2013


Reid Kleckner wrote:

> Since you're using the mingw linker, you should probably target mingw. 
> Try
> using i386-pc-mingw32 as the triple.  I think using win32 as the os
> assumes you want the Visual Studio toolchain by default, and I don't
> recall what else controls it.
> 

Thanks for the pointer. That indeed does not warn when linking, but it also 
doesn't link at all:

stephen at hal:/tmp$ i686-w64-mingw32-gcc -v -shared lib.o -o example_dll.dll -
Wl,--out-implib,libexample_dll.a
Using built-in specs.
COLLECT_GCC=i686-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.6/lto-wrapper
Target: i686-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr 
--includedir='/usr/include' --mandir='/usr/share/man' --
infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --
libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-
dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-
multilib --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib 
--without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --
with-tune=generic --enable-version-specific-runtime-libs --enable-
threads=win32 --enable-fully-dynamic-string --enable-sjlj-exceptions --
enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-lto --with-plugin-
ld --target=i686-w64-mingw32 --with-gxx-include-dir=/usr/include/c++/4.6 --
with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld
Thread model: win32
gcc version 4.6.3 (GCC) 
COMPILER_PATH=/usr/lib/gcc/i686-w64-mingw32/4.6/:/usr/lib/gcc/i686-w64-
mingw32/4.6/:/usr/lib/gcc/i686-w64-mingw32/:/usr/lib/gcc/i686-w64-
mingw32/4.6/:/usr/lib/gcc/i686-w64-mingw32/
LIBRARY_PATH=/usr/lib/gcc/i686-w64-mingw32/4.6/:/usr/lib/gcc/i686-w64-
mingw32/4.6/../../../../i686-w64-mingw32/lib/../lib/:/usr/lib/gcc/i686-w64-
mingw32/4.6/../../../../i686-w64-mingw32/lib/
COLLECT_GCC_OPTIONS='-v' '-shared' '-o' 'example_dll.dll' '-mtune=generic' 
'-march=pentiumpro'
 /usr/lib/gcc/i686-w64-mingw32/4.6/collect2 -m i386pe --shared -Bdynamic -e 
_DllMainCRTStartup at 12 --enable-auto-image-base -o example_dll.dll 
/usr/lib/gcc/i686-w64-mingw32/4.6/../../../../i686-w64-
mingw32/lib/../lib/dllcrt2.o /usr/lib/gcc/i686-w64-mingw32/4.6/crtbegin.o -
L/usr/lib/gcc/i686-w64-mingw32/4.6 -L/usr/lib/gcc/i686-w64-
mingw32/4.6/../../../../i686-w64-mingw32/lib/../lib -L/usr/lib/gcc/i686-w64-
mingw32/4.6/../../../../i686-w64-mingw32/lib lib.o --out-implib 
libexample_dll.a -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt -
ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_eh -lgcc -lmoldname 
-lmingwex -lmsvcrt /usr/lib/gcc/i686-w64-mingw32/4.6/crtend.o
Cannot export myveryeasymethod(): symbol not found
collect2: ld returned 1 exit status


stephen at hal:/tmp$ cat lib.o  
Lݘ�Q�.textd P`.drectvej�*� -export:__Z16myveryeasymethodv.text.drectve 
_Z16myveryeasymethodv
stephen at hal:/tmp$ cat lib.o  | i686-w64-mingw32-c++filt 
Lݘ�Q� `.drectve�*� -export:myveryeasymethod() [clone .text] 

However, if I remove the BUILDING_EXAMPLE_DLL from in front of 
myveryeasymethod() it does successfully link, which is the opposite of what 
I expect...

Thanks,

Steve.





More information about the cfe-dev mailing list