我有以下两个项目:
`/home/jagbirs/Downloads/sample/SampleExtLib1` containing:
ext_lib1.c
ext_lib1.h
Makefile
/home/jagbirs/Downloads/sample/SampleMakeTest
包含:
main.c
Makefile
我正在学习如何链接外部库。 ext_lib1.h中有一个函数,我是
在main.c中使用但是在make之后我得到以下错误:
gcc -o main main.c -L/home/jagbirs/Downloads/sample/SampleExtLib1 -lext_lib1
main.c:10:22: fatal error: ext_lib1.h: No such file or directory
compilation terminated.
make: *** [all] Error 1
两个makefile如下: SampleMakeTest /生成文件:
LIB = main
SRC := main.c
CFLAGS := -I../SampleExtLib1
all: $(SRC)
gcc -o $(LIB) $(SRC) -L/home/jagbirs/Downloads/sample/SampleExtLib1 -lext_lib1
clean:
rm -f *.o
SampleExtLib1 /生成文件:
all: ext_lib1.o
ar r libext_lib1.a ext_lib1.o
clean:
rm -f *.o *.a
有些人可以帮我弄清楚为什么链接没有正常发生? 感谢
答案 0 :(得分:0)
尝试添加-I
以包含库的.h
文件:
gcc -o $(LIB) $(SRC) -I/home/jagbirs/Downloads/sample/SampleExtLib1 -L/home/jagbirs/Downloads/sample/SampleExtLib1 -lext_lib1