[英]Having trouble with the gcc -I flag
我確信這是一件非常簡單的事情,但我無法讓 gcc 或 clang 使用自定義包含目錄。 我正在使用 Linux Mint。 該項目位於名為morg
的目錄中。
這是我在morg/src/main.c
上的令人興奮的代碼
#include <stdio.h>
#include "GLFW/glfw3.h"
int main(){
printf("hello world!\n");
return 0;
}
目錄morg/include
包含GLFW/glfw3.h
目錄morg/lib
包含libglfw3.a
,這是我嘗試使用的編譯庫。
我在morg/build.sh
有一個 bash 文件
#!/bin/bash
gcc -Wall -Wextra -v -g -o -Iinclude -Llib -lglfw3 morg src/main.c
我用這個網站來幫助我把它放在一起。 編譯器能夠看到我試圖鏈接到的 static 庫,但運行上述結果如下:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.4.0-1ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-v' '-g' '-o' '-Iinclude' '-Llib' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/7/cc1 -quiet -v -imultiarch x86_64-linux-gnu src/main.c -quiet -dumpbase main.c -mtune=generic -march=x86-64 -auxbase main -g -Wall -Wextra -version -fstack-protector-strong -Wformat-security -o /tmp/cc7OGbRB.s
GNU C11 (Ubuntu 7.4.0-1ubuntu1~18.04.1) version 7.4.0 (x86_64-linux-gnu)
compiled by GNU C version 7.4.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C11 (Ubuntu 7.4.0-1ubuntu1~18.04.1) version 7.4.0 (x86_64-linux-gnu)
compiled by GNU C version 7.4.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: fa57db1fe2d756b22d454aa8428fd3bd
src/main.c:2:10: fatal error: GLFW/glfw3.h: No such file or directory
#include "GLFW/glfw3.h"
^~~~~~~~~~~~~~
compilation terminated.
我可以看到include "..." starts here
是空的,並且include <...> starts here
是不變的,無論我是否在命令行選項中包含-Iinclude
。
我也有點擔心那些說ignoring nonexistent directory
但它看起來並不相關的行。
我認為 clang 可能會提供更多有用的錯誤消息,但它基本上是相同的。
對於它的價值,我之前使用過 GLFW,但在 Windows 和 Visual Studio 上使用過。
我錯過了什么? 我在搜索中搜索了互聯網的高低,感覺很愚蠢。
編輯:正如頂部評論所說,我在錯誤的地方使用了-o
命令,但這不是唯一的問題! 我需要將-lglfw
(不是-lglfw3
)放在主源文件之后,如下所示:
gcc -Wall -Wextra -g -Iinclude -Llib -o morg src/main.c -lglfw
看起來 -o 選項放錯了位置,導致錯誤。
嘗試這個
gcc -Wall -Wextra -v -g -Iinclude -Llib -lglfw3 -o morg src/main.c
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.