DEV C++的问题,超高难度,非高手勿进!!

bit7 2003-03-24 11:47:47
欲在DEV C++中使用lib文件,使用#pragma comment(lib,"libws2_32.a")
libws2_32.a文件存放于DEV C++ 安装目录的lib文件夹中,但编译提示没有定义WSAStartup()函数的入口地址,原因何在?
原代码如下:
//---------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <windows.h>
#include <iostream>
//using namespace std;
#pragma comment(lib,"libws2_32.a")

int main(int argc, char *argv[])
{
WSADATA wsv ;
int r = WSAStartup(0x0200,&wsv);
if (r!=0)
{
printf("Windows socket startup success!");
exit(0);
}
printf("%.2x%.2x",wsv.wVersion,wsv.wHighVersion);
system("PAUSE");
return 0;
}
...全文
138 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bit7 2003-04-11
  • 打赏
  • 举报
回复
thanks!
ckacka 2003-03-30
  • 打赏
  • 举报
回复
先摘两段话,你看看

MSDN:

Pragmas are machine- or operating system-specific by definition, and are
usually different for every compiler.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~注意这里


Dev-C++ Help:

A little history :
Library filenames under the GNU system are in the form libNAME.a (with NAME the name of the library, like wsock32).
Thus if for example you want to use the wsock32 (winsock) library, the filename will be libwsock32.a
The GCC parameter for linking a library is -INAME, so for linking with the wsock32 library we would give GCC the -Iwsock32 parameter.

Linking your library :

Click on Project menu then on Options. Now click on the Parameters sheet.
In the Linker edit box, you can specify as many libraries as you need. You can also pass the complete filename of the library.
Example : -lwx -Im -Iwsock32 c:\libs\mylib.a c:\objs\myobj.o

You may also use the Add Library or Object button to select your library from a list.


明白了么?这段帮助的出处是在你的帮助里面的 Dev-C++5 -> Basic steps -> Managing Project Options -> Linking libraries with your project
^_^
bit7 2003-03-24
  • 打赏
  • 举报
回复
我手头上没有关于devcpp的手册,它支持这个预编译指令吗?
bit7 2003-03-24
  • 打赏
  • 举报
回复
windows系统
EricHxy 2003-03-24
  • 打赏
  • 举报
回复
什么操作系统?
试试把库文件的完整路径加上。
bit7 2003-03-24
  • 打赏
  • 举报
回复
在dev-cpp中是这样的
rickfeng 2003-03-24
  • 打赏
  • 举报
回复
应该是这样的吧:

#pragma comment ( lib, "ws2_32.lib" )
ckacka 2003-03-24
  • 打赏
  • 举报
回复
支持#pragma
不支持comment

在工程里面添加

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