Linux环境下,Makefile中如何链接静态库

a476439154 2014-08-11 03:23:07
我新写一个test.c,test.c中调用到一个第三方静态库(libcrexr64.a)中的函数,test.c和libcrexr64.a都位于当前目录下,我在Makefile中应该如何写? 对于MakeFile文件我是一点不通啊,求大侠
...全文
27078 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
nswcfd 2015-10-23
  • 打赏
  • 举报
回复
就像2#或4#说的那样? gcc -o test test.c libcrexr64.a
guo6409535 2015-10-22
  • 打赏
  • 举报
回复
引用 19 楼 nswcfd 的回复:
应该是可以的。
//============================== 怎么把直接把静态库,当作.o 文件一块编译 要怎么做
nswcfd 2015-09-15
  • 打赏
  • 举报
回复
应该是可以的。
alinly 2015-09-15
  • 打赏
  • 举报
回复
简单的方法,可不可以直接把静态库,当作.o 文件一块编译?
xx-xx-xxx-xxx 2015-09-11
  • 打赏
  • 举报
回复
gcc -o hello hello.c -I /home/hello/include -L /home/hello/lib -lworld 上面这句表示在编译hello.c时: (大写I小写i的I)-I /home/hello/include表示将/home/hello/include目录作为第一个寻找头文件的目录,寻找的顺序是:/home/hello/include-->/usr/include-->/usr/local/include -L /home/hello/lib表示将/home/hello/lib目录作为第一个寻找库文件的目录,寻找的顺序是:/home/hello/lib-->/lib-->/usr/lib-->/usr/local/lib (大写L小写l的l)-lworld表示在上面的lib的路径中寻找libworld.so动态库文件(如果gcc编译选项中加入了“-static”表示寻找libworld.a静态库文件) 如 -lpthread 寻找线程库
liuyihao0825 2015-09-09
  • 打赏
  • 举报
回复
赞楼上两位~
  • 打赏
  • 举报
回复
Hangzhou is a nice place to live. Zhenjiang Univ? work for 阿里巴巴? I am old but not that old. How old are u? 22 if under, 24 if graduate, you don't sound like a phd though...
rs232的日常 2014-08-14
  • 打赏
  • 举报
回复
引用 13 楼 micropentium6 的回复:
[quote=引用 12 楼 luqiang2014 的回复:] [quote=引用 10 楼 micropentium6 的回复:] [quote=引用 9 楼 luqiang2014 的回复:] [quote=引用 8 楼 micropentium6 的回复:] [quote=引用 7 楼 luqiang2014 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 luqiang2014 的回复:] Are you turtle pie?Your english is pretty good.
To 逗比: do u know what turtle pie is?[/quote] 海归pie~[/quote] http://www.urbandictionary.com/define.php?term=Turtle%20Pie Don't worry, you don't want to know the mistake I made in French...[/quote] You see, am I right? [/quote] WTF!!! turtle pie in English implies to XXXXX Whatever meaning it takes, I am not "turtle pie". I have a feeling that you are somewhere else, are you?[/quote] Sorry for my poor english...do you mean I know you ? I don't think I know you,but this talk makes great fun, shall we continue?Or can I get your QQ or Wechat?[/quote] I was asking if you are studying or working abroad? Believe it or not, I don't have QQ, Wechat, facekbook, twitter, weibo, smart phone......[/quote] So I do have poor english,I just finished my school this July, now I work in Hangzhou。I‘m wondering how can you survive without all these communicating tools,are you caveman,or you are 60+ old?
  • 打赏
  • 举报
回复
引用 12 楼 luqiang2014 的回复:
[quote=引用 10 楼 micropentium6 的回复:] [quote=引用 9 楼 luqiang2014 的回复:] [quote=引用 8 楼 micropentium6 的回复:] [quote=引用 7 楼 luqiang2014 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 luqiang2014 的回复:] Are you turtle pie?Your english is pretty good.
To 逗比: do u know what turtle pie is?[/quote] 海归pie~[/quote] http://www.urbandictionary.com/define.php?term=Turtle%20Pie Don't worry, you don't want to know the mistake I made in French...[/quote] You see, am I right? [/quote] WTF!!! turtle pie in English implies to XXXXX Whatever meaning it takes, I am not "turtle pie". I have a feeling that you are somewhere else, are you?[/quote] Sorry for my poor english...do you mean I know you ? I don't think I know you,but this talk makes great fun, shall we continue?Or can I get your QQ or Wechat?[/quote] I was asking if you are studying or working abroad? Believe it or not, I don't have QQ, Wechat, facekbook, twitter, weibo, smart phone......
rs232的日常 2014-08-14
  • 打赏
  • 举报
回复
引用 10 楼 micropentium6 的回复:
[quote=引用 9 楼 luqiang2014 的回复:] [quote=引用 8 楼 micropentium6 的回复:] [quote=引用 7 楼 luqiang2014 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 luqiang2014 的回复:] Are you turtle pie?Your english is pretty good.
To 逗比: do u know what turtle pie is?[/quote] 海归pie~[/quote] http://www.urbandictionary.com/define.php?term=Turtle%20Pie Don't worry, you don't want to know the mistake I made in French...[/quote] You see, am I right? [/quote] WTF!!! turtle pie in English implies to XXXXX Whatever meaning it takes, I am not "turtle pie". I have a feeling that you are somewhere else, are you?[/quote] Sorry for my poor english...do you mean I know you ? I don't think I know you,but this talk makes great fun, shall we continue?Or can I get your QQ or Wechat?
loong0306 2014-08-14
  • 打赏
  • 举报
