2017-04-18 100 views
-1

我一直在努力解決這個問題,我決定尋求幫助。CMake未定義的引用'mg_printf'

我想在自己的項目貓鼬,所以在我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的工作正常,但是當我嘗試讓我得到:

... 
[ 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 

我敢肯定,我失去了一些東西簡單,任何幫助將不勝感激。

我看着別處,包括: What is an undefined reference/unresolved external symbol error and how do I fix it?

此引用並沒有幫助我,但拉瑪的建議一樣。

+2

你不鏈接到的資料庫,即你錯過了'target_link_libraries'的【什麼是未定義參考/解析的外部 –

+1

可能的複製符號錯誤和我如何解決它?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-doi-i-fix ) – Olaf

回答

1

你忘了鏈接到貓鼬。 你CmakeList.txt的末尾添加這一行:

target_link_libraries (api_and_json mongoose) 
+0

這是正確的答案......爲什麼它有-1? – Gianni