【问题标题】:Cannot including files with GCC无法使用 GCC 包含文件
【发布时间】:2015-01-29 12:34:58
【问题描述】:

我正在从事这个项目,该项目需要我使用一些很久以前编写的软件,现在已经开源,可以在http://www.wotug.org/occam/compilers/oc/oc-src.tar.gz 找到。该软件基本上是 Occam 的编译器。

当我解压 tar.gz 时,我找到了一个源文件夹,其中包含用于构建软件的 csh 脚本。

#!/bin/csh -f
#   
# Quick build script for occam compiler and libraries
#   

# You will need to redefine these
set gccinclude = "/u/products/toolset/release/build/include/gcc"
set inmos_occam = /inmos/prod/d4205a

# These should be ok
set base_dir = $cwd
set path = ($inmos_occam/tools $base_dir/preocc $path)
setenv ISEARCH "$base_dir/libs/ $base_dir/include/ $gccinclude/"

set buildlibs = (arglib extlib tcofflib)
foreach buildlib ($buildlibs)
    echo --- $buildlib
    cd $buildlib
    make -f [Mm]akefile.s4 COMMON=$base_dir GCCINCLUDE=$gccinclude TLIB=
    cd ..
end 
... some other stuff...

我相信以下几行: 设置 gccinclude = "/u/products/toolset/release/build/include/gcc" 设置 inmos_occam = /inmos/prod/d4205a 为编译过程指定 .h 文件的存储位置,inmos_occam 变量告诉我希望最终二进制文件存储在哪里,所以我将它们更改为: 设置 gccinclude = "/usr/include" 设置 inmos_occam = ./bin 问题是当我运行脚本时出现以下错误:

--- arglib
gcc -I./ -nostdinc /usr/include ./arg.c -c -o arg.o -ansi -DSUN4
./arg.c:9:19: fatal error: ctype.h: No such file or directory
#include <ctype.h>
                   ^
compilation terminated.
make: *** [arg.a] Error 1
--- extlib
gcc -c -msoft-float -Wall -ansi -pedantic -nostdinc /usr/include I/home/andres/Documents/T2015-Compiler/src/include -DGNU extconv.c
In file included from /home/andres/Documents/T2015-Compiler/src/include/extlib.h:8:0,
                 from extconv.c:1:
/home/andres/Documents/T2015-Compiler/src/include/imsstd.h:30:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
....and a lot more....

我对 GCC 了解不多,但我认为问题在于参数“-nostdinc”告诉编译器不要查看标准包含目录(文件在我的 ubuntu 系统中的位置),这就是它的原因不工作。但是,我不知道如何覆盖这种行为。非常感谢帮助,以便我可以编译它,如果您认为这不是问题的原因,请告诉我。

谢谢!

【问题讨论】:

    标签: c gcc build compiler-errors


    【解决方案1】:

    -nostdinc 表示您忽略了标准包含路径,我猜您不想要。但是我可以看到:

    gcc -I./ -nostdinc /usr/include ./arg.c -c -o arg.o -ansi -DSUN4
    

    /usr/include 应该类似于 -I/usr/include 以便将其包含到包含路径中。

    后来你有

    I/home/andres/Documents/T2015-Compiler/src/include
    

    应该是

    -I/home/andres/Documents/T2015-Compiler/src/include
    

    【讨论】:

    • 感谢您的回复,关于'I'和'-I'的问题,我实际上有它,因为'-I'只是我从命令行复制时出错了。我尝试设置'set gccinclude =“-I/usr/include”',这似乎有我想要的效果,但我相信我的机器实际上缺少一些库,例如'sys/cdefs.h'跨度>
    • 如果缺少库,链接器应该抱怨。如果缺少头文件,编译器应该会抱怨。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-09
    • 2019-05-04
    • 2015-04-27
    • 1970-01-01
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    相关资源
    最近更新 更多