[cfe-dev] Cross compiling for windows with clang

Reid Kleckner rnk at google.com
Sun May 19 04:48:31 PDT 2013


Looking at the export directive, it seems like something is off in name
mangling.
-export:__Z16myveryeasymethodv

The double underscore seems wrong, which suggests we're applying both C and
C++ mangling.  Use a version of nm that works on COFF to make sure that the
.o has the same name as the -export.

If it's broken, try building TOT clang, and if that doesn't work, please
file a bug.  There was a recent bugfix for a similar issue which had to do
with stdcall mangling, but I'm not sure if it's the same as this one.

On Sat, May 18, 2013 at 11:08 AM, Stephen Kelly <steveire at gmail.com> wrote:

> 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.
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130519/b5986730/attachment.html>


More information about the cfe-dev mailing list