/ usr / bin / ld找不到标题:文件格式无法识别

时间:2018-02-21 11:42:54

标签: c++ gcc linker

尝试编译程序时,我得到以下输出:

    /usr/bin/ld: cannot find headers/dir1: File format not recognized
/usr/bin/ld: cannot find headers/dir1/dir11: File format not recognized
/usr/bin/ld: cannot find headers/dir1/dir12: File format not recognized
/usr/bin/ld: cannot find headers/dir1/dir13: File format not recognized
collect2: error: ld returned 1 exit status
make: *** [all] Error 1

该项目由.c和.cpp源以及main.cpp(LOCAL_SRC_FILES)组成。 目录和子目录dir * / dir *(LOCAL_C_INCLUDES)包含.h头文件。

我用来编译的命令是:

gcc $(LOCAL_SRC_FILES) -I $(LOCAL_C_INCLUDES)

我已经多次讨论过这个问题,但它通常涉及不被识别的库而不是头文件。

您对此可能发生的原因有任何建议吗?

1 个答案:

答案 0 :(得分:3)

如果在命令行上展开变量,您将得到类似的结果:

gcc file1.cpp file2.cpp -I headers/dir1 headers/dir2

由于headers / dir2没有前缀“-I”,gcc会将其视为源文件。命令必须是:

gcc file1.cpp file2.cpp -I headers/dir1 -I headers/dir2