简体   繁体   English

找不到非标准 header 包括

[英]Cant find non-standard header includes

I am not using standard gcc headers.我没有使用标准gcc标头。 I am building with -nostdlib and -nostdinc options.我正在使用-nostdlib-nostdinc选项进行构建。 These options force the compiler to not use standard headers.这些选项强制编译器不使用标准头文件。

I am using newlib for my custom kernel development.我正在使用newlib进行自定义 kernel 开发。 newlib contains headers and other libs. newlib包含标题和其他库。

https://stackoverflow.com/a/30792552/13014162 https://stackoverflow.com/a/30792552/13014162

The error when I type make :我输入make时的错误:

lib/builtins/lib_int.h:29:12: fatal error: 'stdint.h' file not found
#  include <stdint.h>
           ^
1 error generated.
Makefile:90: recipe for target 'lib/builtins/kern_lib.o' failed

So, when building the compiler should pick up the stdint.h from newlib (instead from standard header).因此,在构建编译器时,应该从newlib (而不是从标准头文件)中获取stdint.h Why is it not picking it?为什么不采摘它?

This project has already been built by others previously.该项目之前已经由其他人构建。 So there is something in my setup that is wrong.所以我的设置中有些地方是错误的。 I believe that include paths and other things are correctly setup because others are able to build it.我相信包含路径和其他内容已正确设置,因为其他人能够构建它。

Can someone point to me specifically how to USE newlib .有人可以具体指点我如何使用newlib I checked that newlib has stdint.h inside it.我检查了newlib里面有stdint.h

From the newlib README.txt file:来自 newlib README.txt文件:

To compile a program against shared newlib:要针对共享的 newlib 编译程序:

 gcc -nostdlib $(target_install_dir)/lib/crt0.o progname.c -I $(target_install_dir)/include -L $(target_install_dir)/lib -lc -lm -lgcc

To run the program, make sure that $(target_install_dir)/lib is listed in the LD_LIBRARY_PATH environment variable.要运行该程序,请确保 $(target_install_dir)/lib 列在LD_LIBRARY_PATH环境变量中。

To create a static binary linked against newlib, do the following:要创建与 newlib 链接的 static 二进制文件,请执行以下操作:

 gcc -nostdlib -static $(target_install_dir)/lib/crt0.o progname.c -I $(target_install_dir)/include -L $(target_install_dir)/lib -lc -lm

The above is written in Makefile format, with progname.c being the name of the source file to compile, and $(target_install_dir) being the directory where newlib was installed into.上面写的是Makefile格式, progname.c是要编译的源文件名, $(target_install_dir)是newlib的安装目录。 If you are unsure, you can run find ~/ /usr /lib* -name crt0.o ;如果不确定,可以运行find ~/ /usr /lib* -name crt0.o newlib should be installed in two directories above one of the outputs. newlib 应该安装在其中一个输出之上的两个目录中。 If that command doesn't output anything, you haven't installed newlib yet.如果该命令没有 output 任何内容,则您尚未安装 newlib。

Personally, I'd try with something like the following Makefile:就个人而言,我会尝试使用类似以下 Makefile 的内容:

INCNEWLIB := /usr/include/newlib
LIBNEWLIB := /usr/lib/arm-none-eabi/newlib
CRT0      := $(LIBNEWLIB)/crt0.o
CC        := /usr/bin/arm-none-eabi-gcc
CFLAGS    := -Wall -Wextra -O2
LDFLAGS   :=

%.o: %.c
    $(CC) $(CFLAGS) -nostdlib -I $(INCNEWLIB) $^ -c -o $@

# For dynamically linked binary executables:
dynamic-bin: your.o object.o files.o here.o
    $(CC) $(CFLAGS) -nostdlib $(CRT0) $^ -L $(LIBNEWLIB) -lc -lgcc $(LDFLAGS) -o $@

# For statically linked binary executables:
static-bin: your.o object.o files.o here.o
    $(CC) $(CFLAGS) -static -nostdlib $(CRT0) $^ -L $(LIBNEWLIB) -lc $(LDFLAGS) -o $@

Note that this forum eats tabs, and Makefiles need to be indented with tabs, so if you copy-paste the above, fix the indentation using eg sed -e 's|^ *|\t|' -i Makefile请注意,该论坛使用制表符,并且 Makefile 需要使用制表符缩进,因此如果您复制粘贴以上内容,请使用例如sed -e 's|^ *|\t|' -i Makefile修复缩进sed -e 's|^ *|\t|' -i Makefile . sed -e 's|^ *|\t|' -i Makefile

The above paths are for Debian/Ubuntu/Mint ARM newlib, edit them to match your system and personal preferences.以上路径适用于 Debian/Ubuntu/Mint ARM newlib,编辑它们以匹配您的系统和个人喜好。

You can override any of the variables at the command line.您可以在命令行覆盖任何变量。 For example, make CRT0=/usr/lib/arm-none-eabi/newlib/thumb/v7e-m/fpv5/hard/crt0.o uses a different startup routines for the binary executable (v7e-m hard-fpv5).例如, make CRT0=/usr/lib/arm-none-eabi/newlib/thumb/v7e-m/fpv5/hard/crt0.o为二进制可执行文件 (v7e-m hard-fpv5) 使用不同的启动例程。

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

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