I use Code :: Blocks, MinGW and Windows. I am trying to initialize winsock so that I can work on a project. I keep getting the error Undefined Reference to WSAStartup@8Does anyone know how to fix this?
Undefined Reference to WSAStartup@8
#include <stdio.h> #include <stdlib.h> #include <winsock2.h> #pragma comment(lib,"ws2_32.lib") int main(int argc , char *argv[]){ WSADATA wsa; int output; output=WSAStartup(MAKEWORD(2,2),&wsa); if(output != 0) { printf("Startup failed %d\n", output); return 1; } else { printf("Initialized"); return 0; } }
. , , , , , , . winsock -lws2_32, .
-lws2_32
gcc prog.c -o prog -lws2_32
, ( Microsoft), #pragma comment(lib,"ws2_32.lib"). :
#pragma comment(lib,"ws2_32.lib")
, MSVC ; , (), tinky_winky:
gcc prog.c -o prog.exe [...other .c and .o files...] -lws2_32 ...
( , , ).
: , funtion, , . lib MINGW ( C:/MinGW/lib); , , Dlib regconite missing lib. wxWidgets Code:: Blocks
You can check yours compiler options, add -lws2_32in add linker options when linking. I use TDM-GCC, works well after that.
compiler options
add linker options when linking
Source: https://habr.com/ru/post/1621016/More articles:How can I iterate over a list from a specific index? - pythonAccess to the upper left corner of `uitable` - matlabFirebase-Android, failed to save data after a long downtime - androidLaravel: How to get related table columns with active load - phpFirebase-Android, how to sync data when resuming after losing a connection? - androidFast image processing filters - image-processingAndroid Application Architecture - RxJava - javaWhat is a Django endpoint? - javascript'if x% 2: return True', will True return if the number was divisible by 2? - pythonPython regex matches only the whole string - pythonAll Articles