LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ARM Cross-compile environment setup (https://www.linuxquestions.org/questions/linux-newbie-8/arm-cross-compile-environment-setup-901696/)

Jae-Yong Yoo 09-07-2011 09:00 PM

ARM Cross-compile environment setup
 
Hello,

I just installed arm-linux-gnueabi-gcc for cross-compiling a code.
Now I have to setup an environment that can compile with standard libraries (assuming that the arm device has the same library environment).
If I try to compile
#include <stdio.h>

int main()
{
printf("hello, wrold\n");
return 0;
}

using arm-linux-gnueabi-gcc hello.c
It says #include <stdio.h> not found
How can I setup this environment?
Would I have to put -I/usr/include stuffs while compiling?

Jae-Yong Yoo 09-07-2011 09:07 PM

I just compiled by using

$ arm-linux-gnueabi-gcc hello.c -I/usr/include/ -L/usr/lib

and it gives an error


/usr/lib/gcc/arm-linux-gnueabi/4.4.5/../../../../arm-linux-gnueabi/bin/ld: cannot find crt1.o: No such file or directory
/usr/lib/gcc/arm-linux-gnueabi/4.4.5/../../../../arm-linux-gnueabi/bin/ld: cannot find crti.o: No such file or directory
collect2: ld returned 1 exit status


which is strange because I include the library path that has crt1.o and crti.0.

$ ls /usr/lib/crt* -l
-rw-r--r-- 1 root root 1212 2011-01-22 08:54 /usr/lib/crt1.o
-rw-r--r-- 1 root root 1012 2011-01-22 08:54 /usr/lib/crti.o
-rw-r--r-- 1 root root 504 2011-01-22 08:54 /usr/lib/crtn.o

any idea?

theNbomr 09-07-2011 09:25 PM

There is a lot of configuration of a cross compiler that isn't easy to see or even understand. The header files associated with the compiler are distinct from those that probably exist is part of the native toolchain. A properly crafted compiler must not trash the hosts native toolchain, so the builder of the toolchain specifies where the sysroot tree will be. The compiler then uses that in lieu of the native toolchain component locations. You can see where this is with
Code:

/path/to/your/arm-linux-gnueabi-gcc/gcc -v --help
I think if you look at the '-iprefix' output, it will point to the tree where the sysroot components are expected to be. Putting them there should make it right. On one cross compiler I have right now, I see
Code:

.........arm-rn100628ctng142-linux-gnu/arm-rn100628ctng142-linux-gnu/bin/../lib/gcc/arm-rn100628ctng142-linux-gnu/4.2.1/
The accordant sysroot tree is at the same level as the 'bin/../lib/' directory. I can do
Code:

ls  ...........arm-rn100628ctng142-linux-gnu/arm-rn100628ctng142-linux-gnu/bin/../sys-root/usr/include/

aio.h        cursesf.h  fmtmsg.h        lastlog.h  mtd            paths.h      signal.h      termios.h
aliases.h    curses.h    fnmatch.h      libelf      nc_tparm.h    poll.h      sound        tgmath.h
alloca.h    cursesm.h  form.h          libelf.h    ncurses_dll.h  printf.h    spawn.h      thread_db.h
ansidecl.h  cursesp.h  fpu_control.h  libgen.h    ncurses.h      protocols    stab.h        tic.h
a.out.h      cursesw.h  fstab.h        libintl.h  net            pthread.h    stdint.h      time.h
argp.h      cursslk.h  fts.h          libio.h    netash        pty.h        stdio_ext.h  ttyent.h
argz.h      dirent.h    ftw.h          limits.h    netatalk      pwd.h        stdio.h      ucontext.h
ar.h        dlfcn.h    _G_config.h    link.h      netax25        rdma        stdlib.h      ulimit.h
arpa        dmalloc.h  gconv.h        linux      netdb.h        re_comp.h    string.h      unctrl.h
asm          elf.h      gelf.h          locale.h    neteconet      regex.h      strings.h    unistd.h
asm-generic  endian.h    getopt.h        malloc.h    netinet        regexp.h    stropts.h    ustat.h
assert.h    envz.h      glob.h          math.h      netipx        resolv.h    symcat.h      utime.h
bfd.h        err.h      gmp.h          mcheck.h    netpacket      rpc          sys          utmp.h
bfdlink.h    errno.h    gnu            memory.h    netrom        rpcsvc      syscall.h    utmpx.h
bits        error.h    gnu-versions.h  menu.h      netrose        sched.h      sysexits.h    values.h
byteswap.h  eti.h      grp.h          mntent.h    nfs            scsi        syslog.h      video
complex.h    etip.h      iconv.h        monetary.h  nlist.h        search.h    tar.h        wait.h
cpio.h      execinfo.h  ieee754.h      mpf2mpfr.h  nl_types.h    semaphore.h  termcap.h    wchar.h
crypt.h      fcntl.h    ifaddrs.h      mpfr.h      nss.h          setjmp.h    term_entry.h  wctype.h
ctype.h      features.h  inttypes.h      mp.h        obstack.h      sgtty.h      term.h        wordexp.h
cursesapp.h  fenv.h      langinfo.h      mqueue.h    panel.h        shadow.h    termio.h      xlocale.h

You just need to get your headers files in the right place.

What is the origin of your cross toolchain?

--- rod.

Jae-Yong Yoo 09-07-2011 10:41 PM

I'm using Ubuntu 10.0.4 in x86 archi and I downloaded the following packages and install them using dpkg

- binutils-arm-linux-gnueabi_2.20.51.20100908-0ubuntu2cross1.50_i386.deb
- cpp-4.4-arm-linux-gnueabi_4.4.4-14ubuntu4_i386.deb
- cpp-arm-linux-gnueabi_4.4.4-9_i386.deb
- gcc-4.4-arm-linux-gnueabi_4.4.4-14ubuntu4_i386.deb
- gcc-4.4-arm-linux-gnueabi-base_4.4.4-14ubuntu4_i386.deb
- gcc-4.5-arm-linux-gnueabi-base_4.5.1-7ubuntu1cross1.38_i386.deb
- gcc-arm-linux-gnueabi_4.4.4-9_i386.deb
- libc6-armel-cross_2.12.1-0ubuntu6cross1.50_all.deb
- libgcc1-armel-cross_4.5.1-7ubuntu1cross1.50_all.deb
- libgmp3c2_4.3.2+dfsg-1ubuntu1_i386.deb
- libgomp1-armel-cross_4.5.1-7ubuntu1cross1.38_all.deb
- libmpfr4_3.0.0-2_i386.deb

I have several followup questions

1. I try to find /path/to/your/arm-linux-gnueabi-gcc/gcc but the only possible match in my case is the following
/usr/lib/gcc/arm-linux-gnueabi/4.4.5/cc1
Does it do the same thing?

2. When I type /usr/lib/gcc/arm-linux-gnueabi/4.4.5/cc1 -v --help

It gives me ... -iprefix <path> ... and looks like it is not setup properly

How can I set iprefix? Do I have to change some configuration file?

Thanks for the help.

Jaeyong

theNbomr 09-08-2011 07:53 AM

You can't set any of the built-in paths; they're set at build time of the compiler/toolchain. I would think that the .deb packages would be set up properly, so I'm not sure how to advise you. Have you found the header files anywhere (the ones that belong to the cross compiler, not the native compiler header)? Do you have a native compiler installed? I don't know how to inspect the .deb packages to see their contents, but I think if you were able to look in the 'libc6-armel-cross_2.12.1-0ubuntu6cross1.50_all.deb', that is probably where the headers would be. Is it possible you've not installed one or more packages related to the toolchain? Is the compiler/toolchain bin directory in your $PATH?

I've never used a cross toolchain from a distro's repository, so I'm sorry that I don't know much about their makeup. I've only ever used toolchains built with crosstool-ng.

--- rod.

Jae-Yong Yoo 09-08-2011 11:09 PM

Oh I see, I better try crosstool-ng for building my own cross toolchain.
Thanks rod.

Jaeyong


All times are GMT -5. The time now is 01:56 AM.