Discussion:
[64 bit] problem using Win32 API in native Cygwin64 library
Václav Zeman
2013-04-02 10:25:19 UTC
Permalink
Hi.

I have tried to compile the log4cplus library on Cygwin64. Compilation
goes fine but linking ends with error.

The file src/.libs/liblog4cplus_la-cygwin-win32.o is the only one that
references Win32 API and includes windows.h. The library is trying to
get Windows' thread ID using the GetCurrentThreadId() function.

Here is libtool invocation:

libtool: link: g++ -shared -nostdlib
/usr/lib/gcc/x86_64-pc-cygwin/4.8.0/crtbegin.o
src/.libs/liblog4cplus_la-appenderattachableimpl.o
src/.libs/liblog4cplus_la-appender.o
src/.libs/liblog4cplus_la-asyncappender.o
src/.libs/liblog4cplus_la-clogger.o
src/.libs/liblog4cplus_la-configurator.o
src/.libs/liblog4cplus_la-consoleappender.o
src/.libs/liblog4cplus_la-cygwin-win32.o
src/.libs/liblog4cplus_la-env.o src/.libs/liblog4cplus_la-factory.o
src/.libs/liblog4cplus_la-fileappender.o
src/.libs/liblog4cplus_la-fileinfo.o
src/.libs/liblog4cplus_la-filter.o
src/.libs/liblog4cplus_la-global-init.o
src/.libs/liblog4cplus_la-hierarchy.o
src/.libs/liblog4cplus_la-hierarchylocker.o
src/.libs/liblog4cplus_la-layout.o
src/.libs/liblog4cplus_la-log4judpappender.o
src/.libs/liblog4cplus_la-lockfile.o
src/.libs/liblog4cplus_la-logger.o
src/.libs/liblog4cplus_la-loggerimpl.o
src/.libs/liblog4cplus_la-loggingevent.o
src/.libs/liblog4cplus_la-loggingmacros.o
src/.libs/liblog4cplus_la-loglevel.o
src/.libs/liblog4cplus_la-loglog.o
src/.libs/liblog4cplus_la-logloguser.o src/.libs/liblog4cplus_la-mdc.o
src/.libs/liblog4cplus_la-ndc.o
src/.libs/liblog4cplus_la-nullappender.o
src/.libs/liblog4cplus_la-nteventlogappender.o
src/.libs/liblog4cplus_la-objectregistry.o
src/.libs/liblog4cplus_la-patternlayout.o
src/.libs/liblog4cplus_la-pointer.o
src/.libs/liblog4cplus_la-property.o src/.libs/liblog4cplus_la-queue.o
src/.libs/liblog4cplus_la-rootlogger.o
src/.libs/liblog4cplus_la-sleep.o src/.libs/liblog4cplus_la-snprintf.o
src/.libs/liblog4cplus_la-socketappender.o
src/.libs/liblog4cplus_la-socketbuffer.o
src/.libs/liblog4cplus_la-socket.o
src/.libs/liblog4cplus_la-socket-unix.o
src/.libs/liblog4cplus_la-socket-win32.o
src/.libs/liblog4cplus_la-stringhelper.o
src/.libs/liblog4cplus_la-stringhelper-clocale.o
src/.libs/liblog4cplus_la-stringhelper-cxxlocale.o
src/.libs/liblog4cplus_la-stringhelper-iconv.o
src/.libs/liblog4cplus_la-syncprims.o
src/.libs/liblog4cplus_la-syslogappender.o
src/.libs/liblog4cplus_la-threads.o
src/.libs/liblog4cplus_la-timehelper.o src/.libs/liblog4cplus_la-tls.o
src/.libs/liblog4cplus_la-version.o
src/.libs/liblog4cplus_la-win32consoleappender.o
src/.libs/liblog4cplus_la-win32debugappender.o -lws2_32 -ladvapi32
-lkernel32 -L/usr/lib/gcc/x86_64-pc-cygwin/4.8.0
-L/usr/lib/gcc/x86_64-pc-cygwin/4.8.0/../../../../x86_64-pc-cygwin/lib/../lib
-L/usr/lib/gcc/x86_64-pc-cygwin/4.8.0/../../../../lib -L/lib/../lib
-L/usr/lib/../lib
-L/usr/lib/gcc/x86_64-pc-cygwin/4.8.0/../../../../x86_64-pc-cygwin/lib
-L/usr/lib/gcc/x86_64-pc-cygwin/4.8.0/../../.. -lstdc++
-lssp_nonshared -lssp -lgcc_s -lgcc -lcygwin -ladvapi32 -lshell32
-luser32 -lkernel32 -lgcc_s -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.8.0/crtend.o -O2
-Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc -o
.libs/cyglog4cplus-1-2-0.dll -Wl,--enable-auto-image-base -Xlinker
--out-implib -Xlinker .libs/liblog4cplus.dll.a

