[英]Linking .a file in Makefile
How can I add a .a library into my Makefile? 如何将.a库添加到我的Makefile中?
For example, if I have ../mylib/mylib.a, what do I have to write into the Makefile in order for it to include all the code in mylib.a? 例如,如果我有../mylib/mylib.a,我要写什么文件才能使其包含mylib.a中的所有代码?
Sorry, Makefiles are very new to me. 抱歉,Makefile对我来说很新。 Thanks for the help! 谢谢您的帮助!
(Supposing mylib.a and mylib.h are on the same ../mylib/ path) (假设mylib.a和mylib.h在同一../mylib/路径中)
CC = gcc
CFLAGS = -O3 -Wall
LIB = mylib
LIB_PATH = ../mylib/
PROGRAM = myprogram
...
all:
...
$(CC) $(CFLAGS) -I$(LIB_PATH) -L$(LIB_PATH) -o $(PROGRAM) main.c -l$(LIB) `pkg-config ...`
Basically, you need set the include path to the .h file with -I, then -L for the lib path and -l to set the lib name. 基本上,您需要使用-I设置.h文件的include路径,然后使用-L设置lib路径,使用-l设置lib名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.