PDA

View Full Version : Linking to a static library on Windows



rexi
22nd July 2009, 22:17
Hi,

I'm somewhat confused by this problem I ran into:
I have a static library (not written by me, though I have changed its build system to qmake) that I want to use in my application. The library itself is compatible with Linux and Windows, it is stated. And yes, it compiles well on both. But, when I want to actually use it, everything is fine on Linux, but on Windows the linker gives me strange errors that it cannot find anything. I am not at all familiar with how to use static libraries on Windows, so I guess the error is on my part...

As it is very small, I have attached the test project. Maybe someone can tell me what I am doing wrong?

Oh, and for those that take in interest in it: said library is XmlRpc++ (http://xmlrpcpp.sourceforge.net/)

kuzulis
23rd July 2009, 06:51
Try to use: http://code.google.com/p/qxmlrpc/source/checkout

rexi
23rd July 2009, 12:59
Thanks, I'll have a look at it. Still, I'd like to know what the problem is with linking on Windows and how to solve it.

kuzulis
23rd July 2009, 13:04
Thanks, I'll have a look at it. Still, I'd like to know what the problem is with linking on Windows and how to solve it.

No problems there! :)

franz
23rd July 2009, 22:48
Thanks, I'll have a look at it. Still, I'd like to know what the problem is with linking on Windows and how to solve it.

What compiler do you use and what are the errors you get?

rexi
24th July 2009, 00:10
g++ 3.4.2 from the MinGW installed with Qt 4.5.1.

The exact errors are:


g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
oc -mthreads -Wl -Wl,-subsystem,windows -o ..\build\xmlrpc-client.exe debug/clie
nt.o -L"c:\Qt\4.5.1\lib" -lmingw32 -lqtmaind -L../build -lxmlrpc -lQtCored4
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x2a): In function `Z11initWinSockv':

C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:48: undefined reference to `WSAStartup@8'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x5d): In function `ZN6XmlRpc12XmlRpc
Socket6socketEv':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:83: undefined reference to `socket@12'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x8e): In function `ZN6XmlRpc12XmlRpc
Socket5closeEi':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:92: undefined reference to `closesocket@4'

../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0xbc): In function `ZN6XmlRpc12XmlRpc
Socket14setNonBlockingEi':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:106: undefined reference to `ioctlsocket@1
2'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x10b): In function `ZN6XmlRpc12XmlRp
cSocket12setReuseAddrEi':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:118: undefined reference to `setsockopt@20
'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x157): In function `ZN6XmlRpc12XmlRp
cSocket4bindEii':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:129: undefined reference to `htonl@4'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x16b):C:/XmlRpc++/xmlrpc++/XmlRpcSoc
ket.cpp:130: undefined reference to `htons@4'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x18c):C:/XmlRpc++/xmlrpc++/XmlRpcSoc
ket.cpp:131: undefined reference to `bind@12'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x1bc): In function `ZN6XmlRpc12XmlRp
cSocket6listenEii':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:139: undefined reference to `listen@8'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x1fa): In function `ZN6XmlRpc12XmlRp
cSocket6acceptEi':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:154: undefined reference to `accept@12'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x23a): In function `ZN6XmlRpc12XmlRp
cSocket7connectEiRSsi':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:167: undefined reference to `gethostbyname
@4'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x290):C:/XmlRpc++/xmlrpc++/XmlRpcSoc
ket.cpp:172: undefined reference to `htons@4'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x2b1):C:/XmlRpc++/xmlrpc++/XmlRpcSoc
ket.cpp:176: undefined reference to `connect@12'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x389): In function `ZN6XmlRpc12XmlRp
cSocket6nbReadEiRSsPb':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:194: undefined reference to `recv@16'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x4a4): In function `ZN6XmlRpc12XmlRp
cSocket7nbWriteEiRSsPi':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:226: undefined reference to `send@16'
../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x51d): In function `ZN6XmlRpc12XmlRp
cSocket8getErrorEv':
C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:251: undefined reference to `WSAGetLastErr
or@0'
../build/libxmlrpc.a(XmlRpcDispatch.o)(.text+0x6b3): In function `ZN6XmlRpc14Xml
RpcDispatch4workEd':
C:/XmlRpc++/xmlrpc++/XmlRpcDispatch.cpp:103: undefined reference to `select@20'
../build/libxmlrpc.a(XmlRpcDispatch.o)(.text+0x7b6):C:/XmlRpc++/xmlrpc++/XmlRpcD
ispatch.cpp:109: undefined reference to `select@20'
../build/libxmlrpc.a(XmlRpcDispatch.o)(.text+0x8d6):C:/XmlRpc++/xmlrpc++/XmlRpcD
ispatch.cpp:128: undefined reference to `__WSAFDIsSet@8'
../build/libxmlrpc.a(XmlRpcDispatch.o)(.text+0x929):C:/XmlRpc++/xmlrpc++/XmlRpcD
ispatch.cpp:130: undefined reference to `__WSAFDIsSet@8'
../build/libxmlrpc.a(XmlRpcDispatch.o)(.text+0x97c):C:/XmlRpc++/xmlrpc++/XmlRpcD
ispatch.cpp:132: undefined reference to `__WSAFDIsSet@8'
collect2: ld returned 1 exit status
mingw32-make[2]: *** [..\build\xmlrpc-client.exe] Error 1
mingw32-make[2]: Leaving directory `C:/XmlRpc++/client'
mingw32-make[1]: *** [debug] Error 2
mingw32-make[1]: Leaving directory `C:/XmlRpc++/client'
mingw32-make: *** [sub-client-make_default-ordered] Error 2

kuzulis
24th July 2009, 07:00
Changes in the file : \XmlRpc++\xmlrp++\xmlrpc++.pro


XmlRcpSource.h \
XmlRcpUtil.h \
XmlRcpValue.h

on


XmlRpcSource.h \
XmlRpcUtil.h \
XmlRpcValue.h


PS: And to see that you display qmake - where it all clear

Be careful!

rexi
24th July 2009, 11:30
Thanks, that was a stupid typo. It doesn't change anything, though, the problem remains. The linking step still fails with the same error messages.

rexi
27th July 2009, 20:50
Just for the record, in case anyone is interested in this: the problem was that, in addition to the static library I used, I also had to link against the Winsocks library which is used by said static library. Strange, but it solves the problem.

rexi
27th July 2009, 20:54
Try to use: http://code.google.com/p/qxmlrpc/source/checkout

Looks promising, but there doesn't seem to happen much at the moment. I'll stay with XmlRpc++, as it has less dependencies. And it now, finally, works ;)