소켓 프로그래밍에서 컴파일시 에러가 납니다.

lkjt의 이미지

환경
--------win32 g++

에러코드:

C:\WINDOWS\system32\cmd.exe /c g++ project\downHTML\source.cpp -o project\downHT
ML\source
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccAraaaa.o(.text+0x11e):source.cpp: undefined
 reference to `WSAStartup@8'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccAraaaa.o(.text+0x19c):source.cpp: undefined
 reference to `socket@12'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccAraaaa.o(.text+0x1b9):source.cpp: undefined
 reference to `WSAGetLastError@0'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccAraaaa.o(.text+0x1cf):source.cpp: undefined
 reference to `WSACleanup@0'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccAraaaa.o(.text+0x1ea):source.cpp: undefined
 reference to `inet_addr@4'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccAraaaa.o(.text+0x1fd):source.cpp: undefined
 reference to `htons@4'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccAraaaa.o(.text+0x21e):source.cpp: undefined
 reference to `connect@12'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccAraaaa.o(.text+0x23b):source.cpp: undefined
 reference to `WSACleanup@0'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccAraaaa.o(.text+0x296):source.cpp: undefined
 reference to `send@16'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccAraaaa.o(.text+0x2bd):source.cpp: undefined
 reference to `recv@16'
shell returned 1
Hit any key to close this window...

이렇게 나는데요,,, 이건 왜그러는건가요?
비쥬얼 C++에서 도 이런에러가 나는군요,,,

Rica의 이미지

VisualC++라면 wsock32.lib 를 명시적으로 링크해야 합니다.
#pragma comment(lib, "wsock32.lib") 를 아무 소스 파일에나 써주시면 되겠네요.

Win32에서 g++은 안 써봐서 잘 모르겠습니다만 비슷하지 않을까요. 라이브러리 링크..

feanor의 이미지

GCC에서는 명령행에 -lwsock32 적어주시면 됩니다.

--feanor

lkjt의 이미지

감사합니다.