Page 1 of 1

[Newlib] Problem with compilation (headers)

Posted: Fri Dec 30, 2011 12:03 pm
by fiveayem
Hello,

I am currently trying to port dash for my OS, and I am stuck with the following compilation error :

Code: Select all

In file included from /usr/include/sys/stat.h:107,
                 from /usr/include/fcntl.h:38,
                 from mkinit.c:50:
/usr/include/bits/stat.h:117: error: redefinition of ‘struct stat’
In file included from /usr/include/fcntl.h:38,
                 from mkinit.c:50:
/usr/include/sys/stat.h:502: error: redefinition of ‘stat’
/usr/include/sys/stat.h:453: note: previous definition of ‘stat’ was here
/usr/include/sys/stat.h:509: error: redefinition of ‘lstat’
/usr/include/sys/stat.h:460: note: previous definition of ‘lstat’ was here
/usr/include/sys/stat.h:516: error: redefinition of ‘fstat’
/usr/include/sys/stat.h:467: note: previous definition of ‘fstat’ was here
In file included from /usr/include/fcntl.h:205,
                 from mkinit.c:50:
/usr/include/bits/fcntl2.h:74: error: redefinition of ‘open’
/usr/include/bits/fcntl2.h:42: note: previous definition of ‘open’ was here
It seems there are two problems :
  • the headers the compiler uses do not seem to be the good ones (they are located in "/usr/include" and not in "/usr/local/cross/i586-pc-myos/include") ;
  • multiple definitions of structs and functions.
Maybe both problems are linked, I do not know...

However, when I compile my own programs with my OS specific compiler (i586-pc-myos-gcc), it does use the headers in "/usr/local/cross/i586-pc-myos/include".

I have made some changes in the shell.h file, replacing '#define JOBS 1' by '#define JOBS 0' and '#define BSD 1' by '#define BSD 0'.

The PATH environment is set properly, and I can see that the compiler used to build is the good one. I configured in the following way before building (in dash-0.5.7 directory) :

Code: Select all

./configure --host=i586-pc-myos --prefix=/usr/local/cross/dash
Thanks for your help.

EDIT : I have also set the JOBS variable to 0 in "builtins.def.in".

Re: [Newlib] Problem with compilation (headers)

Posted: Fri Dec 30, 2011 12:30 pm
by bluemoon
Try this:

Code: Select all

./configure --help
A well written configure script support things like --target and/or sysroot, etc. If none you may need to port the build scripts too.

Re: [Newlib] Problem with compilation (headers)

Posted: Fri Dec 30, 2011 3:21 pm
by gerryg400
Which C compiler is it executing ? If it's executing your cross-compiler and your cross-compiler is including the host files then it's broken. If it's executing the host GCC then dash configure didn't run correctly.

When you port software to your OS, especially something simple like dash you should be able to read through the configure output and check that it is as you expected, that it found and tested your toolchain and found all your headers. Those configure scripts are a very good test of your tools. Dash is good practice because its configure is simple.

Also, you should be able to get dash to configure and make with absolutely no modifications to dash at all. By all means disable features or comment out problem pieces while you are playing with it but you should find that it compiles and runs in the end with no changes.

[Added] IIRC the

Code: Select all

--prefix=/usr/local/cross/dash
is only used for the

Code: Select all

make install
step so the only thing you need to pass to configure is your host, so your configure looks correct.

Re: [Newlib] Problem with compilation (headers)

Posted: Fri Dec 30, 2011 4:06 pm
by fiveayem
Here is the configure output :

Code: Select all

configure: WARNING: if you wanted to set the --build type, don't use --host.
    If a cross compiler is detected then cross compile mode will be used
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for i586-pc-myos-strip... i586-pc-myos-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for i586-pc-myos-gcc... i586-pc-myos-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether i586-pc-myos-gcc accepts -g... yes
checking for i586-pc-myos-gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of i586-pc-myos-gcc... gcc3
checking how to run the C preprocessor... i586-pc-myos-gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... no
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for bison... no
checking for byacc... no
checking for build system compiler... cc
checking for __attribute__((__alias__()))... yes
checking alloca.h usability... yes
checking alloca.h presence... yes
checking for alloca.h... yes
checking paths.h usability... yes
checking paths.h presence... yes
checking for paths.h... yes
checking whether _PATH_BSHELL is declared... yes
checking whether _PATH_DEVNULL is declared... no
checking whether _PATH_TTY is declared... no
checking whether isblank is declared... yes
checking size of intmax_t... 8
checking size of long long int... 8
checking whether PRIdMAX is declared... yes
checking for bsearch... yes
checking for faccessat... no
checking for getpwnam... no
checking for getrlimit... no
checking for imaxdiv... no
checking for isalpha... yes
checking for killpg... no
checking for mempcpy... yes
checking for sigsetmask... no
checking for stpcpy... yes
checking for strchrnul... yes
checking for strsignal... yes
checking for strtod... yes
checking for strtoimax... no
checking for strtoumax... no
checking for sysconf... no
checking for signal... yes
checking for stat64... no
checking for open64... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating config.h
config.status: executing depfiles commands
The cross-compiler is executed. Normally, it should include the headers from "/usr/local/cross/i586-pc-myos/include" (I wrote some test programs and the headers were included from this directory when compiling, I checked it). But even with "--includedir=/usr/local/cross/i586-pc-myos/include" option passed to the configure script, I still get the same error.

