[英]How to link my C program to a static/dynamic library?
I'm trying to link my C program to both a static and dynamic library to see the difference. 我试图将我的C程序链接到静态库和动态库,以了解两者之间的区别。 How do I do that? 我怎么做? I've made my own Makefile: 我已经创建了自己的Makefile:
# ------ executable rule -----------
app : app.o
-gcc -g app.o -o app
# ------ intermeditate object files rule (.o) -------
app.o : main.c
-gcc -g -c main.c -o app.o
I've only shown you some of my Makefile as I think the rest is unnecessary. 我只显示了一些Makefile,因为我认为其余的不必要。
I've tried to write -L. lstatic
我试图写-L. lstatic
-L. lstatic
after -gcc -g app.o -o app
but it didn't work. -L. lstatic
后-gcc -g app.o -o app
,但没有奏效。
Read about invoking GCC . 了解有关调用GCC的信息 。 Order of arguments to gcc
matters a lot! gcc
的参数顺序很重要!
You could use -static
or -Bstatic
您可以使用-static
或-Bstatic
You can also explicitly link with static libraries, by giving some /usr/lib/libfoo.a
(or some appropriate file path) argument at link time. 您还可以通过在链接时提供一些/usr/lib/libfoo.a
(或一些适当的文件路径)参数来显式链接静态库。
You'll better improve your Makefile
to use existing builtin rules (try make -p
) and conventional variables, eg like here . 您最好改善Makefile
以使用现有的内置规则(尝试make -p
)和常规变量,例如here 。 Read the documentation of GNU make
. 阅读GNU make
的文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.