1

I am trying to cross compile a simple program with the arm toolchain. And stdio library points to another library, which results in the following error:

/home/sansari/tools/arm-eabi-4.7/bin/arm-eabi-gcc hello.c -o hello
In file included from hello.c:3:0:
/home/sansari/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/include-fixed/stdio.h:50:23: fatal error: sys/cdefs.h: No such file or directory
compilation terminated.
make: *** [hello] Error 1

At first, I thought this file is in some subdirectory of the toolchain, and I need to include the folder for this library in my makefile. But a quick tree output says that it is not. So given that I have used this toolchain successfully for a larger project, I know it is copied from somewhere. So my question is how do I add it to this project please? And what is the appropriate place to copy it from? I am trying to understand why it is not in the toolchain folders that I have, and how I should add it to my project please.

@Olaf - You have been very helpful; I however have a little more learning curve. But I do understand what you are instructing. I know I have the libraries in my build system since have built for this platform successfully. I even know that it is in my WORKING_DIRECTORY. What I do not know is if I can copy a folder and address the issue entirely or do I need to keep compiling and see what errors I get. That is do it incrementally. For example, one of the files, which was missing was cdefs.h. And I was able to find it in the folder:

/home/sansari/ndk/android-ndk-r10d/platforms/android-19/arch-arm/usr/include/sys/cdefs_elf.h

So I copied it over and the build process proceeded to the next stage. I do like to know if I should perhaps have copied the entire /sys or /include directory or compared the /include directory of my source and make sure all the files are also in the destination directory also. And that way I can avoid having to compile a number of times.

But nevertheless, I proceeded with copying one file at a time. The last error I got is:

/home/sansari/tbt/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/include/stdint.h:3:26: fatal error: stdint.h: No such file or directory

And I look in the include directory; I see a file call stdint.h What do you make of that? Does that make sense to you? I am confused by this error. How can I get this error when the file is in the directory. Basically it seems make is saying this file does not exist when it does.

I did find This post also, which seems to say what you are saying. I just need to know what is the best way to address it.

@Olaf - I really appreciate all your help. I was able to get through all the library errors by putting an include statement in my makefile. Now the linker is giving me errors as follows:

/home/sansari/tbt/tools/arm-eabi-4.7/bin/arm-eabi-gcc -I../../ndk/android-ndk-r10d/platforms/android-19/arch-arm/usr/include hello.c -o hello
/home/sansari/tbt/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/../../../../arm-eabi/bin/ld: cannot find crt0.o: No such file or directory
/home/sansari/tbt/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/../../../../arm-eabi/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
make: *** [hello] Error 1

update - I searched for a solution for the above errors. The first error is discussed here and -nostartfiles switch seems to work for me for now. I found this link that talks about libc.a being the fix for the error about not finding -lc. So I found an appropriate copy of libc.a and passed the location to the linker. The program compiles, but I get one last warning as follows:

warning: cannot find entry symbol _start; defaulting to 00000000000080dc

For which this link suggested using --entery-main switch. So now I have an executable. I want to thank you again. If you do see any problem in what I have done, please post something for me. it is gonna take a while for me to get this executable on my device.

Community
  • 1
  • 1
user3326293
  • 817
  • 1
  • 14
  • 37
  • 1
    This might be for a freestanding environment. Also note that gcc does _not_ include the stdlib (making it actually not conforming to the standard for a hosted implementation. It relies on glibc for Linux systems e.g. For cross-compilation on bare-metal, you could use newlib for example. Note that you still have to provide some basic IO-functions externally. – too honest for this site Jul 18 '15 at 22:53
  • I really appreciate this comment. Could you elaborate a couple of points please. For instance, the comment on Linux system glibc means that I have to provide this library by other means. right? How should I point to it? Do I update my make file or do I copy the file into the directory structure of the toolchain? – user3326293 Jul 19 '15 at 00:44
  • Sorry, I would have made that an answer with more details. It was mostly a general idea what the problem _could_ be. Normally, you just have to install the correct packages. However, you might check if the search paths are set up correctly, too. Try to search the header(s) anywhere reasonable (not the host system's headers). Are other standard headers like `string.h` also not found? (Note that `limits.h`, `stdint.h` and some other _are_ actually supplied by gcc (yes, that is a bit - well - complicated. – too honest for this site Jul 19 '15 at 00:54
  • so far I got errors for /sys/cdefs.h, /sys/cdefs_elf.h, _types.h, and stdint.h. The last error as stated above is the most confusing. Compiler complains about lack of a header file, which seems to be there. – user3326293 Jul 19 '15 at 01:23
  • `stdint.h` and `limits.h` (not sure about `_limits.h`) definitvely come with gcc. Check the include paths, I'd say. Otherwise I really have no further clue. In general, you should not copy standard/system headers/libraries into your project's home (that would be against the idea). – too honest for this site Jul 19 '15 at 01:37

0 Answers0