vc 上的 socket 实现 c/s 间的通信,采用 c 代码,编译通过;
但再将代码移到 eclipse 上,却出现 n 多问题:
1、#pragma comment(lib,"ws2_32.lib") [使用 vc
通信常用的连接库加载语句]
*****warning: ignoring #pragma comment [-Wunknown-pragmas]
ld.exe cannot find -l WS2_32.Lib
或者是 一大堆的如下东东
*****
tmp/ccxABKPU.o:coco.c:(.text+0x2f): undefined reference to `_send@16' /tmp/ccxABKPU.o:coco.c:(.text+0x78): undefined reference to `_WSAStartup@8' /tmp/ccxABKPU.o:coco.c:(.text+0x89): undefined reference to `_socket@12' 。。。
原因:eclipse 不支持 ws2_32.lib 这个库,(支持 pragma 语句否?)
解决方法:采用 eclipse 安装目录 lib\中自带的 libws2_32.a 静态库,
即在项目名右键--》properties-->>c/c++ build-->>tool settings-->>mingw c linker -->>libraries
在右侧 libraries(-l)点+添加“ws2_32”即可;
2、#include
****
使用 mysql 的 API 链接时出错,undefined reference to mysql_init@4
....
原因:不明;但有解决方法如下:
1)考虑头文件包含:将 mysql.h 的头文件所在的目录加入 eclipse 的包含路径中
即在项目名右键--》properties-->>c/c++ build-->>tool settings-->>gcc c compiler-->>includes, 在右 侧同上,添加完整目录;
2)若还是出现链接问题,那就这样:
eclipse 对于 lib 库上链接有点问题(具体?),可以将.lib 转换为.a 的静态库,在包含到 eclipse 中(同上)。
3、如何将把库文件从 msvc 格式(.lib)转化成 MinGW 格式(.a)的方法
工具:DEV-C++ 、 mingw-utils(主要是使用它自带的 Reimp 工具);
代码:进入 cmd 下 cd c:\mysql\lib\opt(先切换到 自个安装的目录)
Reimp -d
libmysql.lib ==》生成 libmysql.def 文件
Dlltool --input-def 生成 libmysql.a 文件;
libmySQL.def --dllname libmySQL.dll --output-lib libmySQL.a -k ==》
具体讲解可以参考:cnblogs/top5/archive/2011/02/18/1958093.html
4、libxml 问题 这家伙问题还真不是一般的多: 1)头文件路径包含,这是必须的; 2)***** undefined reference to '_imp_xmlFree' undefined .... .... 原因:貌似和第二个问题一样,库的链接出了问题(?) 解决: ‘xmlParseFile’
<1>生成.lib 到.a 的文件; <2>关于 imp_xmlFree 的问题:
方法:修改 xmlexports.h。。。 即先将 这段注释掉,改为: #if defined(_WIN32) &;&; defined(__MINGW32__) #define XMLPUBFUN #ifdef __cplusplus #define XMLPUBVAR extern #else #define XMLPUBVAR #endif #if !defined _REENTRANT #define _REENTRANT #endif #endif 不过我在编译时,总是出现: ***** C:\Program Files\libxml2-2.6.22.win32\include/libxml/xmlexports.h:140:0: warning: "XMLPUBVAR" redefined [enabled by default] C:\Program Files\libxml2-2.6.22.win32\include/libxml/xmlexports.h:36:0: note: this is the location of the previous definition 。。。
所以我习惯在加一句
:
#undef XMLPUBVAR 在第二行。