当前位置:首页 » 编程软件 » 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 浏览:114
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:806
python股票数据获取 发布:2025-10-20 07:39:44 浏览:712