當前位置:首頁 » 編程軟體 » gcc編譯庫文件

gcc編譯庫文件

發布時間: 2023-01-04 21:28:49

① 如何在XCode中使用gcc編譯生成的.a庫文件

1. 把你的.a文件添加到^projectName下的任意一個組里(例如默認的Classes組)。
2. 找到Target > ^targetName,在這個^targetName下會有Link Binary With Libraries。把你已經在某組里的那個.a文件拖到Link Binary With Libraries這個Build Phase中。(也可能同時也要添加到某個Copy的Build Phase中...)
3. 提供一個可用的頭文件。
4. Build and Go.
封裝的話,標準的Cocoa做法是用Cocoa Framework。也就是在新建工程的時候,選擇Cocoa Framework。

② 如何用GCC在linux下編譯C語言程序

在Linux下面,如果要編譯一個C語言源程序,我們要使用GNU的gcc編譯器,假設我們有下面一個非常簡單的源程序(hello.c):


int main(int argc,char **argv)


{


printf("Hello Linux ");


}


要編譯這個程序,我們只要在命令行下執行:


gcc -o hello hello.c


gcc 編譯器就會為我們生成一個hello的可執行文件.執行./hello就可以看到程
序的輸出結果了

③ gcc編譯時默認使用的庫在哪個目錄

看你包含的
頭文件
和使用的函數啊~兩者包含的函數不一樣~
你要是使用fopen/memcpy等等這樣標准C的函數,當然會在鏈接時使用到標准C庫(ANSI
C),如果你使用了read/write這些glibc庫實現的函數,肯定就在鏈接時使用到glibc庫~
具體使用了什麼庫,要看你調用的函數了~可能不會僅僅只包含一個庫~
Linux下,庫的路徑一般是:/lib,/usr/lib,/usr/local/lib等,這些路徑一般會在/etc/ld.so.conf
中標記出來,如果需要添加特殊位置的庫,可以把庫的路徑添加到/etc/ld.so.conf中去,並且執行ldconfig來使得新路徑立即生效~

④ LInux 如何使用GCC編譯器將一個文件夾下的100個.o文件打包成一個靜態庫文件(.a)

你已經用gcc編譯出目標文件了,用ar工具打包成.a文件就行了啊,示例:


如上圖,假設我有test1.c,test2.c兩個源文件,先使用gcc -c *.c將源文件編譯成目標文件,可以看到,生成了test1.o,test2.o兩個目標文件,然後,使用ar命令:ar crv libtest.a *.o將該目錄下的所有目標文件打包生成了libtest.a文件。這樣,你在編譯的時候就可以直接使用這個靜態庫了。

⑤ 怎麼用gcc編譯文件

在終端中輸入 gcc 文件名 -o 目標文件名x0dx0a然後 ./目標文件名 就行了,沒有目標文件名,自動存為 ax0dx0a執行 ./a 就行了。x0dx0ax0dx0a在使用Gcc編譯器的時候,我們必須給出一系列必要的調用參數和文件名稱。GCC編譯器的調用參數大約有100多個,其中多數參數我們可能根本就用不到,這里只介紹其中最基本、最常用的參數。x0dx0aGCC最基本的用法是∶gcc [options] [filenames]x0dx0a其中options就是編譯器所需要的參數,filenames給出相關的文件名稱。x0dx0a-c,只編譯,不連接成為可執行文件,編譯器只是由輸入的.c等源代碼文件生成.o為後綴的目標文件,通常用於編譯不包含主程序的子程序文件。x0dx0a-o output_filename,確定輸出文件的名稱為output_filename,同時這個名稱不能和源文件同名。如果不給出這個選項,gcc就給出預設的可執行文件a.out。x0dx0a-g,產生符號調試工具(GNU的gdb)所必要的符號資訊,要想對源代碼進行調試,我們就必須加入這個選項。x0dx0a-O,對程序進行優化編譯、連接,採用這個選項,整個源代碼會在編譯、連接過程中進行優化處理,這樣產生的可執行文件的執行效率可以提高,但是,編譯、連接的速度就相應地要慢一些。x0dx0a-O2,比-O更好的優化編譯、連接,當然整個編譯、連接過程會更慢。x0dx0a-Idirname,將dirname所指出的目錄加入到程序頭文件目錄列表中,是在預編譯過程中使用的參數。C程序中的頭文件包含兩種情況∶x0dx0aA)#include x0dx0aB)#include 「myinc.h」x0dx0a其中,A類使用尖括弧(< >),B類使用雙引號(「 」)。對於A類,預處理程序cpp在系統預設包含文件目錄(如/usr/include)中搜尋相應的文件,而B類,預處理程序在目標文件的文件夾內搜索相應文件。 x0dx0ax0dx0aGCC執行過程示例x0dx0ax0dx0a示例代碼 a.c:x0dx0a#include x0dx0aint main()x0dx0a{x0dx0aprintf("hello\n");x0dx0a}x0dx0a預編譯過程:x0dx0a這個過程處理宏定義和include,並做語法檢查。x0dx0a可以看到預編譯後,代碼從5行擴展到了910行。x0dx0agcc -E a.c -o a.ix0dx0acat a.c | wc -lx0dx0a5x0dx0acat a.i | wc -lx0dx0a910x0dx0a編譯過程:x0dx0a這個階段,生成匯編代碼。x0dx0agcc -S a.i -o a.sx0dx0acat a.s | wc -lx0dx0a59x0dx0a匯編過程:x0dx0a這個階段,生成目標代碼。x0dx0a此過程生成ELF格式的目標代碼。x0dx0agcc -c a.s -o a.ox0dx0afile a.ox0dx0aa.o: ELF 64-bit LSB relocatable, AMD x86-64, version 1 (SYSV), not strippedx0dx0a鏈接過程:x0dx0a鏈接過程。生成可執行代碼。鏈接分為兩種,一種是靜態鏈接,另外一種是動態鏈接。使用靜態鏈接的好處是,依賴的動態鏈接庫較少,對動態鏈接庫的版本不會很敏感,具有較好的兼容性;缺點是生成的程序比較大。使用動態鏈接的好處是,生成的程序比較小,佔用較少的內存。x0dx0agcc a.o -o ax0dx0a程序運行:x0dx0a./ax0dx0ahellox0dx0a編輯本段x0dx0aGCC編譯簡單例子x0dx0ax0dx0a編寫如下代碼:x0dx0a#include x0dx0aint main()x0dx0a{x0dx0aprintf("hello,world!\n");x0dx0a}x0dx0a執行情況如下:x0dx0agcc -E hello.c -o hello.ix0dx0agcc -S hello.i -o hello.sx0dx0agcc -c hello.s -o hello.ox0dx0agcc hello.c -o hellox0dx0a./hellox0dx0ahello,world!

