0

C and C++ program is not compiling on Angstrom OS



C Progam (board.c):

#include<stdio.h>
void main(){
    printf("hello world");
}


Compiling C program on Angstrom Terminal

root@pldek-beagle:~/Comparison# gcc board.c -o board
/usr/lib/gcc/arm-angstrom-linux-gnueabi/4.7.3/../../../../arm-angstrom-linux-gnueabi/bin/ld: this linker was not configured to use sysroots
collect2: error: ld returned 1 exit status


root@pldek-beagle:~/Comparison# gcc --sysroot=/usr/local  board.c -o board
board.c:1:18: fatal error: stdio.h: No such file or directory
compilation terminated.

root@pldek-beagle:~/Comparison# whereis stdio
stdio: /usr/include/stdio.h

root@pldek-beagle:~/Comparison# echo $PATH
/mnt/data/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/include/c++/:/usr/include/:/usr/include/c++/:/usr/include/c++:/usr/include/c++/:/usr/include/c++/:/usr/include/c++/:/usr/include/:/usr/include

As you can see above , stdio.h path is available in $PATH even then the gcc is not able to find it.


C++ Progam (beagle.cpp):

using namespace std;
#include<iostream>
void main(){
    cout<<"hello world";
}


Compiling C++ program on Angstrom Terminal

root@pldek-beagle:~/Comparison# g++ beagle.cpp -o beagle
/usr/lib/gcc/arm-angstrom-linux-gnueabi/4.7.3/../../../../arm-angstrom-linux-gnueabi/bin/ld: this linker was not configured to use sysroots
collect2: error: ld returned 1 exit status

root@pldek-beagle:~/Comparison# g++ --sysroot=/usr/local  beagle.cpp -o beagle
beagle.cpp:2:19: fatal error: iostream: No such file or directory
compilation terminated.

root@pldek-beagle:~/Comparison# whereis iostream
iostream: /usr/include/c++/iostream

echo $PATH
/mnt/data/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/include/c++/:/usr/include/:/usr/include/c++/:/usr/include/c++:/usr/include/c++/:/usr/include/c++/:/usr/include/c++/:/usr/include/:/usr/include

As you can see above , iostream path is available in $PATH even then the g++ is not able to find it.

  • Where do you place your cross-compiler? From the error message, it seems at `/usr/lib/...` but it is not present in your `PATH`. Can you double check the cross-compiler location? – SSC Nov 26 '14 at 06:46
  • As far as I know, gcc doesn't look in $PATH for headers or libraries. ($PATH is for executables.) Relevant environment variables are [here](https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html). – molbdnilo Nov 26 '14 at 06:56
  • possible duplicate of [Linker Error : gcc](http://stackoverflow.com/questions/16437383/linker-error-gcc) – Ulrich Eckhardt Nov 26 '14 at 07:07
  • Searching the web for the error message would have given you answers, I'm voting to close your question as duplicate. – Ulrich Eckhardt Nov 26 '14 at 07:08
  • @SSC : Cross-Compiler location is added in PATH but same error is coming. – Gurdeepak Joshi Nov 26 '14 at 07:41
  • @UlrichEckhardt : As you can see from above Angstrom terminal screenshot, even when the linker error is resolved still the gcc is not able to find stdio.h – Gurdeepak Joshi Nov 26 '14 at 07:43
  • @GurdeepakJoshi Is your cross-compiler and the related includes located at `/usr/local`, or `/usr/lib` or other places? – SSC Nov 26 '14 at 07:50
  • @SSC: Cross Compiler is located at /usr/lib but even when i run " gcc --sysroot=/usr/lib/gcc board.c -o board" or "gcc --sysroot=/usr/lib board.c -o board", same error is coming i.e it is not able to find stdio.h – Gurdeepak Joshi Nov 26 '14 at 07:53
  • @GurdeepakJoshi I have no answer... Sorry. Maybe you can try to follow molbdnilo's advise and check out the environment variables. – SSC Nov 26 '14 at 07:56
  • I have used angstrom distro on beagleboard. There is a package manager (like apt-get/yum) for angstrom distro also. I forgot the name. Try using that for installing binutils, gcc etc.. – anishsane Nov 26 '14 at 08:15
  • @anishsane The package manager for angstrom is opkg and I tried installing g++ and gcc executing "opkg install gcc" and "opkg install g++" but terminal shows gcc,binutils and g++ are already up to date. – Gurdeepak Joshi Nov 26 '14 at 08:18
  • @molbdnilo I added the stdio.h path to C_INCLUDE_PATH and then executed "gcc --sysroot=/usr/local board.c -o beagle". After its execution i get the linker error i.e "/usr/lib/gcc/arm-angstrom-linux-gnueabi/4.7.3/../../../../arm-angstrom-linux-gnueabi/bin/ld: this linker was not configured to use sysroots collect2: error: ld returned 1 exit status". It appears that now it found the stdio.h but i am trying to find why this linking error is coming – Gurdeepak Joshi Nov 26 '14 at 08:40
  • @GurdeepakJoshi You're cross-compiling, so you can't use the system libraries. You need to specify the path to the cross-compiler libraries. If you specify `--sysroot=foo` the compiler will search `foo/usr/include` and `foo/usr/lib`. – molbdnilo Nov 26 '14 at 09:40

1 Answers1

1

You can't just expect to pick up any random stdio.h file. It is part of the implementation, and for a cross-compiler you generally need the cross-compiler implementation. Same for <iostream>.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • I am using the default compiler on angstrom i.e gcc and g++. I believe it is not cross compiler. – Gurdeepak Joshi Nov 26 '14 at 08:25
  • You said "cross compiler location is added in $PATH" (in answer to SSC's comment). You have to understand that we're trying to respond based on what you're telling us about your system. Without clear facts, don't expect a clear answer. – MSalters Nov 26 '14 at 08:58
  • As you can see from the above screenshots, I am trying the default compiler. But even after trying the cross- compiler (as SSC suggested) same error is coming. But I need the solution for default compiler. – Gurdeepak Joshi Nov 26 '14 at 09:08
  • you could append your gcc lines with -I. -Ipathtoheaders -LpathtoLibs -llibc6 to find the desired headers and desired library – user3629249 Nov 26 '14 at 09:54