简体   繁体   English

用于OpenWrt的Eclipse GCC C交叉编译不起作用

[英]Eclipse GCC C Cross Compiling for OpenWrt not working

I am a beginner in both linux and openwrt. 我是linux和openwrt的初学者。 Sorry if this is a stupid question. 抱歉,这是一个愚蠢的问题。

I am following this tutorial : https://downloads.openwrt.org/docs/eclipse.pdf 我正在关注本教程: https : //downloads.openwrt.org/docs/eclipse.pdf

  • Chip : MT7620 芯片:MT7620
  • Toolchain Prefix : mipsel-openwrt-linux- 工具链前缀: mipsel-openwrt-linux-
  • Toolchain Path : /ligo/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14 工具链路径: /ligo/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14

Code: 码:

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

Error: 错误:

**** Build of configuration Debug for project hello ****
make all 
Building target: hello
Invoking: Cross GCC Linker
mipsel-openwrt-linux-gcc -L/ligo/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14/lib -o"hello"  ./main.o   
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
/ligo/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14/lib/gcc/mipsel-openwrt-linux-musl/5.3.0/../../../../mipsel-openwrt-linux-musl/lib/crt1.o: In function `_start_c':
/ligo/openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14/musl-1.1.14/crt/crt1.c:17: undefined reference to `main'
/ligo/openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14/musl-1.1.14/crt/crt1.c:17: undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [hello] Error 1

add the following 2 lines at the end of bashrc 在bashrc的末尾添加以下两行

  • export PATH=$PATH:~/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin export STAGING_DIR=~/openwrt/staging_dir

  • source ~/.bashrc

To open/create the bashrc you can execute 要打开/创建bashrc,您可以执行

  • sudo gedit ~/.bashrc

Well I feel stupid when I have to figure this problem which happens too often. 好吧,当我不得不解决这个经常发生的问题时,我会感到愚蠢。

I get the above error when I forget to save the file that contains main() it gives this error since the file is empty until you save it. 当我忘记保存包含main()的文件时,出现上述错误,因为在保存之前文件为空,所以会出现此错误。

These instructions tell how to automatically save all the modified files when you kick off a build Save before build Keep this set and you won't see this again. 这些说明告诉您在启动构建时如何自动保存所有已修改的文件。在构建之前保存。保留此设置,以后将不会再看到此设置。

If you don't have the path to the toolchain set in eclipse, it never even finds a compiler, assembler or linker so it can not produce the error given. 如果您没有在eclipse中设置工具链的路径,它甚至不会找到编译器,汇编器或链接器,因此不会产生给定的错误。 The warnings about STAGING_DIR are harmless in this case. 在这种情况下,有关STAGING_DIR的警告是无害的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM