GCC中同时使用动态和静态库连接的编译

   如何同时同时使用动态和静态库连接,在GCC指令参数中具体参数以下:
    -Wl,-Bstatic -L/usr/local/sqlite-arm-linux/.libs -lsqlite -Wl,-Bdynamic -L/usr/local/arm/3.3.2/lib
 
 具体用途解释:sqlite库静态链接,其它库动态链接。
-Wl,-Bstatic 与-Wl,-Bdynamic参数,从字面意义上能够理解,有静态和动态的意思,可是具体的真正规则在查找了GCC的原版手册上有说明。
 
原文:
Note - if the linker is being invoked indirectly, via a compiler driver (eg gcc) then all the linker command line options should be prefixed by -Wl, (or whatever is appropriate for the particular compiler driver) like this:

gcc -Wl,--startgroup foo.o bar.o -Wl,--endgroup
  
This is important, because otherwise the compiler driver program may silently drop the linker options, resulting in a bad link.

实际上主要针对隐式应用LINKER的参数,用“-Wl,”来标识,,“--startgroup foo.o bar.o -Wl,--endgroup”表示一组,,-Bstatic -Bdynamic 做为关键字与-WL,不可分,在GCC链接库时,默认连接是动态连接,如今用上面的指令限制在连接sqlite库时采用静态连接。
 
-Bstatic 还有三个写法: -dn和-non_shared 和-static

-Bdynamic 还有两个写法:-dy 和-call_shared linux

上面参数“-L/usr/local/sqlite-arm-linux/.libs ”放不放在-Wl,...之间无所谓,由于它只是提供了sqlite动静态库的位置。能够改为下面的参数形式,更直观。

-L/usr/local/sqlite-arm-linux/.libs -L/usr/local/arm/3.3.2/lib -Wl,-dn -lsqlite -Wl,-dy

-Wl,-dn 和 -Wl,-dy成对出现才能起到标题所说的做用。  

关于-Wl,后面的参数还有不少,所有明白我也不能。 sql

还有一个问题值得注意,在-Wl,后面不能有空格,不然会出错! 关于-Wl,option 说明还有一段说明 GCC命令参数的英文原文 -Wl,option Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas. 传递参数option做为linker的一个参数,若是option包含逗号,将在逗号处分割成几个参数。 例如: -Wl,-dn –lsqlite -dn 开始静态连接 -lsqlite 静态连接sqlite库 静态连接完后,而后须要动态连接 -Wl,-dy 从新开始动态连接。
相关文章
相关标签/搜索