MinGW linker error: winsock

前端 未结 4 1960
暗喜
暗喜 2020-11-28 05:50

I am using MinGW compiler on Windows to compile my C++ application with sockets. My command for linking looks like:

g++.exe -Wall -Wno-long-long -pedantic -l         


        
相关标签:
4条回答
  • 2020-11-28 05:53

    Greetings I just went through the problem above....

    So here are some observations first off....

    I know you are refering to MinGw, but you may need cygwin to get around this, I don't know mingw that well, I know cygwin better. But I know that they are cousins of each other.

    Cygwin comes with the precompiled boost libraries, but who knows of which version they are. I'm sure it's possible to check, but who has time to do that right? I do not link against cygwin boost libraries, or the mingw boost libraries, I built boost from scratch using gcc on windows (cygwin). The compile did fine.

    At the time of this writing boost is on version 1.47.0 I beleive.

    Already that fact that cygwin uses version (x?) and boost is 1.47.0 could be a major issue. Make you know what you are using in the way of boost.

    I was using code developed on boost 1.42, and had related linker errors. The code compiled, headers were found, etc..etc... but then I got the undefined reference to WSA etc...etc...opensocket this, close socket that, etc....

    So, apparantly boost, in order to do network sockets, requires a platform library, in which was found in the form of ws2_32 for windows, and socket for linux for sure.

    So if you are properly using boost, and including the correct boost system libraries, you may also need an OS specific library to access some resources (networking in this case).

    Linker errors dissappear after that. It's probably obvious to boost veterans what's going on here, but I was unable to find a clear answer via google.

    0 讨论(0)
  • 2020-11-28 06:05

    with mingw on eclipse: Menu - Projekt - Properties - c/c++Build - Settings: Register "Tool Settings" - MinGW C Linker - Miscellaneous: Lower Part "other objects" add: "D:\Programmierung\mingw\lib\libwsock32.a" for example. No other entries for libwsock32.a on any other properties required, especially not in Library-entries. Also no flags relating to this Lib.

    0 讨论(0)
  • 2020-11-28 06:05

    In:

    Menu - Project - Properties - c/c++Build - Settings: Register "Tool Settings" - MinGW C++ Linker - Miscellaneous: Lower Part "other objects"

    Add: libwsock32.a from bin folder of MinGW.

    0 讨论(0)
  • 2020-11-28 06:10

    Put the -lws2_32 AFTER the list of object files - GCC searches libraries and object files in the order they appear on the command line.

    Just to help the other viewers out there:

    gcc hello.c -o hello.o -lws2_32
    
    0 讨论(0)
提交回复
热议问题