我成立CMakeLists這樣的:如何使用GTK +設置CMakeLists?
project(physiotreapy)
set(HEDEAR_FILES Physiotreapy.h)
set(SOURCE_FILES Physiotreapy.cpp)
add_library(libphysiotreapy STATIC ${SOURCE_FILES})
target_include_directories(libphysiotreapy PUBLIC .)
add_executable(physiotreapy ${SOURCE_FILES} main.cpp)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})
target_link_libraries(physiotreapy libphysiotreapy)
但是當我嘗試運行這段代碼:
#include <gtk/gtk.h>
int main (int argc, char *argv[]) {
GtkWidget *okno;
gtk_init(&argc,&argv);
okno = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (okno);
gtk_main();
return 0;
}
我得到一些錯誤:
/cygdrive/C /用戶/ Mateusz/Desktop/My project/projects/physiotreapy/main.cpp:11:undefined reference to gtk_init_abi_check' /cygdrive/c/Users/Mateusz/Desktop/My project/projects/physiotreapy/main.cpp:11:(.text+0x35): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
gtk_init_abi_check' /cygdrive/c/Users/Mateusz/Desktop/My project/projects/physiotreapy/main.cpp:12:undefined reference to gtk_window_new' /cygdrive/c/Users/Mateusz/Desktop/My project/projects/physiotreapy/main.cpp:12:(.text+0x3f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
gtk_window_new' /cygdrive/c/Users/Mateusz/Desktop/My project/projects/physiotreapy/main.cpp:13:undefined reference to gtk_widget_show' /cygdrive/c/Users/Mateusz/Desktop/My project/projects/physiotreapy/main.cpp:13:(.text+0x4f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
gtk_widget_show' /cygdrive/c/Users/Mateusz/Desktop/My project/projects /physiotreapy/main.cpp:15:未定義的引用gtk_main' /cygdrive/c/Users/Mateusz/Desktop/My project/projects/physiotreapy/main.cpp:15:(.text+0x54): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
進入主循環
只要我這樣做,我有一個CMakeLists – SpeedClimber
問題一旦你確保'pkg-config'的路徑在PATH中,它應該可以工作。 – TingPing