2011-12-25 30 views
1

當我嘗試編譯我的程序make時,我得到一個未定義的對主錯誤的引用。然而,主要存在於我的src目錄中,我對我做錯了什麼感到失落。CMake undefined引用主

我假定add_executable([title] [source])是用來將源文件添加到編譯中的命令。

基於CMake的教程

cmake_minimum_required(VERSION 2.6) 
project(opengl_02) 
add_executable(opengl_02 opengl_02.cpp) 
add_executable(main main.cpp) 
add_executable(geometrics geometrics.cpp) 
set (opengl_02_version_major 1) 
set (openfl_02_version_minor 0) 

#configure the header file to pass some of the CMake settings 
#to the source code 

configure_file(
    "${PROJECT_SOURCE_DIR}/opengl_02_config.h.in" 
    "${PROJECT_BINARY_DIR}/opengl_02_config.h" 
    ) 

#add the binary tree to the search path for include files 
#so that it will find tutorialconfig.h 

include_directories("{PROJECT_BINARY_DIR}") 

add_executable(opengl_02_config opengl_02_config.cpp) 

問題

爲什麼我的主文件沒有得到引用?

回答

4

int main (int argc, char *argv[])(或其沒有參數的等價物)必須存在於每個程序中。很難說在沒有查看源代碼的情況下你的設置有什麼問題,但是我有一種感覺,那就是你試圖編譯成可執行文件的每個文件都不存在main函數,即opengl_02.cpp,geometrics.cppmain.cpp。如果您確實想創建三個可執行文件,則main函數應該出現在您的示例中的所有三個源文件中。如果要從三個源文件創建可執行文件,則必須將其全部指定爲一個可執行文件,如add_executable(main main.cpp opengl_02.cpp geometrics.cpp)。希望能幫助到你。

+0

最後一點是我需要的。謝謝,+1 – zeboidlund 2011-12-25 05:40:34