And here is the error message:

src/.libs/liblog4cplus_la-cygwin-win32.o: In function `VarCmp':
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
src/.libs/liblog4cplus_la-cygwin-win32.o: In function `_InterlockedAdd':
/usr/include/w32api/winnt.h:1452: undefined reference to
`_InterlockedExchangeAdd'
/usr/include/w32api/winnt.h:1452:(.text$_InterlockedAdd[_InterlockedAdd]+0x2c):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`_InterlockedExchangeAdd'
src/.libs/liblog4cplus_la-cygwin-win32.o: In function `_InterlockedAdd64':
/usr/include/w32api/winnt.h:1490: undefined reference to
`_InterlockedExchangeAdd64'
/usr/include/w32api/winnt.h:1490:(.text$_InterlockedAdd64[_InterlockedAdd64]+0x2d):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`_InterlockedExchangeAdd64'
src/.libs/liblog4cplus_la-cygwin-win32.o: In function `MultiplyExtract128':
/usr/include/w32api/winnt.h:1641: undefined reference to `_mul128'
/usr/include/w32api/winnt.h:1641:(.text$MultiplyExtract128[MultiplyExtract128]+0x32):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`_mul128'
/usr/include/w32api/winnt.h:1642: undefined reference to `__shiftright128'
/usr/include/w32api/winnt.h:1642:(.text$MultiplyExtract128[MultiplyExtract128]+0x43):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`__shiftright128'
src/.libs/liblog4cplus_la-cygwin-win32.o: In function
`UnsignedMultiplyExtract128':
/usr/include/w32api/winnt.h:1650: undefined reference to `_umul128'
/usr/include/w32api/winnt.h:1650:(.text$UnsignedMultiplyExtract128[UnsignedMultiplyExtract128]+0x32):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`_umul128'
/usr/include/w32api/winnt.h:1651: undefined reference to `__shiftright128'
/usr/include/w32api/winnt.h:1651:(.text$UnsignedMultiplyExtract128[UnsignedMultiplyExtract128]+0x43):
relocation truncated to fit: R_X86_64_PC32 against undefined symbol
`__shiftright128'
collect2: error: ld returned 1 exit status
Makefile:1110: recipe for target `liblog4cplus.la' failed
make[2]: *** [liblog4cplus.la] Error 1
make[2]: Leaving directory
`/cygdrive/c/stuff/log4cplus-bzr-repo/work-trunk/objdir-cygwin64'
Makefile:1960: recipe for target `all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory
`/cygdrive/c/stuff/log4cplus-bzr-repo/work-trunk/objdir-cygwin64'
Makefile:849: recipe for target `all' failed
make: *** [all] Error 2
--
VZ
Corinna Vinschen
2013-04-02 11:19:42 UTC
Permalink
Hi Václav,
Post by Václav Zeman
Hi.
I have tried to compile the log4cplus library on Cygwin64. Compilation
goes fine but linking ends with error.
[...]
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
/usr/include/w32api/winnt.h:1452: undefined reference to
`_InterlockedExchangeAdd'
[...]
Thanks for the report. That's apparently a bug in the Cygwin w32api
implementation of the mingw libs. On 64 bit, a lot of simple functions
of the w32api, or functions used under the hood of inline functions, are
implemented as compiler intrinsics in the Microsoft Visual compilers.

These compiler intrinsics don't exist in gcc, therefore they are
implemented as library functions in Mingw-w64. Unfortunately they are
implemented in libmingwex.a right now, which is not included in the
Cygwin w32api.

I'm going to fix that today, so that the intrinsics will be exported
by libkernel32.a instead. This allows Cygwin applications to access
them as well.

Stay tuned.


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Corinna Vinschen
2013-04-02 15:37:05 UTC
Permalink
Post by Corinna Vinschen
Hi Václav,
Post by Václav Zeman
Hi.
I have tried to compile the log4cplus library on Cygwin64. Compilation
goes fine but linking ends with error.
[...]
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
/usr/include/w32api/winnt.h:1452: undefined reference to
`_InterlockedExchangeAdd'
[...]
Thanks for the report. That's apparently a bug in the Cygwin w32api
implementation of the mingw libs. On 64 bit, a lot of simple functions
of the w32api, or functions used under the hood of inline functions, are
implemented as compiler intrinsics in the Microsoft Visual compilers.
These compiler intrinsics don't exist in gcc, therefore they are
implemented as library functions in Mingw-w64. Unfortunately they are
implemented in libmingwex.a right now, which is not included in the
Cygwin w32api.
I'm going to fix that today, so that the intrinsics will be exported
by libkernel32.a instead. This allows Cygwin applications to access
them as well.
Stay tuned.
I just uploaded a new w32api package which should fix this issue.
The intrinsics are now provide by libkernel32.a. Please give it
a try.


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Václav Zeman
2013-04-03 11:25:30 UTC
Permalink
Post by Corinna Vinschen
Post by Corinna Vinschen
Hi Václav,
Post by Václav Zeman
Hi.
I have tried to compile the log4cplus library on Cygwin64. Compilation
goes fine but linking ends with error.
[...]
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
/usr/include/w32api/winnt.h:1452: undefined reference to
`_InterlockedExchangeAdd'
[...]
Thanks for the report. That's apparently a bug in the Cygwin w32api
implementation of the mingw libs. On 64 bit, a lot of simple functions
of the w32api, or functions used under the hood of inline functions, are
implemented as compiler intrinsics in the Microsoft Visual compilers.
These compiler intrinsics don't exist in gcc, therefore they are
implemented as library functions in Mingw-w64. Unfortunately they are
implemented in libmingwex.a right now, which is not included in the
Cygwin w32api.
I'm going to fix that today, so that the intrinsics will be exported
by libkernel32.a instead. This allows Cygwin applications to access
them as well.
Stay tuned.
I just uploaded a new w32api package which should fix this issue.
The intrinsics are now provide by libkernel32.a. Please give it
a try.
It is much better but I am still getting one failure:

src/.libs/liblog4cplus_la-cygwin-win32.o: In function `VarCmp':
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
collect2: error: ld returned 1 exit status
Makefile:1110: recipe for target `liblog4cplus.la' failed
--
VZ
Corinna Vinschen
2013-04-03 11:36:25 UTC
Permalink
Post by Václav Zeman
Post by Corinna Vinschen
Post by Corinna Vinschen
Hi Václav,
Post by Václav Zeman
Hi.
I have tried to compile the log4cplus library on Cygwin64. Compilation
goes fine but linking ends with error.
[...]
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
/usr/include/w32api/winnt.h:1452: undefined reference to
`_InterlockedExchangeAdd'
[...]
Thanks for the report. That's apparently a bug in the Cygwin w32api
implementation of the mingw libs. On 64 bit, a lot of simple functions
of the w32api, or functions used under the hood of inline functions, are
implemented as compiler intrinsics in the Microsoft Visual compilers.
These compiler intrinsics don't exist in gcc, therefore they are
implemented as library functions in Mingw-w64. Unfortunately they are
implemented in libmingwex.a right now, which is not included in the
Cygwin w32api.
I'm going to fix that today, so that the intrinsics will be exported
by libkernel32.a instead. This allows Cygwin applications to access
them as well.
Stay tuned.
I just uploaded a new w32api package which should fix this issue.
The intrinsics are now provide by libkernel32.a. Please give it
a try.
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
collect2: error: ld returned 1 exit status
Makefile:1110: recipe for target `liblog4cplus.la' failed
Are you using C++? If so, can you try to use the other variant
of VarCmp, with an extra, forth parameter, set to 0?


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Corinna Vinschen
2013-04-03 11:39:28 UTC
Permalink
Post by Corinna Vinschen
Post by Václav Zeman
Post by Corinna Vinschen
I just uploaded a new w32api package which should fix this issue.
The intrinsics are now provide by libkernel32.a. Please give it
a try.
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
collect2: error: ld returned 1 exit status
Makefile:1110: recipe for target `liblog4cplus.la' failed
Are you using C++? If so, can you try to use the other variant
of VarCmp, with an extra, forth parameter, set to 0?
Also, can you create some self-contained testcase for your scenario,
which allows to reproduce the link error?


Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Corinna Vinschen
2013-04-03 11:59:06 UTC
Permalink
Post by Corinna Vinschen
Post by Václav Zeman
Post by Corinna Vinschen
I just uploaded a new w32api package which should fix this issue.
The intrinsics are now provide by libkernel32.a. Please give it
a try.
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
collect2: error: ld returned 1 exit status
Makefile:1110: recipe for target `liblog4cplus.la' failed
Are you using C++? If so, can you try to use the other variant
of VarCmp, with an extra, forth parameter, set to 0?
I just tried it myself and I can link against VarCmp just fine...
*If* I add a -loleaut32 to the linker stage.


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Václav Zeman
2013-04-03 12:28:19 UTC
Permalink
Post by Corinna Vinschen
Post by Corinna Vinschen
Post by Václav Zeman
Post by Corinna Vinschen
I just uploaded a new w32api package which should fix this issue.
The intrinsics are now provide by libkernel32.a. Please give it
a try.
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
collect2: error: ld returned 1 exit status
Makefile:1110: recipe for target `liblog4cplus.la' failed
Are you using C++? If so, can you try to use the other variant
of VarCmp, with an extra, forth parameter, set to 0?
I am using C++ but I am not using the VarCmp() function at all. I am
only including the windows.h header.
Post by Corinna Vinschen
I just tried it myself and I can link against VarCmp just fine...
*If* I add a -loleaut32 to the linker stage.
I think this is my fault. I am using '-fkeep-inline-functions' GCC
flag for my debug builds. I have not tested but I believe it will work
when I remove the option. I have solved it in the library by linking
to oleaut32.lib.

