我一直在努力解决这个问题,我决定寻求帮助。
我试图在我的项目中包含猫鼬,所以在我的 api_and_json.cpp 文件中我有:
extern "C"{
#include "mongoose/mongoose.h"
}
我的 cmake 文件目前如下所示:
cmake_minimum_required(VERSION 2.8)
include(ProcessorCount)
ProcessorCount(N)
if(NOT N EQUAL 0)
set(CTEST_BUILD_FLAGS -j${N})
set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
endif()
project(api_and_json)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
include_directories("${PROJECT_SOURCE_DIR}")
add_executable(api_and_json ${PROJECT_SOURCE_DIR}/api_and_json.cpp)
我已经尝试了一些排列,所以我把它剥离回原来的样子。
CMake 工作正常,但是当我尝试 make 我得到:
...
[ 50%] Linking CXX executable ../bin/api_and_json
CMakeFiles/api_and_json.dir/api_and_json.cpp.o: In function `ev_handler(mg_connection*, int, void*)':
api_and_json.cpp:(.text+0xa1): undefined reference to `mg_printf'
api_and_json.cpp:(.text+0xb7): undefined reference to `mg_printf_http_chunk'
api_and_json.cpp:(.text+0xcd): undefined reference to `mg_send_http_chunk'
CMakeFiles/api_and_json.dir/api_and_json.cpp.o: In function `main':
api_and_json.cpp:(.text+0x10c): undefined reference to `mg_mgr_init'
api_and_json.cpp:(.text+0x184): undefined reference to `mg_bind_opt'
api_and_json.cpp:(.text+0x1dc): undefined reference to `mg_set_protocol_http_websocket'
api_and_json.cpp:(.text+0x32b): undefined reference to `mg_mgr_poll'
collect2: error: ld returned 1 exit status
CMakeFiles/api_and_json.dir/build.make:94: recipe for target '../bin/api_and_json' failed
make[2]: *** [../bin/api_and_json] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/api_and_json.dir/all' failed
make[1]: *** [CMakeFiles/api_and_json.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
我确定我缺少一些简单的东西,任何帮助将不胜感激。
我在其他地方看过,包括: 什么是未定义的引用/未解决的外部符号错误,我该如何解决?
这个参考对我没有帮助,但拉玛的建议对我有帮助。