简体   繁体   中英

C++ Compilation failure with Boost library

I recently cross compiled Boost library for PowerPC and generated the thread and system library. Then to test the library on my target, tried one of the sample code in Boost library and tried to build the binary using the previously built boost library but got the below compilation errors

.
.
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
.
.

Below is the sample program given with Boost library

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

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

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

Make file:

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

The error is in the file cstdlib in the below location

.
.
_GLIBCXX_BEGIN_NAMESPACE(std)

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

The macro _GLIBCXX_BEGIN_NAMESPACE is setting the namespace as std with certain visibility. I am new to this so couldn't follow it completely.

Has anyone faced similar problem ? I read in some posts that the namespace is missing causing this error but I am not sure if that's the issue in my case.


EDIT I got more information on the problem. First I thought the problem was with the namespace, so I manually changed the namespace to std but it didn't help. Then I added the definition of the structure div_t just before the statement using ::div_t; and one of the errors decreased (ie the statement was compiled). So the problem was with the missing definition of div_t structure.

Now the structure div_t is defined in the file stdlib.h which is included in the current file cstdlib. When I did a locate on the file name stdlib.h, I found the below references

/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

Only the first file has the definition of div_t and not the others. The file under discussion cstdlib is in the folder ../include/c++/4.2.2/, now if the file stdlib.h is included here which one of the multiple stdlib.h is included ? The location /opt/ELDK/4.2/ppc_4xx/usr/include is present in my include path.

BTW how do I know which file is being included ?

The problem was the same as Cross Compile Boost library for PowerPC architecture . The include path which had the definition of dev_t was omitted and the next include path was used. Unfortunately it also had a file stdlib.h which didn't have the definition of dev_t structure. I created soft links and made sure the compiler picked up the correct stdlib.h file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM