我尝试将使用Glade制作的GTK小部件的信号与gtk_builder_connect_signals ()连接起来
,正如文档所说,此功能要求程序使用-Wl,--export-dynamic
Cflags编译并链接到gmodule-export-2.0
。
使用以下命令编译此代码可以成功运行。
/*Command : gcc sample.c -Wall -Wextra -Wl,--export-dynamic `pkg-config --cflags --libs gtk+-3.0 gmodule-export-2.0` -o sample */
#include <gtk/gtk.h>
void add_etdnts(GtkWidget *widget,gpointer data){
g_print("function succefully called");
}
int main(int argc, char *argv[]){
GtkBuilder *builder;
GtkWidget *window;
GError *error = NULL;
gtk_init(&argc,&argv);
builder = gtk_builder_new();
if(! gtk_builder_add_from_file(builder,"style.glade",&error)){
g_warning("%s",error->message);
g_free(error);
return 1;
}
window = GTK_WIDGET(gtk_builder_get_object(builder,"window"));
gtk_builder_connect_signals(builder,NULL);
g_object_unref( G_OBJECT( builder ) );
gtk_widget_show( window );
//Start main loop
gtk_main();
return 0;
}
但由于某些原因,我无法在CLion IDE(LINUX)下编译它,即使将以下行添加到&#34; CMakeLists.txt&#34;
cmake_minimum_required(VERSION 3.6)
project(UI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(GTK 3 REQUIRED gtk)
if(GTK3_FOUND)
include_directories(${GTK3_INCLUDE_DIRS})
set(SOURCE_FILES main.c main.h )
add_executable(UI ${SOURCE_FILES})
target_link_libraries(UI ${GTK3_LIBRARIES})
############# something is wrong here ##############
set(CMAKE_CXX_COMPILER "pkg-config --cflags --libs gtk+-3.0 gmodule-2.0")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} pkg-config --libs gtk+-3.0 gmodule-2.0")
endif()
答案 0 :(得分:1)
set(CMAKE_CXX_COMPILER "pkg-config --cflags --libs gtk+-3.0 gmodule-2.0")
这没有意义:您已将pkg-config设置为c ++编译器。
使用CMake中的pkg-config support:
find_package(PkgConfig)
pkg_check_modules(GTK REQUIRED gtk+-3.0 gmodule-2.0)
...
target_link_libraries(UI ${GTK_LIBRARIES})
target_include_directories(UI ${GTK_INCLUDE_DIRS})