如何在Windows中更轻松地连接gtk库与cmake? [英] How do I link gtk library more easily with cmake in windows?
问题描述
我现在以非常丑陋的方式,通过手动包括所有必需的路径(gtk捆绑在 D:/Tools/gtk+-bundle_2.20.0-20100406_win32
include_directories(D:/Tools/gtk+-bundle_2.20.0-20100406_win32/include/gtk-2.0 D: /Tools/gtk+-bundle_2.20.0-20100406_win32/include/glib-2.0 D:/Tools/gtk+-bundle_2.20.0-20100406_win32/lib/glib-2.0/include D:/Tools/gtk+-bundle_2.20.0-20100406_win32/include / cairo D:/Tools/gtk+-bundle_2.20.0-20100406_win32/include/pango-1.0 D:/Tools/gtk+-bundle_2.20.0-20100406_win32/lib/gtk-2.0/include D:/Tools/gtk+-bundle_2.20.0 -20100406_win32 / include / atk-1.0)
link_directories(D:/Tools/gtk+-bundle_2.20.0-20100406_win32/lib)
target_link_libraries(MyProgram gtk-win32-2.0.lib)
只需添加包含pkg-config在您的gtk-bundle / bin目录中)到您的PATH。
<$> 这是一个用GTK2编写的示例应用程序的CMakeLists.txt:
project(gtk-test)
cmake_minimum_required(VERSION 2.4)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK2 REQUIRED gtk + -2.0)
include_directories($ {GTK2_INCLUDE_DIRS})
link_directories($ {GTK2_LIBRARY_DIRS})
add_executable(gtk-test main.c)
add_definitions($ {GTK2_CFLAGS_OTHER})
target_link_libraries(gtk-test $ {GTK2_LIBRARIES})
我的测试应用程式:
#include< gtk / gtk.h>
int main(char argc,char ** argv)
{
g_print(Hello world!\\\
);
return 0;
}
我在Win XP上测试了CMake 2.4和CMake 2.8以及MinGW,有用。它也应该在MinGW之外工作。
I'm now doing it in a very ugly way by manually including all the required path(the gtk bundle is at D:/Tools/gtk+-bundle_2.20.0-20100406_win32
):
include_directories(D:/Tools/gtk+-bundle_2.20.0-20100406_win32/include/gtk-2.0 D:/Tools/gtk+-bundle_2.20.0-20100406_win32/include/glib-2.0 D:/Tools/gtk+-bundle_2.20.0-20100406_win32/lib/glib-2.0/include D:/Tools/gtk+-bundle_2.20.0-20100406_win32/include/cairo D:/Tools/gtk+-bundle_2.20.0-20100406_win32/include/pango-1.0 D:/Tools/gtk+-bundle_2.20.0-20100406_win32/lib/gtk-2.0/include D:/Tools/gtk+-bundle_2.20.0-20100406_win32/include/atk-1.0)
link_directories(D:/Tools/gtk+-bundle_2.20.0-20100406_win32/lib)
target_link_libraries(MyProgram gtk-win32-2.0.lib)
Just add the directory that contains pkg-config (which is in your gtk-bundle/bin directory) to your PATH. That way, CMake will find it.
Here's a CMakeLists.txt for a sample application written in GTK2:
project (gtk-test)
cmake_minimum_required (VERSION 2.4)
find_package (PkgConfig REQUIRED)
pkg_check_modules (GTK2 REQUIRED gtk+-2.0)
include_directories (${GTK2_INCLUDE_DIRS})
link_directories (${GTK2_LIBRARY_DIRS})
add_executable (gtk-test main.c)
add_definitions (${GTK2_CFLAGS_OTHER})
target_link_libraries (gtk-test ${GTK2_LIBRARIES})
And the main.c file for my test app:
#include <gtk/gtk.h>
int main (char argc, char **argv)
{
g_print ("Hello world!\n");
return 0;
}
I tested it on Win XP with CMake 2.4 and CMake 2.8 and MinGW, and it works. It should also work outside MinGW.
这篇关于如何在Windows中更轻松地连接gtk库与cmake?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!