日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux里c库和gnu c库,Linux下的C的库文件和头文件有什么区别-

發布時間:2025/4/16 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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編譯器默認情況下就在這兩個目錄中搜索庫文件。

如果你需要連接的庫文件不在這默認路徑中,就得指定你這個庫文件的明確路徑了??墒菙祵W函數庫也需要連接啊 它也是在標準庫中啊原帖由 奧丁@

于 2008-3-25 01:16 發表

http://bbs.chinaunix.net/images/common/back.gif

可是數學函數庫也需要連接啊 它也是在標準庫中啊

<>

14.3 做一些簡單的三角函數運算, 也引用了 #include

, 可

是一直得到編譯錯誤 “unde?ned: 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的库文件和头文件有什么区别-的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。