当前位置: 技术问答>linux和unix
linux系统 anjuta gtk+工程静态编译
来源: 互联网 发布时间:2017-01-02
本文导语: 本帖最后由 songqier 于 2011-08-19 11:22:59 编辑 我在anjuta上用gtk+2.0写了一个软件,考虑到软件的移植问题,在没有安装gtk+的linux系统上也能运行,所以尝试静态编译。首先我将gtk+2.0静态编译,并将系统的相关环境变量做...
root@song-ubuntu:/opt# export CPPFLAGS="-I/opt/gtk/include"
root@song-ubuntu:/opt# export LDFLAGS="-L/opt/gtk/lib"
root@song-ubuntu:/opt# export PKG_CONFIG_PATH="/opt/gtk/lib/pkgconfig"
root@song-ubuntu:/opt# export LD_LIBRARY_PATH="/opt/gtk/lib"
root@song-ubuntu:/opt# export PATH="/opt/gtk/bin:$PATH"
上面的路径为我静态编译gtk+的生成路径。
然后就在这个Terminal中开始静态编译我的工程,因为anjuta采用自动生成makefile,所以先
./configure --enable-maintainer-mode 'CFLAGS=-g -O0' 'CXXFLAGS=-g -O0' 'JFLAGS=-g -O0' 'FFLAGS=-g -O0' --enable-shared=no --enable-static=yes
然后make,但是生成的可执行文件的大小仍和原来动态编译时的大小一样大。查看make的过程,发现链接的时候全是链接的.so动态库,而没有链接静态库.a(我的系统上,每一个.so都有一个相应的相同路径的.a存在)。
make过程的链接部分显示为:
libtool: link: gcc -g -g -O0 -Wl,--export-dynamic -o filemon filemon-callbacks.o filemon-main.o filemon-filemonctl.o filemon-filterdialog.o filemon-gtkcontrol.o filemon-setdialog.o filemon-logtotxt.o -pthread -L/opt/gtk/lib /opt/gtk/lib/libgtk-x11-2.0.so /opt/gtk/lib/libgdk-x11-2.0.so /usr/lib/libatk-1.0.so /usr/lib/libpangoft2-1.0.so /usr/lib/libpangocairo-1.0.so -lXext -lXrender -lXinerama -lXrandr -lXcursor -lXcomposite -lXdamage -lgdk_pixbuf-2.0 -lm /usr/lib/libgio-2.0.so -lXfixes /usr/lib/libcairo.so -lX11 -lpng12 /usr/lib/libpango-1.0.so /usr/lib/libfreetype.so -lz -lfontconfig /usr/lib/libgobject-2.0.so /usr/lib/libgmodule-2.0.so /usr/lib/libgthread-2.0.so -lrt /usr/lib/libglib-2.0.so -pthread -Wl,-rpath -Wl,/opt/gtk/lib -Wl,-rpath -Wl,/opt/gtk/lib
另外anjuta提供的configure的help如下:
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/filemon]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-maintainer-mode enable make rules and dependencies not useful
(and sometimes confusing) to the casual installer
--disable-dependency-tracking speeds up one-time build
--enable-dependency-tracking do not reject slow dependency extractors
--disable-nls do not use Native Language Support
--enable-shared[=PKGS] build shared libraries [default=yes]
--enable-static[=PKGS] build static libraries [default=yes]
--enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-pic try to use only PIC/non-PIC objects [default=use
both]
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L if you have libraries in a
nonstandard directory
LIBS libraries to pass to the linker, e.g. -l
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if
you have headers in a nonstandard directory
CPP C preprocessor
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
FILEMON_CFLAGS
C compiler flags for FILEMON, overriding pkg-config
FILEMON_LIBS
linker flags for FILEMON, overriding pkg-config
各位大神大侠们,帮忙看看这是神马缘故。难道是gtk程序不能静态编译?这可了得,每次用gtk写个东西出来,移植到其他PC上的时候都要背个gtk库?这也太麻烦了
|
GTK不是不能静态链接
而是他的许可授权问题
GTK+是LGPL授权协议的
意味着你可以随意动态链接,但如果静态链接就得公开全部源代码
而是他的许可授权问题
GTK+是LGPL授权协议的
意味着你可以随意动态链接,但如果静态链接就得公开全部源代码
|
肯定不对啊
静态链接怎么会有-Wl,--export-dynamic 这种导出
lz想把gtk静态链接干啥啊,Linux下不都自带gtk库么
windows下才可能考虑把它静态链接
静态链接怎么会有-Wl,--export-dynamic 这种导出
lz想把gtk静态链接干啥啊,Linux下不都自带gtk库么
windows下才可能考虑把它静态链接
|
gkt通常不提供静态编译库,依赖的东西太多。
你一般很难找一台没安装gtk的linux机器,除非是不带图形界面的服务器。
你一般很难找一台没安装gtk的linux机器,除非是不带图形界面的服务器。
|
一个危险的办法是把系统的gtk卸载了。。
印象中Makefile工程对库的寻找好像是有一个顺序的,其实大部分软件都不是通过静态编译实现的,一般是独立放一个文件夹,里边放上必要的动态链接库
印象中Makefile工程对库的寻找好像是有一个顺序的,其实大部分软件都不是通过静态编译实现的,一般是独立放一个文件夹,里边放上必要的动态链接库