0

我已经编写了一个扩展的 pythonwinxp脚本mingw+msys。它将调用libeventlib。我希望用户不要安装更多的库,所以我想静态编译它,但是有错误。以下是我的编译和安装过程libevent

​./configure -prefix=D:/libevent -enable-static
make
make install  

我写了两个makefile,我得到了同样的错误。

libevent.a(buffer.o):In function 'evbuffer_read':undefined reference to 'WSARecv@28' 
libevent.a(buffer.o):In function 'evbuffer_write_iovec':undefined reference to 'WSASend@28' 
........................

以下是生成文件:

生成文件 1

HEAD_PATH_FLAGS=-IC:/Python27/include -ID:/boost/include/boost-1_52 -ID:/libevent/include
LIB_PATH_FLAGS=-LD:/boost/lib -LD:/libevent/lib -LC:/Python27/libs
LIB_FLAGS=-lboost_python-mgw46-s-1_52 -Wl,Bstatic -levent -Wl,Bdynamic -lpython27 -lwsock32
SOURCE=test.o 
all:${SOURCE}
g++ ${HEAD_PATH_FLAGS} ${SOURCE} ${LIB_PATH_FLAG} ${LIB_FLAGS} -fPIC -shared -o test.dll

生成文件 2

HEAD_PATH_FLAGS=-IC:/Python27/include -ID:/boost/include/boost-1_52 -ID:/libevent/include
LIB_PATH_FLAGS=-LD:/boost/lib -LD:/libevent/lib -LC:/Python27/libs
LIB_FLAGS=-lboost_python-mgw46-s-1_52 -lpython27 -lwsock32
SOURCE=test.o D:/libevent/lib/libevent.a
all:${SOURCE}
g++ ${HEAD_PATH_FLAGS} ${SOURCE} ${LIB_PATH_FLAG} ${LIB_FLAGS} -fPIC -shared -o test.dll

为什么会这样?我怎样才能让它编译没有错误?

4

1 回答 1

4

您应该链接到libws2_32.a, asWSASendWSARecv在那里定义。添加-lws2_32到您的链接器命令。

于 2013-01-11T19:40:54.133 回答