linux里c库和gnu c库,Linux下的C的库文件和头文件有什么区别-
Linux下的C的库文件和头文件有什么区别-
(2012-04-10 01:16:57)
标签:
linux
杂谈
Linux下的C的库文件和头文件有什么区别?刚刚接触 这里有点没搞清楚
如果按我的理解
头是声明
库是定义
但是为什么有的文件编译的时候还要特意连接一下库呢?回复 #1 奥丁@
的帖子简单地说,头文件中只有函数的声明,而在库文件中却有函数的定义这些。那也就是说LINUX下规定编译时需要库的位置?原帖由 奥丁@
于 2008-3-25 00:54 发表
http://bbs.chinaunix.net/images/common/back.gif
那也就是说LINUX下规定编译时需要库的位置?
标准的系统库文件一般在/usr/lib/和/lib/中,C编译器默认情况下就在这两个目录中搜索库文件。
如果你需要连接的库文件不在这默认路径中,就得指定你这个库文件的明确路径了。可是数学函数库也需要连接啊 它也是在标准库中啊原帖由 奥丁@
于 2008-3-25 01:16 发表
http://bbs.chinaunix.net/images/common/back.gif
可是数学函数库也需要连接啊 它也是在标准库中啊
<>
14.3 做一些简单的三角函数运算, 也引用了 #include
, 可
是一直得到编译错误 “undefined: sin” (函数 sin 未定义)。
确定你真的连接了数学函数库 (math library)。例如, 在 Unix 或Linux 系统
中, 有一个存在了很久的bug, 你需要把参数 -lm 加在编译或连接命令行的最后。
参见问题13.18, 13.19 和14.2。原帖由 奥丁@ 于 2008-3-25 01:16 发表
http://bbs.chinaunix.net/images/common/back.gif
可是数学函数库也需要连接啊 它也是在标准库中啊
gcc编译完毕会调用ld并缺省加上-lc链接libc/libgcc, 但是并不会链接数学库libm.
简单例子:
#include
#include
int
main(void)
{
doubled;
d = 2.0;
(void)printf("sqrt(%lf)=%lf\n",
d, sqrt(d));
return (0);
}
$ gcc -Wl,--verbose math.c -o math
GNU ld version 2.15 2004-05-23
Supported emulations:
elf_i386_fbsd
elf_x86_64_fbsd
using internal linker script:
==================================================
OUTPUT_FORMAT("elf64-x86-64",
"elf64-x86-64",
"elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
PROVIDE (__executable_start = 0x400000); . = 0x400000 +
SIZEOF_HEADERS;
.interp : { *(.interp) }
.hash : { *(.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d: { *(.gnu.version_d) }
.gnu.version_r: { *(.gnu.version_r) }
.rel.dyn :
{
*(.rel.init)
*(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
*(.rel.fini)
*(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
*(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
*(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
*(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
*(.rel.ctors)
*(.rel.dtors)
*(.rel.got)
*(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
}
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
}
.rel.plt : { *(.rel.plt) }
.rela.plt : { *(.rela.plt) }
.init :
{
KEEP (*(.init))
} =0x90909090
.plt : { *(.plt) }
.text :
{
*(.text .stub .text.* .gnu.linkonce.t.*)
*(.gnu.warning)
} =0x90909090
.fini :
{
KEEP (*(.fini))
} =0x90909090
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) }
. = ALIGN (0x100000) - ((0x100000 - .) & (0x100000
- 1)); . = DATA_SEGMENT_ALIGN (0x100000, 0x1000);
. = ALIGN(64 / 8);
PROVIDE (__preinit_array_start = .);
.preinit_array : { *(.preinit_array) }
PROVIDE (__preinit_array_end = .);
PROVIDE (__init_array_start = .);
.init_array : { *(.init_array) }
PROVIDE (__init_array_end = .);
PROVIDE (__fini_array_start = .);
.fini_array : { *(.fini_array) }
PROVIDE (__fini_array_end = .);
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
.tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
.eh_frame : { KEEP (*(.eh_frame)) }
.gcc_except_table : { *(.gcc_except_table) }
.dynamic : { *(.dynamic) }
.ctors :
{
KEEP (*crtbegin*.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin*.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.got : { *(.got.plt) *(.got) }
_edata = .;
PROVIDE (edata = .);
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(64 / 8);
}
. = ALIGN(64 / 8);
_end = .;
PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
.debug_srcinfo0 : { *(.debug_srcinfo) }
.debug_sfnames0 : { *(.debug_sfnames) }
.debug_aranges0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo0 : { *(.debug_macinfo) }
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames0 : { *(.debug_varnames) }
/DISCARD/ : { *(.note.GNU-stack) }
}
==================================================
attempt to open /usr/lib/crt1.o succeeded
/usr/lib/crt1.o
attempt to open /usr/lib/crti.o succeeded
/usr/lib/crti.o
attempt to open /usr/lib/crtbegin.o succeeded
/usr/lib/crtbegin.o
attempt to open /var/tmp//ccgKyaAa.o succeeded
/var/tmp//ccgKyaAa.o
attempt to open /usr/lib/libgcc.so failed
attempt to open /usr/lib/libgcc.a succeeded
attempt to open /usr/lib/libc.so succeeded
-lc (/usr/lib/libc.so)
attempt to open /usr/lib/libgcc.so failed
attempt to open /usr/lib/libgcc.a succeeded
attempt to open /usr/lib/crtend.o succeeded
/usr/lib/crtend.o
attempt to open /usr/lib/crtn.o succeeded
/usr/lib/crtn.o
/var/tmp//ccgKyaAa.o(.text+0x24): In function `main':
: undefined reference to `sqrt'
$ gcc -Wlhttp://www.0813seo.com,--verbose math.c -o math -lm
GNU ld version 2.15 2004-05-23
Supported emulations:
elf_i386_fbsd
elf_x86_64_fbsd
using internal linker script:
==================================================
OUTPUT_FORMAT("elf64-x86-64",
"elf64-x86-64",
"elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
PROVIDE (__executable_start = 0x400000); . = 0x400000 +
SIZEOF_HEADERS;
.interp : { *(.interp) }
.hash : { *(.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d: { *(.gnu.version_d) }
.gnu.version_r: { *(.gnu.version_r) }
.rel.dyn :
{
*(.rel.init)
*(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
*(.rel.fini)
*(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
*(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
*(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
*(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
*(.rel.ctors)
*(.rel.dtors)
*(.rel.got)
*(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
}
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
}
.rel.plt : { *(.rel.plt) }
.rela.plt : { *(.rela.plt) }
.init :
{
KEEP (*(.init))
} =0x90909090
.plt : { *(.plt) }
.text :
{
*(.text .stub .text.* .gnu.linkonce.t.*)
*(.gnu.warning)
} =0x90909090
.fini :
{
KEEP (*(.fini))
} =0x90909090
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) }
. = ALIGN (0x100000) - ((0x100000 - .) & (0x100000
- 1)); . = DATA_SEGMENT_ALIGN (0x100000, 0x1000);
. = ALIGN(64 / 8);
PROVIDE (__preinit_array_start = .);
.preinit_array : { *(.preinit_array) }
PROVIDE (__preinit_array_end = .);
PROVIDE (__init_array_start = .);
.init_array : { *(.init_array) }
PROVIDE (__init_array_end = .);
PROVIDE (__fini_array_start = .);
.fini_array : { *(.fini_array) }
PROVIDE (__fini_array_end = .);
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
.tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
.eh_frame : { KEEP (*(.eh_frame)) }
.gcc_except_table : { *(.gcc_except_table) }
.dynamic : { *(.dynamic) }
.ctors :
{
KEEP (*crtbegin*.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin*.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.got : { *(.got.plt) *(.got) }
_edata = .;
PROVIDE (edata = .);
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(64 / 8);
}
. = ALIGN(64 / 8);
_end = .;
PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
.debug_srcinfo0 : { *(.debug_srcinfo) }
.debug_sfnames0 : { *(.debug_sfnames) }
.debug_aranges0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0
分享:
喜欢
0
赠金笔
加载中,请稍候......
评论加载中,请稍候...
发评论
登录名: 密码: 找回密码 注册记住登录状态
昵 称:
评论并转载此博文
发评论
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。
linux里c库和gnu c库,Linux下的C的库文件和头文件有什么区别-相关推荐
- C++库文件和头文件编写教程
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 「本文介绍了在Linux系统下生成库文件,以及编写头文件来使用该库 ...
- VC 6.0中添加库文件和头文件
VC 6.0中添加库文件和头文件 分类: VC/VS 加头文件包含 VC6.0中: VC6.0默认include包含路径:Tools>Options>Directories>Incl ...
- Linux下利用protoc命令生成protobuf的头文件和源文件,根据mesType.proto文件
Linux下利用protoc命令生成protobuf的头文件和源文件,根据mesType.proto文件 protobuf的message文件为 msgType.proto 生成c++头文件和源文件的 ...
- C语言-库文件与头文件
本文是对目标文件和链接文件两个概念的进化 创建一个文件print.o,里面有一个函数printff用来打印 创建一个文件main.c,调用printff函数 1:创建print.c文件,并添加如下代码 ...
- linux怎么添加头文件目录下,linux下编写c++,include的那些头文件在什么地方?
炎炎设计 C/C++程序在linux下被编译和连接时,GCC/G++会查找系统默认的include和link的路径,以及自己在编译命令中指定的路径.自己指定的路径就不说了,这里说明一下系统自动搜索的路 ...
- linux 常用头文件,(常用头文件详解.doc
(常用头文件详解 linux常用头文件详解 POSIX标准定义的头文件??????? 目录项 ???????? 文件控制 ??? 文件名匹配类型 ??? 路径名模式匹配类型 ??????? 组文件 ? ...
- linux安装中文字体 yum,CentOS 7.6环境下安装中文字体库
这样的对象依赖于本地的字段.新装的linux没有安装字段库,和相应的字体. 1.fc-list查看字体库 2.yum -y install fontconfig安装 3.安装好后/usr/share目 ...
- linux里的挂载错误无法开机怎么办,Linux基础知识 - 开机挂载错误
开机挂载错误 我们可以在/etc/fstab设置开启挂载,不过如果在/etc/fstab定义了挂载信息可是实际并不存在此分区,开机进行分区挂载时就会产生错误,导致我们不能进入操作系统,如下图 根源在于 ...
- linux里数据库退格,Oracle Database for Linux 不能使用退格键
方法一:要使用退格键的时候,同时按住ctrl+backspace 方法二:在任意一个启动脚本中添加如下内容 [Oracle@night ~]$ tail -1 .bash_profile stty ...
最新文章
- 客快物流大数据项目(四):大数据项目为什么使用Docker
- unity 灯笼_如何创建将自己拼成文字的漂亮灯笼
- 如何使用VirtualBox与GNS3搭建思科设备实验环境
- linux系统中tar命令的使用,linux 系统的tar命令使用方法详解
- linux版本查看命令多少位,查看linux系统版本命令32位还是64位
- Git/SQL/正则表达式练习平台
- jQuery.Validate验证库 2
- 计算机基础--操作系统基础
- java中menu用法_Android Menu用法全面讲解
- windows 10 80端口占用处理方法_已迁移
- Redis 安装部署介绍
- 美国亚马逊账号被锁定之后
- 升级Spring Boot内嵌Tomcat版本
- 大数据影响下的专题地图编制
- Themeforest 热卖 Shopify 主题 六折促销活动进行中
- web数字可视化有哪些实现的方法?
- r语言C指数的置信区间,用R语言求置信区间
- Tita绩效宝:绩效管理评语范例
- 当iPhoneXR 升级 卡死在白苹果读条界面,已解决
- 推荐一款免费的数据库管理工具,比Navicat还要好用,功能还很强大
热门文章
- [Swift]LeetCode513. 找树左下角的值 | Find Bottom Left Tree Value
- c++入门之 再话类
- 关于JAVA编译时找不到自定义包的问题
- P1133 教主的花园
- for循坏的穷举与迭代,while、do while循环
- 翻译器DIY它———算在英文文本中的单词数,字符和行数
- 【转载】关于阿里巴巴的问题
- 将在2021年改变商业格局的10项技术
- “中文四六级”考试来了!《国际中文教育中文水平等级标准》发布
- C#版本与.NET版本对应关系以及各版本的特性