【问题标题】:Libevent 2.0.22 project Compilation problems (OSX)Libevent 2.0.22 项目编译问题(OSX)
【发布时间】:2015-06-22 07:10:56
【问题描述】:

我想编译上面的示例代码,但出现以下错误。 这是什么原因。 “OSX - /usr/local”下安装的所有文件

// libevent2 library
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <evhttp.h>
#include <event2/event.h>
#include <event2/http.h>
#include <event2/bufferevent.h>

void generic_handler(struct evhttp_request *req, void *arg) {
    struct evbuffer *buffer;
    buffer = evbuffer_new();

    if (buffer == NULL) {
        err(1, "failed to create response buffer");
    }

    evbuffer_add_printf(buffer, "Requested: %sn", evhttp_request_uri(req));
    evhttp_send_reply(req, HTTP_OK, "OK", buffer);
}

int main(int argc, char **argv) {
    struct evhttp *httpd;
    event_init();
    httpd = evhttp_start("0.0.0.0", 8080);
    // Set a callback for requests to "/specific".
    // evhttp_set_cb(httpd, "/specific", another_handler, NULL);
    // Set a callback for all other requests.
    evhttp_set_gencb(httpd, generic_handler, NULL);
    // Not reached in this code as it is now.
    event_dispatch();
    evhttp_free(httpd);
    return 0;
}

错误:

/Users/batuhangoksu/Desktop/test.c:14:10: fatal error: 'evhttp.h' file not found
#include <evhttp.h>
                 ^
1 error generated.

命令:

gcc -o octopus /Users/batuhangoksu/Desktop/test.c -levent -lpthread

【问题讨论】:

    标签: c libevent


    【解决方案1】:

    首先,请找到evhttp.h文件中的path

    然后,您可以通过命令检查此path 是否在#include 文件搜索路径列表中

    gcc -o octopus /Users/batuhangoksu/Desktop/test.c -levent -lpthread -v
    

    输出是这样的,

    #include "..." search starts here:
    #include <...> search starts here:
     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/include
     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
     /usr/include
     /System/Library/Frameworks (framework directory)
     /Library/Frameworks (framework directory)
    

    如果path不在搜索列表中,则将-I /missed_include(假设它是path)添加到您的命令中,例如

    gcc -o 章鱼 /Users/batuhangoksu/Desktop/test.c -levent -lpthread -I /missed_include

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-25
      相关资源
      最近更新 更多