Results 1 to 10 of 10

Thread: Linking to a static library on Windows

  1. #1
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Linking to a static library on Windows

    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++
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking to a static library on Windows

    Try to use: http://code.google.com/p/qxmlrpc/source/checkout
    Attached Files Attached Files

  3. #3
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Linking to a static library on Windows

    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.

  4. #4
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking to a static library on Windows

    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!

  5. #5
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking to a static library on Windows

    Quote Originally Posted by rexi View Post
    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?

  6. #6
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Linking to a static library on Windows

    g++ 3.4.2 from the MinGW installed with Qt 4.5.1.

    The exact errors are:

    Qt Code:
    1. g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
    2. oc -mthreads -Wl -Wl,-subsystem,windows -o ..\build\xmlrpc-client.exe debug/clie
    3. nt.o -L"c:\Qt\4.5.1\lib" -lmingw32 -lqtmaind -L../build -lxmlrpc -lQtCored4
    4. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x2a): In function `Z11initWinSockv':
    5.  
    6. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:48: undefined reference to `WSAStartup@8'
    7. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x5d): In function `ZN6XmlRpc12XmlRpc
    8. Socket6socketEv':
    9. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:83: undefined reference to `socket@12'
    10. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x8e): In function `ZN6XmlRpc12XmlRpc
    11. Socket5closeEi':
    12. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:92: undefined reference to `closesocket@4'
    13.  
    14. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0xbc): In function `ZN6XmlRpc12XmlRpc
    15. Socket14setNonBlockingEi':
    16. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:106: undefined reference to `ioctlsocket@1
    17. 2'
    18. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x10b): In function `ZN6XmlRpc12XmlRp
    19. cSocket12setReuseAddrEi':
    20. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:118: undefined reference to `setsockopt@20
    21. '
    22. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x157): In function `ZN6XmlRpc12XmlRp
    23. cSocket4bindEii':
    24. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:129: undefined reference to `htonl@4'
    25. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x16b):C:/XmlRpc++/xmlrpc++/XmlRpcSoc
    26. ket.cpp:130: undefined reference to `htons@4'
    27. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x18c):C:/XmlRpc++/xmlrpc++/XmlRpcSoc
    28. ket.cpp:131: undefined reference to `bind@12'
    29. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x1bc): In function `ZN6XmlRpc12XmlRp
    30. cSocket6listenEii':
    31. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:139: undefined reference to `listen@8'
    32. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x1fa): In function `ZN6XmlRpc12XmlRp
    33. cSocket6acceptEi':
    34. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:154: undefined reference to `accept@12'
    35. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x23a): In function `ZN6XmlRpc12XmlRp
    36. cSocket7connectEiRSsi':
    37. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:167: undefined reference to `gethostbyname
    38. @4'
    39. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x290):C:/XmlRpc++/xmlrpc++/XmlRpcSoc
    40. ket.cpp:172: undefined reference to `htons@4'
    41. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x2b1):C:/XmlRpc++/xmlrpc++/XmlRpcSoc
    42. ket.cpp:176: undefined reference to `connect@12'
    43. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x389): In function `ZN6XmlRpc12XmlRp
    44. cSocket6nbReadEiRSsPb':
    45. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:194: undefined reference to `recv@16'
    46. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x4a4): In function `ZN6XmlRpc12XmlRp
    47. cSocket7nbWriteEiRSsPi':
    48. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:226: undefined reference to `send@16'
    49. ../build/libxmlrpc.a(XmlRpcSocket.o)(.text+0x51d): In function `ZN6XmlRpc12XmlRp
    50. cSocket8getErrorEv':
    51. C:/XmlRpc++/xmlrpc++/XmlRpcSocket.cpp:251: undefined reference to `WSAGetLastErr
    52. or@0'
    53. ../build/libxmlrpc.a(XmlRpcDispatch.o)(.text+0x6b3): In function `ZN6XmlRpc14Xml
    54. RpcDispatch4workEd':
    55. C:/XmlRpc++/xmlrpc++/XmlRpcDispatch.cpp:103: undefined reference to `select@20'
    56. ../build/libxmlrpc.a(XmlRpcDispatch.o)(.text+0x7b6):C:/XmlRpc++/xmlrpc++/XmlRpcD
    57. ispatch.cpp:109: undefined reference to `select@20'
    58. ../build/libxmlrpc.a(XmlRpcDispatch.o)(.text+0x8d6):C:/XmlRpc++/xmlrpc++/XmlRpcD
    59. ispatch.cpp:128: undefined reference to `__WSAFDIsSet@8'
    60. ../build/libxmlrpc.a(XmlRpcDispatch.o)(.text+0x929):C:/XmlRpc++/xmlrpc++/XmlRpcD
    61. ispatch.cpp:130: undefined reference to `__WSAFDIsSet@8'
    62. ../build/libxmlrpc.a(XmlRpcDispatch.o)(.text+0x97c):C:/XmlRpc++/xmlrpc++/XmlRpcD
    63. ispatch.cpp:132: undefined reference to `__WSAFDIsSet@8'
    64. collect2: ld returned 1 exit status
    65. mingw32-make[2]: *** [..\build\xmlrpc-client.exe] Error 1
    66. mingw32-make[2]: Leaving directory `C:/XmlRpc++/client'
    67. mingw32-make[1]: *** [debug] Error 2
    68. mingw32-make[1]: Leaving directory `C:/XmlRpc++/client'
    69. mingw32-make: *** [sub-client-make_default-ordered] Error 2
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking to a static library on Windows

    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!

  8. #8
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Linking to a static library on Windows

    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.

  9. #9
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Linking to a static library on Windows

    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.

  10. #10
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Linking to a static library on Windows

    Quote Originally Posted by kuzulis View Post
    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

Similar Threads

  1. Extending a plugin in a static library
    By ultim8 in forum Qt Programming
    Replies: 5
    Last Post: 25th March 2010, 15:10
  2. Trouble linking static library
    By russdot in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2009, 10:56
  3. Linking problems with QT4 under Windows
    By Ancalagon in forum Qt Programming
    Replies: 2
    Last Post: 8th September 2008, 13:29
  4. Qt 4.3 static linking on Windows
    By john_crichton in forum Installation and Deployment
    Replies: 2
    Last Post: 13th May 2008, 06:57
  5. Please Help-->have few doubts with Static build in Windows !
    By Krish in forum Installation and Deployment
    Replies: 1
    Last Post: 17th March 2008, 14:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.