c++ -/usr/bin/ld 找不到 header : File format not recognized

标签 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)

我看到这个问题讨论了很多次,但它通常与未被识别的库有关,而不是头文件。

对于为什么会发生这种情况,您有什么建议吗?

最佳答案

如果您在命令行上展开变量,您会得到如下内容:

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

关于c++ -/usr/bin/ld 找不到 header : File format not recognized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48905044/

相关文章:

android - 如何解决 "section type conflict"编译错误以及将 section 属性与 gcc 结合使用的最佳实践

linux - FreeType 2 的 undefined reference

linux - 即使设置了 `-lm`,也找不到 Math.h

c++ - 从文件中解析原始数据的最快最有效的方法

c++ - 头文件和包含最佳实践

c# - Emgu Opencv C# ConvertTo 不同的结果

gcc - 如何在没有共享库的情况下使用 GMP、MPFR、MPC、ELF 逐个安装 GCC?

c++ - 带有 CKKS 的 Microsoft SEAL 中的 vector 点积

c - gcc:汇编代码中不同引用的命令行参数

ios - 具有共享依赖项的多个静态库 - iOS