Page 1 of 2

Cross-compiler

Posted: Thu Jun 30, 2011 10:39 pm
by alaroldai
Hi, I'm trying to use the instructions on the "GCC Cross-compiler" wiki page, but I keep getting a file not found error when I try to make binutils. The file in question is "sysinfo.h". Here's the error:

(Obviously I've left most of the make output out. The command given was "sudo make all")
Making all in po
make[4]: Entering directory `/usr/src/build-binutils/opcodes/po'
make[4]: Nothing to be done for `all'.
make[4]: Leaving directory `/usr/src/build-binutils/opcodes/po'
make[3]: Leaving directory `/usr/src/build-binutils/opcodes'
make[2]: Leaving directory `/usr/src/build-binutils/opcodes'
mkdir -p -- ./binutils
Configuring in ./binutils
configure: creating cache ./config.cache
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for x86_64-unknown-linux-gnu-gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for library containing strerror... none required
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... mawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for x86_64-unknown-linux-gnu-gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking how to run the C preprocessor... 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... yes
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 special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by gcc... ld
checking if the linker (ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... nm
checking the name lister (nm) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 3458764513820540925
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for ld option to reload object files... -r
checking for x86_64-unknown-linux-gnu-objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for x86_64-unknown-linux-gnu-ar... ar
checking for x86_64-unknown-linux-gnu-strip... no
checking for strip... strip
checking for x86_64-unknown-linux-gnu-ranlib... ranlib
checking command to parse nm output from gcc object... ok
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
Setting warning flags = -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror
checking for bison... /usr/src/binutils-2.21/missing bison -y
checking for flex... flex
checking lex output file root... lex.yy
checking lex library... -lfl
checking whether yytext is a pointer... yes
checking whether NLS is requested... no
checking whether NLS is requested... no
checking for msgfmt... /usr/bin/msgfmt
checking for gmsgfmt... /usr/bin/msgfmt
checking for xgettext... /usr/bin/xgettext
checking for msgmerge... /usr/bin/msgmerge
checking whether to enable maintainer-specific portions of Makefiles... no
checking for x86_64-unknown-linux-gnu-ranlib... (cached) ranlib
checking for string.h... (cached) yes
checking for strings.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking sys/file.h usability... yes
checking sys/file.h presence... yes
checking for sys/file.h... yes
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for working alloca.h... yes
checking for alloca... yes
checking for sbrk... yes
checking for utimes... yes
checking for setmode... no
checking for getc_unlocked... yes
checking for strcoll... yes
checking for mkstemp... yes
checking for mkdtemp... yes
checking for library containing frexp... none required
checking for time_t in time.h... yes
checking for time_t in sys/types.h... yes
checking for a known getopt prototype in unistd.h... yes
checking for utime.h... yes
checking whether fprintf is declared... yes
checking whether stpcpy is declared... yes
checking whether strstr is declared... yes
checking whether sbrk is declared... yes
checking whether getenv is declared... yes
checking whether environ is declared... yes
checking whether getc_unlocked is declared... yes
checking whether snprintf is declared... yes
checking whether vsnprintf is declared... yes
checking for library containing zlibVersion... no
checking iconv.h usability... yes
checking iconv.h presence... yes
checking for iconv.h... yes
checking for ld used by GCC... ld -m elf_x86_64
checking if the linker (ld -m elf_x86_64) is GNU ld... yes
checking for shared library run path origin... done
checking for iconv... yes
checking for iconv declaration... install-shextern size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
configure: updating cache ./config.cache
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating po/Makefile.in
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing default-1 commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
make[2]: Entering directory `/usr/src/build-binutils/binutils'
if [ -r sysinfo.c ]; then \
gcc -c -I. -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -Wno-error sysinfo.c ; \
else \
gcc -c -I. -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -Wno-error ../../binutils-2.21/binutils/sysinfo.c ; \
fi
/bin/bash ../../binutils-2.21/binutils/../ylwrap ../../binutils-2.21/binutils/syslex.l lex.yy.c syslex.c -- flex
if [ -r syslex.c ]; then \
gcc -c -I. -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -Wno-error syslex.c ; \
else \
gcc -c -I. -I../../binutils-2.21/binutils -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -Wno-error ../../binutils-2.21/binutils/syslex.c ;\
fi
syslex.l:31:21: fatal error: sysinfo.h: No such file or directory
compilation terminated.
make[2]: *** [syslex.o] Error 1
make[2]: Leaving directory `/usr/src/build-binutils/binutils'
make[1]: *** [all-binutils] Error 2
make[1]: Leaving directory `/usr/src/build-binutils'
make: *** [all] Error 2


any help?

Re: Cross-compiler

Posted: Fri Jul 01, 2011 12:06 am
by jnc100
What are the arguments you give to configure? It seems your build, host and target systems are all the same (which defeats the object of a cross compiler). Also, which version of binutils are you trying to use?

Regards,
John.

Re: Cross-compiler

Posted: Fri Jul 01, 2011 12:31 am
by Solar
jnc100 wrote:What are the arguments you give to configure?
Hint to OP: head config.log lists your configure-line for easy copy & paste.
jnc100 wrote:It seems your build, host and target systems are all the same (which defeats the object of a cross compiler).
Indeed:

Code: Select all

checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu    // this should be akin to your $TARGET, not your host...
jnc100 wrote:Also, which version of binutils are you trying to use?
That, at least, isn't the problem:

Code: Select all

/bin/bash ../../binutils-2.21/binutils/../ylwrap ../../binutils-2.21/binutils/syslex.l lex.yy.c syslex.c -- flex

Re: Cross-compiler

Posted: Sat Jul 02, 2011 8:38 pm
by alaroldai
I'm running "sudo ../configure --target=i586-elf --host=x86_64-unknown-linux-gnu --prefix=/usr/cross --disable-nls", followed by "sudo make all". The output I gave before must have been from a run after a restart - I must have forgotten to export target and prefix. However, that shouldn't mean that it couldn't find the sysinfo.h file.

output from head config.log:

Code: Select all

alaroldai@alaroldai-MacBook:/usr/src/build-binutils$ head config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by configure, which was
generated by GNU Autoconf 2.64.  Invocation command line was

  $ ../binutils-2.21/configure --target=i586-elf --host=x86_64-unknown-linux-gnu --prefix=/usr/cross --disable-nls

## --------- ##
## Platform. ##
I've also rerun everything with the correct target and the same error returns. I'd post the output but it's more than 1300 lines long...

Code: Select all

alaroldai@alaroldai-MacBook:/usr/src/build-binutils$ sudo make all >> ~/Desktop/binutils-build-info.txt
../../../binutils-2.21/bfd/doc/chew.c: In function ‘print_stack_level’:
../../../binutils-2.21/bfd/doc/chew.c:479:3: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’
../../../binutils-2.21/bfd/doc/chew.c:480:3: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’
../../../binutils-2.21/bfd/doc/chew.c: In function ‘main’:
../../../binutils-2.21/bfd/doc/chew.c:1567:9: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’
syslex.l:31:21: fatal error: sysinfo.h: No such file or directory
compilation terminated.
make[2]: *** [syslex.o] Error 1
make[1]: *** [all-binutils] Error 2
make: *** [all] Error 2

Re: Cross-compiler

Posted: Sat Jul 02, 2011 8:40 pm
by alaroldai
also worth noting: a search through the output of "sudo make all" for "sysinfo.h" shows only two lines:

Code: Select all

...
checking for sys/sysinfo.h... yes
checking for machine/hal_sysinfo.h... no
...

Re: Cross-compiler

Posted: Sat Jul 02, 2011 9:33 pm
by gerryg400
I'm running "sudo ../configure --target=i586-elf --host=x86_64-unknown-linux-gnu --prefix=/usr/cross --disable-nls", followed by "sudo make all". The output
Why are you setting the host ? And why do you need sudo. Neither should be necessary to build a cross-compiler.

Re: Cross-compiler

Posted: Sat Jul 02, 2011 9:46 pm
by alaroldai
I'm building binutils in /usr/src, which I don't have write access to. At least, I get permission denied errors when I try to configure without sudo. And I'm specifying the host because config.guess apparently couldn't work out what host I was using. I'll give it a try without again though.

Re: Cross-compiler

Posted: Sat Jul 02, 2011 9:52 pm
by alaroldai
Well, I can configure without specifying the host apparently. But this still doesn't help me find sysinfo.h... does anyone know where it's used? The output from make only mentions it twice, and the Makefile seems to have a line that shows sysinfo.h being generated as part of the make process:

Code: Select all

alaroldai@alaroldai-MacBook:/usr/src/build-binutils/binutils$ grep sysinfo.h Makefile
GENERATED_HFILES = arparse.h sysroff.h sysinfo.h defparse.h rcparse.h mcparse.h
EXTRA_DIST = arparse.c arparse.h arlex.c nlmheader.c sysinfo.c sysinfo.h \
syslex.o: syslex.c sysinfo.h config.h
sysinfo.h: sysinfo.c

Re: Cross-compiler

Posted: Sat Jul 02, 2011 10:17 pm
by gerryg400
sysinfo.h isn't generated. It's in the distribution.

Re: Cross-compiler

Posted: Sun Jul 03, 2011 1:20 am
by alaroldai
Ok, after re-downloading the binutils and gcc archives, I've finally managed to install my cross compiler. However, there's still one problem: When I try to compile my kernel, the compiler returns assembler errors. I can compile it correctly but running gcc -S, and then as, but if I try to compile using only gcc it returns errors. Would I be right to guess that the cross-compiler gcc is calling the native assembler rather than the cross-compiler assembler? If so, how can I have it call the right version of as?

Re: Cross-compiler

Posted: Sun Jul 03, 2011 3:16 am
by Combuster
I can compile it correctly but running gcc -S, and then as
Start with actually using the crosscompiler instead of what your mac thinks is a nice substitute?

Re: Cross-compiler

Posted: Sun Jul 03, 2011 6:14 pm
by alaroldai
Yeah. Triple boot Mac/Windoze/Ubuntu.

It'd be nice to know how to specify which assembler gcc should call. I should probably have mentioned that I am using the gcc cross-compiler, but I think it's calling the wrong assembler. Alternatively I could have gcc spit out some assembler code and then call the assembler manually - is this a better solution?

Re: Cross-compiler

Posted: Mon Jul 04, 2011 12:24 am
by xenos
So, I guess now you have a bunch of executables in /usr/cross/bin. Fine, that's your cross compiler. There are different ways to actually use it. I simply added a few symlinks:

/usr/bin/i686-pc-elf-gcc -> /usr/i686-elf/bin/gcc

and so on for all the other executables. You might want to do something like this:

/usr/bin/i586-elf-gcc -> /usr/cross/bin/gcc

and so on. If you then run something like "i586-elf-gcc myfile.c -o myfile", it should do what you want.

Re: Cross-compiler

Posted: Mon Jul 04, 2011 12:54 am
by Solar
*Sigh*

To quote the tutorial, section "Usage", emphasis mine:
Once you are finished, your toolset resides in /usr/local/cross. For example, you have a gcc executable in /usr/local/cross/bin/$TARGET-gcc (and /usr/local/cross/$TARGET/gcc as well), which spits out binaries for your TARGET. Add /usr/local/cross/bin to your PATH environment variable, so that gcc invokes your system compiler, and $TARGET-gcc invokes your cross-compiler. (Note that you have to prefix any of the binutils just as well, i.e. $TARGET-ld, $TARGET-ar, $TARGET-objdump etc.)
/usr/local/cross/bin/${TARGET}-gcc will always use /usr/local/cross/bin/${TARGET}-as for assembly.

Re: Cross-compiler

Posted: Tue Oct 04, 2011 5:10 pm
by gfmoore
I am so sorry for asking this follow up to Solar's last post on this - I don't want him to be sad, but

I have followed the tutorial using cygwin and have the executables and when I try $TARGET-gcc it says no input file which is great.

then I try from /home/Gordon (under cygwin)

$TARGET-gcc GordOS.c -o GordOS

and I get an error saying that

/usr/local/cross/lib/gcc/i586-elf/4.4.3/../../../../i586-elf/bin/ld: crt0.o: No such file: No such file or directory
collect2: ld returned 1 exit status

I checked the long path to ld and that's fine, I assume then that crt0.o is the issue, but I have no idea what that is.

I tried Googling, but didn't understand the answers, which seemed to relate to Android dev and leaving out some switches, but I don't think i need any switches but -o for a trivial int main() { return 0; } app?

I'm thinking that $TARGET-gcc is creating some intermediate files somewhere which aren't then being identified as somehow the path is wrong, but I have no ideas how to fix that.

I guess I have some research to do, but if anyone cares to take pity on me and save me that time, I'd be grateful (and perhaps be useful to others.)

If I've done something stupid I'm sorry, but I've worked through two complete installs for this and I know I'm so close :)

Gordon

edit:cygwin 1.7.9-1 binutils-2.2.0 gcc-core.4.4.3 as per tutorial (and also installed the libs)