操作系统 WINDOWS XP
环境 VC 6.0
源码:(照着计算机网络与因特网第26章摘抄的)#include <windows.h>
#include <winsock.h>#include <stdio.h>
#include <string.h>
#define PROTA 5193
main()
{
int port;
struct sockaddr_in sad;
#ifdef WIN32
WSADATA wsaData;
WSAStartup(0x0101,&wsaData);
#endif
port = PROTA;
sad.sin_port = htons((u_short)port);
}编译能通过。链接的时候出现以下问题:
lint.obj : error LNK2001: unresolved external symbol _htons@4
clint.obj : error LNK2001: unresolved external symbol _WSAStartup@8
Debug/clint.exe : fatal error LNK1120: 2 unresolved externals 问题:
1 什么原因导致了这个错误
2 问下symbol _htons@4,_WSAStartup@8里的@4和@8是什么意思?(对这个确实不懂~~~)备注:1.文件是C文件。
2.用的是CONSOLE
环境 VC 6.0
源码:(照着计算机网络与因特网第26章摘抄的)#include <windows.h>
#include <winsock.h>#include <stdio.h>
#include <string.h>
#define PROTA 5193
main()
{
int port;
struct sockaddr_in sad;
#ifdef WIN32
WSADATA wsaData;
WSAStartup(0x0101,&wsaData);
#endif
port = PROTA;
sad.sin_port = htons((u_short)port);
}编译能通过。链接的时候出现以下问题:
lint.obj : error LNK2001: unresolved external symbol _htons@4
clint.obj : error LNK2001: unresolved external symbol _WSAStartup@8
Debug/clint.exe : fatal error LNK1120: 2 unresolved externals 问题:
1 什么原因导致了这个错误
2 问下symbol _htons@4,_WSAStartup@8里的@4和@8是什么意思?(对这个确实不懂~~~)备注:1.文件是C文件。
2.用的是CONSOLE
#pragma comment(lib, "ws2_32.lib")
link选项里面添加上Ws2_32.lib或者楼上老大的办法.
他是DLL的导出文件还是静态库了?还有symbol _htons@4,_WSAStartup@8里的@4和@8是什么意思?
2. 至于symbol _htons@4,_WSAStartup@8里面的那个符号是无意义的,这是c++的名字改编,系统随即加上的,目的是为了区分同名标识符(像函数的重载) 名字改编在C语言里面是没有的,只存在在c++里面。