[tlbuild] Static linking of C++ runtime library causing problems on x86_64-cygwin
Ken Brown
kbrow1i at gmail.com
Wed Feb 19 15:28:39 CET 2014
On 2/19/2014 2:41 AM, Peter Breitenlohner wrote:
> the macro in kpse-cxx-hack.m4 jusst reformulates what was done in earlier
> versions. For some (obscure?) reasons cygwin is treated differently from
> all other systems using gcc (including MinGW). Perhaps this distinction
> should be removed. In order to test this please try to change line 17862
> *cygwin*) flags_try0='-static -static-libgcc';
> of texk/web2c/configure into
> NEVER) flags_try0='-static -static-libgcc';
> and see if that helps (for cygwin32 and cygwin64). If that succeeds we can
> simplify the definition of _KPSE_CXX_HACK in m4/kpse-cxx-hack.m4.
Hi Peter,
It almost works. The problem is -nodefaultlibs. I made a test program
based on the configure test:
$ cat test.cc
#include <iostream>
using namespace std;
int
main ()
{
cout <<"worksok\n";
;
return 0;
}
It builds and runs fine (with static linking of stdc++) if I omit
-nodefaultlibs from try0:
$ g++ -o test test.cc -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic -lm
$ ./test.exe
worksok
$ ldd test.exe
ntdll.dll => /c/Windows/SysWOW64/ntdll.dll (0x775f0000)
kernel32.dll => /c/Windows/syswow64/kernel32.dll (0x75240000)
KERNELBASE.dll => /c/Windows/syswow64/KERNELBASE.dll (0x751c0000)
cygwin1.dll => /usr/bin/cygwin1.dll (0x61000000)
cyggcc_s-1.dll => /usr/bin/cyggcc_s-1.dll (0x6ac50000)
But with -nodefaultlibs, it fails on both x86-cygwin and x86_64-cygwin.
Here's the x86 case, but it looks the same on x86_64:
$ g++ -o test test.cc -nodefaultlibs -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
-lm /usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../crt0.o: In function
`mainCRTStartup':
/usr/src/debug/cygwin-1.7.28-2/winsup/cygwin/crt0.c:29: undefined
reference to `cygwin_crt0'
/usr/src/debug/cygwin-1.7.28-2/winsup/cygwin/crt0.c:34: undefined
reference to `cygwin_premain0'
/usr/src/debug/cygwin-1.7.28-2/winsup/cygwin/crt0.c:35: undefined
reference to `cygwin_premain1'
/usr/src/debug/cygwin-1.7.28-2/winsup/cygwin/crt0.c:36: undefined
reference to `cygwin_premain2'
/usr/src/debug/cygwin-1.7.28-2/winsup/cygwin/crt0.c:37: undefined
reference to `cygwin_premain3'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0xa):
undefined reference to `_imp__GetModuleHandleA at 4'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x2e):
undefined reference to `_imp__LoadLibraryA at 4'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x47):
undefined reference to `_imp__GetProcAddress at 8'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x8e):
undefined reference to `_imp__GetProcAddress at 8'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0xd2):
undefined reference to `_imp__GetProcAddress at 8'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0xf4):
undefined reference to `_imp__FreeLibrary at 4'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/crtbegin.o: bad reloc address 0x20 in
section `.eh_frame'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld:
final link failed: Invalid operation
collect2: error: ld returned 1 exit status
Is it important to use -nodefaultlibs?
Ken
More information about the tlbuild
mailing list