⑥ 萌新求助、gcc編譯c++動態庫編寫makefile

假設有下面幾個c++文件:
wherewhen.h wherewhen.c
countdown.h countdown.c 包含了math.h, 需要連接庫文件
main.c 主函數, main.c 包含了兩個頭文件 wherewhen.h and countdown.h
1、第一種編譯方法:
g++ -Wall -g wherewhen.c countdown.c main.c -lm -o myprogram
生成可執行文件myprogram
2、第二中編譯方法, 分別編譯各個文件:
g++ -Wall -g -c wherewhen.c
g++ -Wall -g -c countdown.c
g++ -Wall -g -c main.c
g++ -g wherewhen.o countdown.o main.o -lm -o myprogram

⑦ gcc交叉編譯怎麼找頭文件及lib庫的

是在specs裡面讀取的路徑信息。
命令行中鍵入 gcc -v
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --ver
bose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libe
xecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-langu
ages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --
enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-
awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-thre
ads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptio
ns --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)

注意「--prefix=/usr」 以及「--libdir=/usr/lib 」
表示gcc ld as 等可執行文件安裝在/usr/bin,而libc.a 等文件是在/usr/lib中。
壓縮交叉編譯器時,也是要解壓縮在在--prefix 指定的目錄下。
比如 下載了arm-linux 的交叉編譯器cross-3.3.2.tar.bz2,解壓縮之後,運行 arm-linux-gcc -v
得到 --prefix=/usr/local/arm。那麼就要把 bin lib 等所有的文件和文件夾到/usr/local/arm目錄下。
否則到時候運行arm-linux-gcc hello.c會提示找不到stdio.h 或者 lib.so.6 等

HOWTO Use the GCC specs file

About Specs file
The "gcc" program invoked by users is a convenient front-end driver executable which will invoke other programs in the background such as cc1, as or ld to do its work according to the command line parameter given. A specs file is plain text used to control the default behavior for the "gcc" front-end. The specs file is usually built-in but for flexibility purposes, it can be overridden with an external version.
Basic Specs file modifications
CC will proce a specs file via the following command.
gcc -mpspecs > specs
You may use a text editor of your choice to inspect it. It may be confusing at first, but there are many places of interest. To use the specs file, invoke gcc with -specs= or place it at "/mingw/lib/gcc/mingw32//specs" to make GCC use it by default, where refers to the GCC version installed.
Adding include directories to the search path
& #160;he *cpp: section should be modified. It contains the following by default:
*cpp:
%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}
If "z:\libx\include" needs to be added to the GCC includes search path, it should be changed to the following
*cpp:
%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} -I/z/libx/include
Adding lib directories to the search path
& #160;he *link_libgcc: section should be modified. It contains the following by default:
*link_libgcc:
%D
& #160;f "z:\libx\lib" needs to be added to the GCC library search path, it should be changed to the following
*link_libgcc:
%D -L/z/libx/lib

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:593
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:888
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:581
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:765
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:684
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1012
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:255
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:113
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:806
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:712