0

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 (i.e 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 ?

Neo
  • 141
  • 5
  • 16
  • 1
    My guess would be incompatible versions of boost, gcc and stdlibc++. Why are you on a compiler as old as gcc4.2? – us2012 Feb 28 '13 at 09:46
  • @us2012 - But the answer is obvious - he doesn't care (afraid to get lost?) to build a new compiler with libraries including boost. – SChepurin Feb 28 '13 at 09:55
  • @us2012: I am using Boost 1.53.0 and the release notes say that any gcc>=4.1 is fine. stdlibc++ is provided by my toolchain and it is also compatible with gcc 4.2, is there any other way I can check their compatability ? BTW I wrote a sample C program without using the Boost library and it compiled and worked fine on the target. – Neo Feb 28 '13 at 22:30
  • @us2012: I updated the problem statement with more information. – Neo Mar 01 '13 at 01:36

1 Answers1

0

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.

Community
  • 1
  • 1
Neo
  • 141
  • 5
  • 16