2011-11-03 169 views
1

在Code :: Blocks中編程時,它可以很好地編譯C語言,但不適用於C++。即使是一個「Hello World」程序:C++程序不能在Code :: Blocks中運行

#include <iostream> 

using namespace std; 

int main() 
{ 
    cout << "Hello world!" << endl; 
    return 0; 
} 

它給了這些錯誤:

-------------- Build: Debug in project --------------- 

    Compiling: main.cpp 
    Linking console executable: bin\Debug\project.exe 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_throw.o):eh_throw.cc:(.text+0x7b): undefined reference to `__w32_sharedptr_unexpected' 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_throw.o):eh_throw.cc:(.text+0x8c): undefined reference to `__w32_sharedptr_terminate' 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x4e): undefined reference to `__w32_sharedptr' 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0xb9): undefined reference to `__w32_sharedptr' 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x179): undefined reference to `__w32_sharedptr' 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x186): undefined reference to `__w32_sharedptr' 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x1e3): undefined reference to `__w32_sharedptr' 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_globals.o):eh_globals.cc:(.text+0x1ef): more undefined references to `__w32_sharedptr' follow 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0x67): undefined reference to `__w32_sharedptr_terminate' 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0x97): undefined reference to `__w32_sharedptr_unexpected' 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0xb3): undefined reference to `__w32_sharedptr_terminate' 
    C:\Program Files (x86)\CodeBlocks\MinGW\lib/libstdc++.a(eh_terminate.o):eh_terminate.cc:(.text+0xd3): undefined reference to `__w32_sharedptr_unexpected' 
    collect2: ld returned 1 exit status 
    Process terminated with status 1 (0 minutes, 1 seconds) 
    12 errors, 0 warnings 
+0

請上傳您所使用的代碼。 –

+0

請張貼一些源代碼。 –

+1

#include using namespace std; int main() { cout <<「Hello world!」 << endl; return 0; } –

回答

4

你得到的錯誤表示連接是有問題的定位__w32_sharedptr這可能是一個依賴的libstdC++需求上班。

正常情況下,標準庫及其所需的任何依賴關係在構建項目時會自動關聯。然而,正如trojanfoe的評論所指出的,這隻有在你用g ++編譯時纔是正確的。如果您使用gcc構建C++代碼,那麼C++標準庫不會自動包含,因爲gcc驅動程序認爲它正在編譯C代碼。

爲了驗證什麼實際發生在你的代碼塊的設置去設置 - >編譯器和調試器 - >全局編譯器設置(左側) - >下工具鏈的可執行文件標籤。您應該看到類似這樣的東西:

enter image description here

如果你的設置是正確的,但仍然不肯建設好,使完整的編譯器記錄和查看命令實際上是由IDE調用什麼。你可以在下找到這個全局編譯器設置 - >其他設置 tab->編譯器日誌=完整的命令行。請注意,您可能需要向右滾動一下以查找選項卡。

啓用完整日誌記錄後,再次重建項目並使用所用命令更新您的問題。

這大約是你應該在日誌窗口中看到的,當你使用以上選項重建開啓:

enter image description here

+1

我的設置看起來正確,因爲你有指導。它曾經工作過,但在我的代碼塊中安裝SDL庫之後,該程序給了我這種麻煩。是否因爲SDL Library ..? –

+0

@PrajwalAcharya你是否在這種情況下啓用了完整的日誌記錄?當您嘗試構建時,日誌窗口會顯示什麼內容?當您啓用完整日誌記錄時,用於構建的完整命令行將顯示在那裏。 – greatwolf

+1

這次登錄窗口也顯示與上面相同.. ??將重新安裝codeblocks解決這個.. ??我也可以重新安裝SDL Library .. !!! –