2013-02-28 161 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文件。