J'utilise le compilateur MinGW sous Windows pour compiler mon application C++ avec des sockets. Ma commande de liaison ressemble à:
g++.exe -Wall -Wno-long-long -pedantic -lwsock32 -o dist/Windows/piskvorky { there are a lot of object files }
et j'ai aussi essayé
g++.exe -Wall -Wno-long-long -pedantic -lws2_32 -o dist/Windows/piskvorky { there are a lot of object files }
mais dans les deux cas, j'obtiens cette erreur:
build/Windows/MinGW-Windows/src/utils/tcpunit.o:tcpunit.cpp:(.text+0x33): undefined reference to `closesocket@4'
build/Windows/MinGW-Windows/src/utils/tcpunit.o:tcpunit.cpp:(.text+0xd0): undefined reference to `send@16'
build/Windows/MinGW-Windows/src/utils/tcpunit.o:tcpunit.cpp:(.text+0x1ee): undefined reference to `recv@16'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x184): undefined reference to `WSAStartup@8'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x1a5): undefined reference to `closesocket@4'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x1cb): undefined reference to `closesocket@4'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x1d3): undefined reference to `WSACleanup@0'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x6fe): undefined reference to `bind@12'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x724): undefined reference to `listen@8'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x7f0): undefined reference to `gethostbyaddr@12'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x83c): undefined reference to `socket@12'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x86f): undefined reference to `htons@4'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x8b5): undefined reference to `connect@12'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x9c6): undefined reference to `accept@12'
Avez-vous des idées sur le problème, s'il vous plaît?
Mettez le -lws2_32
APRÈS la liste des fichiers objets - GCC recherche les bibliothèques et les fichiers objets dans l'ordre où ils apparaissent sur la ligne de commande.
Juste pour aider les autres téléspectateurs:
gcc hello.c -o hello.o -lws2_32
avec mingw sur Eclipse: Menu - Projekt - Propriétés - Construction c/c ++ - Paramètres: Enregistrer les "Paramètres de l'outil" - Linker MinGW C - Divers: Partie inférieure "autres objets" ajouter: "D:\Programmierung\mingw\lib\libwsock32.a "par exemple. Aucune autre entrée pour libwsock32.a sur les autres propriétés requises, en particulier pas dans les entrées de bibliothèque. Pas de drapeaux non plus concernant ce Lib.
Dans:
Menu - Projet - Propriétés - Construction c/c ++ - Paramètres: Enregistrer les "Paramètres de l'outil" - Linker MinGW C++ - Divers: Partie inférieure "Autres objets"
Ajoutez: libwsock32.a à partir du dossier bin de MinGW.