2013-02-28 155 views
0

我最近爲PowerPC交叉編譯Boost庫並生成線程和系統庫。然後來測試我的目標庫,試圖Boost庫示例代碼中的一個,並試圖使用先前內置升壓庫來構建二進制,但得到下面的編譯錯誤C++使用Boost庫編譯失敗

. 
. 
GNU C++ version 4.2.2 (powerpc-linux) 
compiled by GNU C version 2.96 20000731 (Red Hat Linux 7.3 2.96-113). 
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128176 
Compiler executable checksum: dd5a9a41381fa3b9978b2738b80f5a75 
In file included from /shared/deps/powerpc/include/boost/config/platform/linux.hpp:15, 
      from /shared/deps/powerpc/include/boost/config.hpp:53, 
      from /shared/deps/powerpc/include/boost/thread/detail/platform.hpp:14, 
      from /shared/deps/powerpc/include/boost/thread/thread.hpp:12, 
      from helloworld.cpp:7: 
4.2.2/cstdlib:106: error: '::div_t' has not been declared 
4.2.2/cstdlib:107: error: '::ldiv_t' has not been declared 
4.2.2/cstdlib:109: error: '::abort' has not been declared 
4.2.2/cstdlib:110: error: '::abs' has not been declared 
4.2.2/cstdlib:111: error: '::atexit' has not been declared 
4.2.2/cstdlib:112: error: '::atof' has not been declared 
4.2.2/cstdlib:113: error: '::atoi' has not been declared 
. 
. 

下面是一個給定的樣本程序Boost庫

#include <boost/thread/thread.hpp> 
#include <iostream> 

void helloworld() 
{ 
    std::cout << "Hello World!" << std::endl; 
} 

int main() 
{ 
    boost::thread thrd(&helloworld); 
    thrd.join(); 
} 

Make文件:

CC=ppc_4xx-gcc 
CPP=ppc_4xx-g++ 
CFLAGS=-c -g -Wall -static -v 
LDFLAGS_TARGET=-$(LDFLAGS_PowerPC) 
LIBS_TARGET=$(LIBS_PowerPC) 
CPPFLAGS=$(CPPFLAGS_COMMON) $(CPPFLAGS_PowerPC) 
INCLUDES=-I/opt/ELDK/4.2/ppc_4xx/usr/include/ -I. -I/opt/ELDK/4.2/ppc_4xx/usr/src/u-boot-1.3.1/board/xilinx/common/ -I/opt/ELDK/4.2/ppc_4xx/usr/src/linux-2.6.24/arch/powerpc/boot/ -I4.2.2/ 

DEPSROOT=/shared/deps 
COMMON_INCLUDES = $(DEPSROOT)/common/include 
PowerPC_INCLUDES=$(DEPSROOT)/powerpc/include 
CPPFLAGS_PowerPC=-I$(PowerPC_INCLUDES) 
CPPFLAGS_COMMON = -I$(COMMON_INCLUDES) 
PowerPC_LIBS=$(DEPSROOT)/powerpc/lib 
LDFLAGS_PowerPC=-L$(PowerPC_LIBS) 
LIBS_PowerPC=-lboost_thread -lboost_system 

all: helloworld 

helloworld: helloworld.o 
$(CPP) -g helloWorld.o -o helloworld -static 

helloworld.o: helloworld.cpp 
$(CPP) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $(MODS) helloworld.cpp 

clean: 
rm -rf *.o helloWorld 

的錯誤是在文件cstdlib在下面的位置

. 
. 
_GLIBCXX_BEGIN_NAMESPACE(std) 

using ::div_t; 
using ::ldiv_t; 
using ::abort; 
. 
. 

宏_GLIBCXX_BEGIN_NAMESPACE將名稱空間設置爲std,並具有一定的可見性。我對此很陌生,所以無法完全遵循。

有沒有人遇到過類似的問題?我在一些帖子中讀到名稱空間丟失導致此錯誤,但我不確定這是否是我的情況中的問題。


編輯 我對這個問題的更多信息。首先,我認爲問題出在命名空間上,所以我手動將名稱空間更改爲std,但沒有幫助。然後我使用:: div_t在語句之前添加了結構div_t的定義;,其中一個錯誤減少了(即語句被編譯)。所以問題在於div_t結構缺少定義。

現在,結構div_t在文件stdlib.h中定義,該文件包含在當前文件cstdlib中。當我做文件名stdlib.h中一個定位,我發現下面引用

/opt/ELDK/4.2/ppc_4xx/usr/include/stdlib.h 
/opt/ELDK/4.2/ppc_4xx/usr/include/bits/stdlib.h 
/opt/ELDK/4.2/ppc_4xx/usr/include/c++/4.2.2/tr1/stdlib.h 
/opt/ELDK/4.2/ppc_4xx/usr/include/freetype2/freetype/config/ftstdlib.h 
/opt/ELDK/4.2/ppc_4xx/usr/src/linux-2.6.24/arch/powerpc/boot/stdlib.h 
/opt/ELDK/4.2/ppc_4xx/usr/src/linux-2.6.24-xenomai/arch/powerpc/boot/stdlib.h 

只有第一個文件具有div_t的兩個定義,而不是其他人。正在討論的文件cstdlib位於../include/c++/4.2.2/文件夾中,現在如果文件stdlib.h包含在此處,那麼包含多個stdlib.h中的哪一個?位置/opt/ELDK/4.2/ppc_4xx/usr/include出現在我的包含路徑中。

順便說一句如何知道哪個文件被包含?

+1

我的猜測是boost,gcc和stdlibC++的不兼容版本。爲什麼你使用的編譯器和gcc4.2一樣久? – us2012 2013-02-28 09:46:01

+0

@ us2012 - 但答案顯而易見 - 他不在乎(害怕迷路?)來構建一個包含boost的庫的新編譯器。 – SChepurin 2013-02-28 09:55:34

+0

@ us2012:我使用的是Boost 1.53.0,發行說明表示任何gcc> = 4.1都可以。 stdlibC++由我的工具鏈提供,它也與gcc 4.2兼容,有沒有其他方法可以檢查它們的兼容性?順便說一句,我寫了一個示例C程序,而不使用Boost庫,它編譯並在目標上正常工作。 – Neo 2013-02-28 22:30:38

回答

0

問題與Cross Compile Boost library for PowerPC architecture相同。具有dev_t定義的包含路徑被省略,並且使用下一個包含路徑。不幸的是,它也有一個stdlib.h文件,它沒有dev_t結構的定義。我創建了軟鏈接並確保編譯器獲取了正確的stdlib.h文件。