交叉编译环境以及开发板上-/bin/sh: ./hello: not found(使用arm-linux-gcc -static -o 来进行静态编译)
chmod +x hello
执行./hello
这时,报错:-/bin/sh: ./hello: not found
问题定位到动态链接库上
于是在主机上用arm-linux-gcc -static -o 来进行静态编译.然后将新产生的文件传到目标板上.可以发现通过静态编译的文件明显比动态编译的要大.
然后再次执行./hello 可以看到屏幕上出现了久违的Hello,World!
可以把缺少的库拷贝到目标板的/lib文件夹中。
如果目标板用的是RAMDISK,那么就要每次拷贝,太麻烦。
另一种解决方法是,使用静态链接。在GCC LINKER中,加入选项-static。
在SDK中,找到Project->properties.
页面中,找到C Build -> settings -> tool settings -> gcc linker 。
原有的command是arm-linux-gnueabihf-gcc ,将其修改为
arm-linux-gnueabihf-gcc -static。(加一个-static选项)
方法,在miscellaneous option里,修改linker flag,或者在文本框里选择,add a new option,然后填入-static。
保存,重新Build工程。
可以发现通过静态编译的文件明显比动态编译的要大.