Gcc use newlib instead of glibc?

I want to use newlib instead of glibc to compile small static binaries. (I'm not going to cross-compile, since binaries must be used by the same computer.) I believe I need to build a separate gcc for this?

I compiled gcc:

  ./configure --prefix = / home / myuser / Desktop / gcc-4.4.5 --libexecdir = / home / myuser / Desktop / gcc-4.4.5 --libdir = / home / myuser / Desktop / gcc-4.4. 5 --with-gxx-include-dir = / home / myuser / Desktop / gcc-4.4.5 --enable-languages ​​= c --enable-libmudflap --disable-multilib --disable-libssp --disable-nls --with-newlib --with-gnu-as --with-gnu-ld --with-system-zlib
 make

It compiled without errors, but now when I try to compile a simple Hello World! the program wants to use the headers from / usr instead of the path above. Here are some of the errors:

  In file included from /home/myprogram/Desktop/myprogram.c:1:
 /usr/include/stdio.h:34:21: error: stddef.h: No such file or directory
 In file included from /usr/include/stdio.h:75,
                  from /home/myprogram/Desktop/myprogram.c:1:
 /usr/include/libio.h:53:21: error: stdarg.h: No such file or directory
 In file included from /usr/include/stdio.h:75,
                  from /home/myprogram/Desktop/myprogram.c:1:
 /usr/include/libio.hhaps32: error: expected specifier-qualifier-list before 'size_t'
 /usr/include/libio.hhaps64: error: expected declaration specifiers or '...' before 'size_t'
 /usr/include/libio.hhaps73: error: expected declaration specifiers or '...' before 'size_t'

What am I doing wrong? Is compiling a new gcc necessary or can I use my existing gcc and use newlib instead of glibc ???

+7
source share
3 answers

You do not need to rebuild gcc for this; you just need to point your existing gcc to the right things (using -I , -L , etc.) and say that it is not pulling ordinary system things (using -nostdlib ).

In the section entitled "Shared newlib" in the file

+6
source

I would highly recommend using crosstool-ng to create your GCC binding. If you choose x86 followed by bare metal as your operating system, you can safely use newlib as libc.

Please note that newlib does not work with the operating system - these are standard things, such as IO, will not work out of the box.

+3
source

You must tell the compiler where it can find the include files:

 gcc -IyourDirectoryHere -IanotherDirectoryHere 

-I (this is a minus followed by a capital -I i, as in Italy)

More information: http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Directory-Options.html

+1
source

All Articles