It is odd that I have never experienced the same issue on 32 bit Cygwin.
--
VZ
Corinna Vinschen
2013-04-03 14:11:32 UTC
Permalink
Post by Václav Zeman
Post by Corinna Vinschen
Post by Corinna Vinschen
Post by Václav Zeman
Post by Corinna Vinschen
I just uploaded a new w32api package which should fix this issue.
The intrinsics are now provide by libkernel32.a. Please give it
a try.
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
collect2: error: ld returned 1 exit status
Makefile:1110: recipe for target `liblog4cplus.la' failed
Are you using C++? If so, can you try to use the other variant
of VarCmp, with an extra, forth parameter, set to 0?
I am using C++ but I am not using the VarCmp() function at all. I am
only including the windows.h header.
Post by Corinna Vinschen
I just tried it myself and I can link against VarCmp just fine...
*If* I add a -loleaut32 to the linker stage.
I think this is my fault. I am using '-fkeep-inline-functions' GCC
flag for my debug builds. I have not tested but I believe it will work
when I remove the option. I have solved it in the library by linking
to oleaut32.lib.
Erm... oleaut32.lib? You didn't link against the Microsoft link lib,
did you? That should have been -loleaut32 or /usr/lib/w32api/liboleaut32.a
Post by Václav Zeman
It is odd that I have never experienced the same issue on 32 bit Cygwin.
Even when using the newer w32api headers from mingw-w64? Maybe there's
a difference in terms of gcc versions...


Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Václav Zeman
2013-04-03 16:11:42 UTC
Permalink
Post by Corinna Vinschen
Post by Václav Zeman
Post by Corinna Vinschen
Post by Corinna Vinschen
Post by Václav Zeman
Post by Corinna Vinschen
I just uploaded a new w32api package which should fix this issue.
The intrinsics are now provide by libkernel32.a. Please give it
a try.
/usr/include/w32api/oleauto.h:487: undefined reference to `VarCmp'
/usr/include/w32api/oleauto.h:487:(.text+0x34f): relocation truncated
to fit: R_X86_64_PC32 against undefined symbol `VarCmp'
collect2: error: ld returned 1 exit status
Makefile:1110: recipe for target `liblog4cplus.la' failed
Are you using C++? If so, can you try to use the other variant
of VarCmp, with an extra, forth parameter, set to 0?
I am using C++ but I am not using the VarCmp() function at all. I am
only including the windows.h header.
Post by Corinna Vinschen
I just tried it myself and I can link against VarCmp just fine...
*If* I add a -loleaut32 to the linker stage.
I think this is my fault. I am using '-fkeep-inline-functions' GCC
flag for my debug builds. I have not tested but I believe it will work
when I remove the option. I have solved it in the library by linking
to oleaut32.lib.
Erm... oleaut32.lib? You didn't link against the Microsoft link lib,
did you? That should have been -loleaut32 or /usr/lib/w32api/liboleaut32.a
Right. What I have actually done is that I have added
AC_HAVE_LIBRARY([oleaut32]) to my configure.ac.
Post by Corinna Vinschen
Post by Václav Zeman
It is odd that I have never experienced the same issue on 32 bit Cygwin.
Even when using the newer w32api headers from mingw-w64? Maybe there's
a difference in terms of gcc versions...
--
VZ
Loading...