2012-11-28 34 views
0

編譯時,C++項目,未定義的參考`atexit對」

我得到了這樣的錯誤:

/usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/crt1.o: In function `_start': 
(.text+0xc): undefined reference to `__libc_csu_fini' 
/usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/crt1.o: In function `_start': 
(.text+0x11): undefined reference to `__libc_csu_init' 

....: undefined reference to `atexit' 
collect2: error: ld returned 1 exit status 

這是代碼:

的std ::的atexit(myExitFunction) ;

myExitFunction已經聲明好。爲什麼會抱怨atexit?

在此先感謝。

+2

你能編輯和添加有關此問題的詳細代碼嗎? – Vargan

+0

是的,我更新了更多的錯誤細節 – olidev

+0

我不知道你是否有代碼模板在你的項目中,但也許這可以幫助你:http://ubuntuforums.org/showthread.php?t=1388438 – Vargan

回答

0

這是一個鏈接錯誤消息。編譯器成功找到聲明std::atexit(),但鏈接程序找不到此函數的任何編譯的定義

嘗試加入這一論點鏈接器鏈接代碼:

-stdlib=libc++ 
+0

我想我得問你另外一個問題。我正在使用cmake來編譯我的C++項目。我對它很新。我應該在哪裏提出這個論點?提前致謝 – olidev

+0

我設法使用:set(CMAKE_CXX_FLAGS_INIT「-Wall -stdlib = libC++」),但問題仍然存在 – olidev

+1

我不是'cmake'的普通用戶,但根據[郵件列表上的一篇文章]( http://www.cmake.org/pipermail/cmake/2006-October/011517.html),您還應該設置「CMAKE_EXE_LINKER_FLAGS」。 –