用cmake编译gtk程序:gssdp

转载时请注明出处和作者联系方式:http://blog.csdn.net/mimepp
作者联系方式:YU TAO <yut616 at sohu dot com>

用cmake编译gtk程序:gssdp

使用cmake来编译gtk的程序,这里用gupnp中的gssdp的例子来讲解一下。

1、gssdp代码
svn co http://svn.o-hand.com/repos/gupnp/trunk/gssdp gssdp

2、安装cmake
apt-get install cmake

3、编写CMakeLists.txt

project (GSSDP)

include_directories (/usr/include/glib-2.0 /usr/lib/glib-2.0/include
/usr/include/gtk-2.0 /usr/lib/gtk-2.0/include /usr/include/atk-1.0
/usr/include/cairo /usr/include/pango-1.0 /usr/include/freetype2
/usr/include/libpng12 /usr/include/pixman-1 ./ /usr/local/include/gssdp-1.0
/usr/include/libglade-2.0 /usr/include/libsoup-2.4)
aux_source_directory (libgssdp LIB_FILE)
add_library (gssdp SHARED ${LIB_FILE})

set (TOOL_FILE tools/gssdp-device-sniffer.c)
add_executable (gssdp-device-sniffer ${TOOL_FILE} ${LIB_FILE} )
target_link_libraries (gssdp-device-sniffer gssdp soup-2.4 gtk-x11-2.0
gdk-x11-2.0 atk-1.0 gdk_pixbuf-2.0 m pangocairo-1.0 pango-1.0 cairo
gobject-2.0 gmodule-2.0 dl glib-2.0 glade-2.0)

4、解释
其中include的内容和连接库的内容可以使用pkg-config --cflags gtk+-2.0和pkg-config --libs gtk+-2.0里获得,并将他们前面的"-I", "-l"去掉,加入到上面的CMakeLists.txt中

5、编译
在gssdp目录下,建立一个build目录

gssdp/build# cmake ..
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Check size of void*
-- Check size of void* - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yutao/study/gupnp_svn/gssdp/build


gssdp/build# make
Scanning dependencies of target gssdp
[  7%] Building C object CMakeFiles/gssdp.dir/libgssdp/gssdp-socket-source.o
[ 15%] Building C object CMakeFiles/gssdp.dir/libgssdp/gssdp-marshal.o
[ 23%] Building C object CMakeFiles/gssdp.dir/libgssdp/gssdp-error.o
[ 30%] Building C object
CMakeFiles/gssdp.dir/libgssdp/gssdp-resource-browser.o
[ 38%] Building C object CMakeFiles/gssdp.dir/libgssdp/gssdp-resource-group.o
[ 46%] Building C object CMakeFiles/gssdp.dir/libgssdp/gssdp-client.o
Linking C shared library libgssdp.so
[ 46%] Built target gssdp
Scanning dependencies of target gssdp-device-sniffer
[ 53%] Building C object
CMakeFiles/gssdp-device-sniffer.dir/tools/gssdp-device-sniffer.o
[ 61%] Building C object
CMakeFiles/gssdp-device-sniffer.dir/libgssdp/gssdp-socket-source.o
[ 69%] Building C object
CMakeFiles/gssdp-device-sniffer.dir/libgssdp/gssdp-marshal.o
[ 76%] Building C object
CMakeFiles/gssdp-device-sniffer.dir/libgssdp/gssdp-error.o
[ 84%] Building C object
CMakeFiles/gssdp-device-sniffer.dir/libgssdp/gssdp-resource-browser.o
[ 92%] Building C object
CMakeFiles/gssdp-device-sniffer.dir/libgssdp/gssdp-resource-group.o
[100%] Building C object
CMakeFiles/gssdp-device-sniffer.dir/libgssdp/gssdp-client.o
Linking C executable gssdp-device-sniffer
[100%] Built target gssdp-device-sniffer


6、运行
#cd ../tools
#../build/gssdp-device-sniffer

7、link情况
#ldd ../build/gssdp-device-sniffer
        linux-gate.so.1 =>  (0xb7f80000)
        libgssdp.so => /home/yutao/study/gupnp_svn/gssdp/build/libgssdp.so (0xb7f74000)
即link的内容是自己编译出来的libgssdp.so

8、编译目录信息

build# ls 
CMakeCache.txt  CMakeFiles  cmake_install.cmake  gssdp-device-sniffer  libgssdp.so  Makefile
9、编译中可能需要的库
apt-get install libsoup2.4-dev

你可能感兴趣的:(object,File,library,compiler,dependencies,gtk)