在angstrom上编译c / c ++程序

时间:2014-11-26 06:40:37

标签: c++ c linux gcc

C和C ++程序没有在Angstrom OS上编译



C Progam(board.c):

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


在Angstrom终端上编译C程序

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

如您所见,stdio.h路径在$ PATH中可用,即使gcc也找不到它。


C ++ Progam(beagle.cpp):

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


在Angstrom终端上编译C ++程序

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

正如您在上面所看到的,即使g ++无法找到它,也可以在$ PATH中使用iostream路径。

1 个答案:

答案 0 :(得分:1)

您不能期望获取任何随机stdio.h文件。它是实现的一部分,对于交叉编译器,您通常需要交叉编译器实现。与<iostream>相同。