码迷,mamicode.com
首页 > Windows程序 > 详细

windows编译libevent时报告“缺少print_winsock_errors.obj”的解决

时间:2017-09-04 11:58:29      阅读:904      评论:0      收藏:0      [点我收藏+]

标签:height   initial   table   window   byte   caching   nop   include   ogre   

一、综述

Libevent 是一个用C语言编写的、轻量级的开源高性能事件通知库。

libevent官网(http://libevent.org)下载源码包,在Windows平台编译时,会报缺少“print_winsock_errors.obj”的错误。

 

二、原因及解决

经检查,这是因为源码包中缺少文件test/print_winsock_errors.c导致,原因未知。

解决方法:手工生成test/print_winsock_errors.c,以下为从git搜索到的代码内容:

#include <winsock2.h>
#include <windows.h>

#include <stdlib.h>
#include <stdio.h>

#include "event2/event.h"
#include "event2/util.h"
#include "event2/thread.h"

#define E(x) printf (#x " -> \"%s\"\n", evutil_socket_error_to_string (x));

int main (int argc, char **argv)
{
  int i, j;
  const char *s1, *s2;

#ifdef EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED
  evthread_use_windows_threads ();
#endif

  s1 = evutil_socket_error_to_string (WSAEINTR);

  for (i = 0; i < 3; i++) {
    printf ("\niteration %d:\n\n", i);
    E(WSAEINTR);
    E(WSAEACCES);
    E(WSAEFAULT);
    E(WSAEINVAL);
    E(WSAEMFILE);
    E(WSAEWOULDBLOCK);
    E(WSAEINPROGRESS);
    E(WSAEALREADY);
    E(WSAENOTSOCK);
    E(WSAEDESTADDRREQ);
    E(WSAEMSGSIZE);
    E(WSAEPROTOTYPE);
    E(WSAENOPROTOOPT);
    E(WSAEPROTONOSUPPORT);
    E(WSAESOCKTNOSUPPORT);
    E(WSAEOPNOTSUPP);
    E(WSAEPFNOSUPPORT);
    E(WSAEAFNOSUPPORT);
    E(WSAEADDRINUSE);
    E(WSAEADDRNOTAVAIL);
    E(WSAENETDOWN);
    E(WSAENETUNREACH);
    E(WSAENETRESET);
    E(WSAECONNABORTED);
    E(WSAECONNRESET);
    E(WSAENOBUFS);
    E(WSAEISCONN);
    E(WSAENOTCONN);
    E(WSAESHUTDOWN);
    E(WSAETIMEDOUT);
    E(WSAECONNREFUSED);
    E(WSAEHOSTDOWN);
    E(WSAEHOSTUNREACH);
    E(WSAEPROCLIM);
    E(WSASYSNOTREADY);
    E(WSAVERNOTSUPPORTED);
    E(WSANOTINITIALISED);
    E(WSAEDISCON);
    E(WSATYPE_NOT_FOUND);
    E(WSAHOST_NOT_FOUND);
    E(WSATRY_AGAIN);
    E(WSANO_RECOVERY);
    E(WSANO_DATA);
    E(0xdeadbeef); /* test the case where no message is available */

    /* fill up the hash table a bit to make sure it grows properly */
    for (j = 0; j < 50; j++) {
      int err;
      evutil_secure_rng_get_bytes(&err, sizeof(err));
      evutil_socket_error_to_string(err);
    }
  }

  s2 = evutil_socket_error_to_string (WSAEINTR);
  if (s1 != s2)
    printf ("caching failed!\n");

  libevent_global_shutdown ();

  return EXIT_SUCCESS;
}

然后使用VS命令提示工具,在libevent解压目录下执行:nmake /f Makefile.nmake,编译顺利通过。

 

三、其它

经检查,在官网列出的1.4.x-stable, 2.0.x-stable, 2.1.x-stable等版本中貌似均存在此问题。

print_winsock_errors.c只有一段测试代码,没有也关系不大,因此另一种解决方法是:修改CmakeFileList,从中删除与print_winsock_errors有关的内容。

windows编译libevent时报告“缺少print_winsock_errors.obj”的解决

标签:height   initial   table   window   byte   caching   nop   include   ogre   

原文地址:http://www.cnblogs.com/wggj/p/7472607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!