回复
学到了,不愧是大神
  • 打赏
  • 举报
回复
引用 9 楼 luqiang2014 的回复:
[quote=引用 8 楼 micropentium6 的回复:] [quote=引用 7 楼 luqiang2014 的回复:] [quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 luqiang2014 的回复:] Are you turtle pie?Your english is pretty good.
To 逗比: do u know what turtle pie is?[/quote] 海归pie~[/quote] http://www.urbandictionary.com/define.php?term=Turtle%20Pie Don't worry, you don't want to know the mistake I made in French...[/quote] You see, am I right? [/quote] WTF!!! turtle pie in English implies to XXXXX Whatever meaning it takes, I am not "turtle pie". I have a feeling that you are somewhere else, are you?
rs232的日常 2014-08-13
  • 打赏
  • 举报
回复
引用 8 楼 micropentium6 的回复:
[quote=引用 7 楼 luqiang2014 的回复:]
[quote=引用 6 楼 micropentium6 的回复:]
[quote=引用 5 楼 luqiang2014 的回复:]
Are you turtle pie?Your english is pretty good.


To 逗比: do u know what turtle pie is?[/quote]
海归pie~[/quote]


http://www.urbandictionary.com/define.php?term=Turtle%20Pie

Don't worry, you don't want to know the mistake I made in French...[/quote]

You see, am I right?

  • 打赏
  • 举报
回复
引用 7 楼 luqiang2014 的回复:
[quote=引用 6 楼 micropentium6 的回复:] [quote=引用 5 楼 luqiang2014 的回复:] Are you turtle pie?Your english is pretty good.
To 逗比: do u know what turtle pie is?[/quote] 海归pie~[/quote] http://www.urbandictionary.com/define.php?term=Turtle%20Pie Don't worry, you don't want to know the mistake I made in French...
rs232的日常 2014-08-12
  • 打赏
  • 举报
回复
引用 6 楼 micropentium6 的回复:
[quote=引用 5 楼 luqiang2014 的回复:] Are you turtle pie?Your english is pretty good.
To 逗比: do u know what turtle pie is?[/quote] 海归pie~
  • 打赏
  • 举报
回复
引用 5 楼 luqiang2014 的回复:
Are you turtle pie?Your english is pretty good.
To 逗比: do u know what turtle pie is?
rs232的日常 2014-08-12
  • 打赏
  • 举报
回复
引用 4 楼 micropentium6 的回复:
[quote=引用 2 楼 luqiang2014 的回复:] 先了解GCC命令行编译吧,makefile也是根据命令行的参数来编写的,你需要调用一个静态库,最简单的方法就是(假设生成test可执行文件,libcrexr64.a在当前路径)
gcc -o test test.c libcrexr64.a
makefile内容如下:
test:test.c
	gcc -o test test.c libcrexr64.a
clean:
	rm -fr *.o *~
更全面一点的命令如下:
gcc -o test test.c -L. -lcrexr64
其中,-L.表示在当前目录(.)中查找函数库,-lcrexr64表示使用名为libcrexr64.a的函数库,相应的makefile你应该会自己写吧?
A more general approach though, if both static and shared libraries reside at the same place, would be adding -static flag for gcc. This will force linker to look for static library first. The default behavior is always shared lib first.[/quote] Are you turtle pie?Your english is pretty good.
  • 打赏
  • 举报
回复
引用 2 楼 luqiang2014 的回复:
先了解GCC命令行编译吧,makefile也是根据命令行的参数来编写的,你需要调用一个静态库,最简单的方法就是(假设生成test可执行文件,libcrexr64.a在当前路径)
gcc -o test test.c libcrexr64.a
makefile内容如下:
test:test.c
	gcc -o test test.c libcrexr64.a
clean:
	rm -fr *.o *~
更全面一点的命令如下:
gcc -o test test.c -L. -lcrexr64
其中,-L.表示在当前目录(.)中查找函数库,-lcrexr64表示使用名为libcrexr64.a的函数库,相应的makefile你应该会自己写吧?
A more general approach though, if both static and shared libraries reside at the same place, would be adding -static flag for gcc. This will force linker to look for static library first. The default behavior is always shared lib first.
竹影半墙 2014-08-11
  • 打赏
  • 举报
回复
搜 “跟我一起写Makefile”
rs232的日常 2014-08-11
  • 打赏
  • 举报
回复
先了解GCC命令行编译吧,makefile也是根据命令行的参数来编写的,你需要调用一个静态库,最简单的方法就是(假设生成test可执行文件,libcrexr64.a在当前路径)
gcc -o test test.c libcrexr64.a
makefile内容如下:
test:test.c
	gcc -o test test.c libcrexr64.a
clean:
	rm -fr *.o *~
更全面一点的命令如下:
gcc -o test test.c -L. -lcrexr64
其中,-L.表示在当前目录(.)中查找函数库,-lcrexr64表示使用名为libcrexr64.a的函数库,相应的makefile你应该会自己写吧?
加载更多回复(1)

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