zoukankan      html  css  js  c++  java
  • Clion 引入libevent Undefined symbols for architecture x86_64: "

    CLion 引入libevent出现

    Undefined symbols for architecture x86_64:
      "_evbuffer_add_printf", referenced from:
          httpHandler(evhttp_request*, void*) in main.cpp.o
      "_evbuffer_free", referenced from:
          httpHandler(evhttp_request*, void*) in main.cpp.o
      "_evbuffer_new", referenced from:
          httpHandler(evhttp_request*, void*) in main.cpp.o
      "_event_base_dispatch", referenced from:
          _main in main.cpp.o
      "_event_base_free", referenced from:
          _main in main.cpp.o
      "_event_base_new", referenced from:
          _main in main.cpp.o
      "_evhttp_bind_socket", referenced from:
          _main in main.cpp.o
      "_evhttp_free", referenced from:
          _main in main.cpp.o
      "_evhttp_new", referenced from:
          _main in main.cpp.o
      "_evhttp_request_get_command", referenced from:
          httpHandler(evhttp_request*, void*) in main.cpp.o
      "_evhttp_request_get_host", referenced from:
          httpHandler(evhttp_request*, void*) in main.cpp.o
      "_evhttp_request_get_uri", referenced from:
          httpHandler(evhttp_request*, void*) in main.cpp.o
      "_evhttp_send_reply", referenced from:
          httpHandler(evhttp_request*, void*) in main.cpp.o
      "_evhttp_set_gencb", referenced from:
          _main in main.cpp.o
    ld: symbol(s) not found for architecture x86_64
    collect2: error: ld returned 1 exit status
    make[3]: *** [learn_libevent] Error 1
    make[2]: *** [CMakeFiles/learn_libevent.dir/all] Error 2
    make[1]: *** [CMakeFiles/learn_libevent.dir/rule] Error 2
    make: *** [learn_libevent] Error 2
    
    

    该问题是CMakeLists.txt导致的问题
    在CMakeLists添加下述配置

    # add extra include directories
    include_directories(/usr/local/Cellar/libevent/2.1.11_1/include)
    # add extra lib directories
    link_directories(/usr/local/Cellar/libevent/2.1.11_1/lib)
    

    在最后添加

    target_link_libraries(learn_libevent event)
    

    一定要加 上述的配置,不然引入第三方库会出现错误,同时注意好顺序。

    完整配置

    cmake_minimum_required(VERSION 3.8)
    project(learn_libevent)
    
    set(CMAKE_CXX_STANDARD 11)
    
    set(SOURCE_FILES main.cpp)
    
    # add extra include directories
    include_directories(/usr/local/Cellar/libevent/2.1.11_1/include)
    # add extra lib directories
    link_directories(/usr/local/Cellar/libevent/2.1.11_1/lib)
    
    
    
    
    add_executable(learn_libevent ${SOURCE_FILES})
    
    target_link_libraries(learn_libevent event)
    
    
  • 相关阅读:
    JavaScript系列:JavaScript简介
    Fit自适应布局
    JavaScript数值类型及变量
    表格列Column
    JavaScript系列:ECMAScript引用类型
    Absolute绝对定位
    JavaScript系列:ECMAScript运算符
    JavaScript系列:ECMAScript类型转换
    jQuery Uploadify在ASP.NET MVC3中的使用
    JavaScript系列:ECMAScript语句
  • 原文地址:https://www.cnblogs.com/outxiao/p/13590834.html
Copyright © 2011-2022 走看看