Re: [Newlib] Problem with compilation (headers)

Posted: Fri Dec 30, 2011 4:43 pm
by gerryg400
Config looks okay, please attach the make output as well.

[EDIT] I think you didn't supply --with-sysroot when you built binutils and gcc. I do it like this

Code: Select all

cd binutils-build
../binutils-$BINUTILS_VER/configure --target=$TARGET --prefix=$PREFIX --with-sysroot=$PREFIX
make all
make install
cd ..
cd gcc-build
../gcc-$GCC_VER/configure --target=$TARGET --prefix=$PREFIX --disable-nls --disable-libssp --enable-languages=c,c++ --with-newlib --with-sysroot=$PREFIX 
make all-gcc
make install-gcc
make all-target-libgcc
make install-target-libgcc
cd ..
cd newlib-build
../newlib-$NEWLIB_VER/configure --target=$TARGET --prefix=$PREFIX
make all
make install
cd ..
cd dash
./configure --host=$TARGET --prefix=$PREFIX
make
make install
cd ..
The result is a tree, rooted at $PREFIX that contains bin, etc, src and usr directories. The tree contains my 'OS' and tools with all its installed apps.

Re: [Newlib] Problem with compilation (headers)

Posted: Sat Dec 31, 2011 12:26 pm
by fiveayem
That's true, I did not set sysroot when building my toolchain. I'm going to try this...

Re: [Newlib] Problem with compilation (headers)

Posted: Sat Dec 31, 2011 4:22 pm
by fiveayem
I think I've finally understood where the problem comes from. Some object files were made using cc instead of i586-pc-myos-gcc :

Code: Select all

i586-pc-myos-gcc -DHAVE_CONFIG_H -I. -I..  -include ../config.h -DBSD=1 -DSHELL -DIFS_BROKEN  -Wall -g -O2 -MT builtins.o -MD -MP -MF .deps/builtins.Tpo -c -o builtins.o builtins.c
mv -f .deps/builtins.Tpo .deps/builtins.Po
cc -I. -I.. -include ../config.h -DBSD=1 -DSHELL -DIFS_BROKEN  -g -O2 -Wall    -o mkinit mkinit.c
And cc does not refer to my cross compiler...

I then replaced "cc" by "i586-pc-myos-gcc" in both makefiles (the one in dash directory and the one in dash/src), but when I started making, I got a segmentation fault from make.

Re: [Newlib] Problem with compilation (headers)

Posted: Sat Dec 31, 2011 5:13 pm
by gerryg400
No, CC is correct. Some of the files (the ones that begin with mk*) are built with the host compiler. The executables (mksignames, mkinit, etc) are code generation tools and are run by make.

Re: [Newlib] Problem with compilation (headers)

Posted: Sun Jan 01, 2012 10:33 am
by fiveayem
Ok, I understand. I configured again to have a correct Makefile, and I discovered that the error happened with cc, in fact.

I looked more carefully at /usr/include/sys/stat.h and I noticed that for instance, cc considered stat() and stat64() declarations as a double definition of stat(). What should I do to remove that error ? And by the way, which version of dash did you compile for your OS ? As for me, I am trying to deal with 0.5.7 and I use gcc 4.6.1.

Re: [Newlib] Problem with compilation (headers)

Posted: Mon Jan 02, 2012 12:17 am
by gerryg400
I use dash 0.5.6 but I just tried 0.5.7 and it works. GCC is 4.6.1

I've build this in Cygwin, Ubuntu 8.04, Ubuntu 11.10, MacOSX Leopard, Snow Leopard and Lion. All work.