提问人:aleks_yolp 提问时间:10/10/2021 最后编辑:kaylumaleks_yolp 更新时间:10/10/2021 访问量:222
如何在 linux (ubuntu 21.04) 上创建可执行文件?
How to create executable file on linux (ubuntu 21.04)?
问:
我的 ubuntu 21.04 上有下一个 CMakeLists.txt 文件:
cmake_minimum_required(VERSION 3.10)
# set the project name
project(gtk4-my)
# add the executable
add_executable(gtk4-my gtk4-my.c)
# gtk4
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK4 REQUIRED gtk4)
include_directories(${GTK4_INCLUDE_DIRS})
link_directories(${GTK4_LIBRARY_DIRS})
add_definitions(${GTK4_CFLAGS_OTHER})
# Use the package PkgConfig to detect GTK+ headers/library files
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED gtkmm-3.0)
target_link_libraries(gtk4-my PRIVATE ${GTKMM_LIBRARIES})
# Add other flags to the compiler
target_compile_definitions(gtk4-my PRIVATE ${GTKMM_CFLAGS_OTHER})
# Setup CMake to use GTK+, tell the compiler where to look for headers
# and to the linker where to look for libraries
target_include_directories(gtk4-my PRIVATE ${GTKMM_INCLUDE_DIRS})
target_link_directories(gtk4-my PRIVATE ${GTKMM_LIBRARY_DIRS})
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
我吩咐过: cmake 文件夹
root@user-PC:/home/user/test123# cmake my123
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/test123
一切都很好。
现在我执行命令:并收到以下错误:make
root@user-PC:/home/user/test123# make
[ 50%] Linking C executable gtk4-my
/usr/bin/ld: CMakeFiles/gtk4-my.dir/gtk4-my.c.o: in function `glib_autoptr_clear_GtkApplication':
gtk4-my.c:(.text+0x1b): undefined reference to `g_object_unref'
/usr/bin/ld: CMakeFiles/gtk4-my.dir/gtk4-my.c.o: in function `activate':
gtk4-my.c:(.text+0x5d): undefined reference to `gtk_application_window_new'
/usr/bin/ld: gtk4-my.c:(.text+0x66): undefined reference to `gtk_window_new'
/usr/bin/ld: gtk4-my.c:(.text+0x6f): undefined reference to `gtk_application_get_type'
/usr/bin/ld: gtk4-my.c:(.text+0x81): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: gtk4-my.c:(.text+0x89): undefined reference to `gtk_window_get_type'
/usr/bin/ld: gtk4-my.c:(.text+0x9b): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: gtk4-my.c:(.text+0xa6): undefined reference to `gtk_window_set_application'
/usr/bin/ld: gtk4-my.c:(.text+0xab): undefined reference to `gtk_window_get_type'
/usr/bin/ld: gtk4-my.c:(.text+0xbd): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: gtk4-my.c:(.text+0xcf): undefined reference to `gtk_window_set_default_size'
/usr/bin/ld: gtk4-my.c:(.text+0xdb): undefined reference to `gtk_widget_show'
/usr/bin/ld: gtk4-my.c:(.text+0xe7): undefined reference to `gtk_label_new'
/usr/bin/ld: gtk4-my.c:(.text+0xf0): undefined reference to `gtk_window_get_type'
/usr/bin/ld: gtk4-my.c:(.text+0x102): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: gtk4-my.c:(.text+0x114): undefined reference to `gtk_window_set_child'
/usr/bin/ld: gtk4-my.c:(.text+0x120): undefined reference to `gtk_widget_show'
/usr/bin/ld: gtk4-my.c:(.text+0x12f): undefined reference to `gtk_box_new'
/usr/bin/ld: gtk4-my.c:(.text+0x138): undefined reference to `gtk_box_get_type'
/usr/bin/ld: gtk4-my.c:(.text+0x14a): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: gtk4-my.c:(.text+0x157): undefined reference to `gtk_box_set_homogeneous'
/usr/bin/ld: gtk4-my.c:(.text+0x15c): undefined reference to `gtk_window_get_type'
/usr/bin/ld: gtk4-my.c:(.text+0x16e): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: gtk4-my.c:(.text+0x180): undefined reference to `gtk_window_set_child'
/usr/bin/ld: gtk4-my.c:(.text+0x18c): undefined reference to `gtk_button_new_with_label'
/usr/bin/ld: gtk4-my.c:(.text+0x1ac): undefined reference to `gtk_window_close'
/usr/bin/ld: gtk4-my.c:(.text+0x1bb): undefined reference to `g_signal_connect_data'
/usr/bin/ld: gtk4-my.c:(.text+0x1c7): undefined reference to `gtk_button_new_with_label'
/usr/bin/ld: gtk4-my.c:(.text+0x1e9): undefined reference to `gtk_window_close'
/usr/bin/ld: gtk4-my.c:(.text+0x1f8): undefined reference to `g_signal_connect_data'
/usr/bin/ld: gtk4-my.c:(.text+0x1fd): undefined reference to `gtk_box_get_type'
/usr/bin/ld: gtk4-my.c:(.text+0x20f): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: gtk4-my.c:(.text+0x221): undefined reference to `gtk_box_append'
/usr/bin/ld: gtk4-my.c:(.text+0x226): undefined reference to `gtk_box_get_type'
/usr/bin/ld: gtk4-my.c:(.text+0x238): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: gtk4-my.c:(.text+0x24a): undefined reference to `gtk_box_append'
gtk4-my.c:(.text+0x28f): undefined reference to `gtk_application_new'
/usr/bin/ld: gtk4-my.c:(.text+0x2be): undefined reference to `g_signal_connect_data'
/usr/bin/ld: gtk4-my.c:(.text+0x2c3): undefined reference to `g_application_get_type
答: 暂无答案
评论
clang
IMPORTED_TARGET
gtk4
link_libraries(${GTK4_LIBRARIES})
target_link_libraries(gtk4-my PRIVATE ${GTK4_LIBRARIES})
gcc
clang
root@user-PC:/home/user/test123#
sudo
su
sudo