- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我对 Cmake 的工作原理了解甚少。我有一个项目,其中包含一个依赖于 glib 的静态库。我遗漏了一些导致大量 undefined references to glib features
的东西,如下所示。我在 Linux Ubuntu 中工作并且有 Cmake 3.5
../Gobbledegook/src/libggk.a(libggk_a-Gobbledegook.o): In function `ggkWait':
/home/ubuntu/visionpro-device-xray/src/user_device_interface/Gobbledegook/src/Gobbledegook.cpp:384: undefined reference to `g_set_print_handler'
/home/ubuntu/visionpro-device-xray/src/user_device_interface/Gobbledegook/src/Gobbledegook.cpp:385: undefined reference to `g_set_printerr_handler'
/home/ubuntu/visionpro-device-xray/src/user_device_interface/Gobbledegook/src/Gobbledegook.cpp:386: undefined reference to `g_log_set_default_handler'
这是我的 Cmake 文件,我在其中尝试自己构建库 - 而没有链接静态库。我尝试使用/包含的库是 https://github.com/nettlep/gobbledegook .
cmake_minimum_required(VERSION 3.2.2)
project(TestBLE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -I/usr/include/glib-2.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/lib/aarch64-linux-gnu/glib-2.0/include")
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED glib-2.0)
include_directories(${GLIB_INCLUDE_DIRS})
link_directories(${GLIB_LIBRARY_DIRS})
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Gets all the header/source files in current directory
file(GLOB SOURCES "*.cpp")
file(GLOB HEADERS "*.h")
file(GLOB GGK_SOURCES "Gobbledegook/src/*.cpp")
file(GLOB GGK_HEADERS "Gobbledegook/src/*.h")
add_executable(
${PROJECT_NAME}
${SOURCES}
${HEADERS}
${CMAKE_SOURCE_DIR}/Gobbledegook/include/Gobbledegook.h
${GGK_SOURCES}
${GGK_HEADERS}
)
target_link_libraries(
${PROJECT_NAME}
${GLIB_LIBRARIES}
Threads::Threads
)
这是我的 CMake 文件,它试图链接静态库 libggk.a
,该静态库是使用 Gobbledegook 库中的 ./configure && make
构建的。
cmake_minimum_required(VERSION 3.2.2)
project(TestBLE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -I/usr/include/glib-2.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/lib/aarch64-linux-gnu/glib-2.0/include")
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED glib-2.0)
include_directories(${GLIB_INCLUDE_DIRS})
link_directories(${GLIB_LIBRARY_DIRS})
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Gets all the header/source files in current directory
file(GLOB SOURCES "*.cpp")
file(GLOB HEADERS "*.h")
add_executable(
${PROJECT_NAME}
${SOURCES}
${HEADERS}
${CMAKE_SOURCE_DIR}/Gobbledegook/include/Gobbledegook.h
)
target_link_libraries(
${PROJECT_NAME}
${GLIB_LIBRARIES}
Threads::Threads
${CMAKE_SOURCE_DIR}/Gobbledegook/src/libggk.a
)
无论哪种情况,我都保留 undefined reference 。感谢大家的帮助,我一直在搜索论坛以寻求提示或解释。
编辑:
here is my directory setup
project
|---------CMakeLists.txt
|---------build
|---------bluetest.cpp
|---------Gobbledegook
| |-----------include
| | |------Gobbldegook.h
| |-----------src
| | |------${all_the_source/header_files}
| | |------libggk.a
编辑 2:修改 Cmake 以显示打印件
cmake_minimum_required(VERSION 3.2.2)
project(TestBLE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
include_directories(Gobbledegook/include)
include_directories(${GLIB_INCLUDE_DIRS})
link_directories(${GLIB_LIBRARIES_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GLIB_CFLAGS}")
message(WARNING "GLIB_LIBRARIES: ${GLIB_LIBRARIES}")
message(WARNING "GLIB_LIBRARY_DIRS: ${GLIB_LIBRARY_DIRS}")
message(WARNING "GLIB_LDFLAGS: ${GLIB_LDFLAGS}")
message(WARNING "GLIB_LDFLAGS_OTHER: ${GLIB_LDFLAGS_OTHER}")
message(WARNING "GLIB_INCLUDE_DIRS: ${GLIB_INCLUDE_DIRS}")
message(WARNING "GLIB_CFLAGS: ${GLIB_CFLAGS}")
message(WARNING "GLIB_CFLAGS_OTHER: ${GLIB_CFLAGS_OTHER}")
pkg_check_modules(DBUS REQUIRED dbus-1)
include_directories(${DBUS_INCLUDE_DIRS})
link_directories(${DBUS_LIBRARIES_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DBUS_CFLAGS}")
message(WARNING "DBUS_LIBRARIES: ${DBUS_LIBRARIES}")
message(WARNING "DBUS_LIBRARY_DIRS: ${DBUS_LIBRARY_DIRS}")
message(WARNING "DBUS_LDFLAGS: ${DBUS_LDFLAGS}")
message(WARNING "DBUS_LDFLAGS_OTHER: ${DBUS_LDFLAGS_OTHER}")
message(WARNING "DBUS_INCLUDE_DIRS: ${DBUS_INCLUDE_DIRS}")
message(WARNING "DBUS_CFLAGS: ${DBUS_CFLAGS}")
message(WARNING "DBUS_CFLAGS_OTHER: ${DBUS_CFLAGS_OTHER}")
pkg_check_modules(DBUS_GLIB REQUIRED dbus-glib-1)
include_directories(${DBUS_GLIB_INCLUDE_DIRS})
link_directories(${DBUS_GLIB_LIBRARIES_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DBUS_GLIB_CFLAGS}")
message(WARNING "DBUS_GLIB_LIBRARIES: ${DBUS_GLIB_LIBRARIES}")
message(WARNING "DBUS_GLIB_LIBRARY_DIRS: ${DBUS_GLIB_LIBRARY_DIRS}")
message(WARNING "DBUS_GLIB_LDFLAGS: ${DBUS_GLIB_LDFLAGS}")
message(WARNING "DBUS_GLIB_LDFLAGS_OTHER: ${DBUS_GLIB_LDFLAGS_OTHER}")
message(WARNING "DBUS_GLIB_INCLUDE_DIRS: ${DBUS_GLIB_INCLUDE_DIRS}")
message(WARNING "DBUS_GLIB_CFLAGS: ${DBUS_GLIB_CFLAGS}")
message(WARNING "DBUS_GLIB_CFLAGS_OTHER: ${DBUS_GLIB_CFLAGS_OTHER}")
message(WARNING "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
set(THREADS_PREFER_PTHREAD_FLAG ON)
FIND_PACKAGE(Threads REQUIRED)
# Gets all the header/source files in current directory
file(GLOB SOURCES "*.cpp")
file(GLOB HEADERS "*.h")
file(GLOB GGK_SOURCES "Gobbledegook/src/*.cpp")
file(GLOB GGK_HEADERS "Gobbledegook/src/*.h")
add_executable(
${PROJECT_NAME}
${SOURCES}
${HEADERS}
#${CMAKE_SOURCE_DIR}/Gobbledegook/include/Gobbledegook.h
${GGK_SOURCES}
${GGK_HEADERS}
)
target_include_directories(
${PROJECT_NAME}
PUBLIC ${GLIB_INCLUDE_DIRS}
PUBLIC ${DBUS_INCLUDE_DIRS}
PUBLIC ${DBUS_GLIB_INCLUDE_DIRS}
)
target_link_libraries(
${PROJECT_NAME}
PUBLIC ${GLIB_LIBRARIES}
PUBLIC ${DBUS_LIBRARIES}
PUBLIC ${DBUS_GLIB_LIBRARIES}
Threads::Threads
)
修改后的 CMake 文件的输出
ubuntu@tegra-ubuntu:~/visionpro-device-xray/src/user_device_interface/build$ sudo cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'glib-2.0'
-- Found glib-2.0, version 2.48.2
CMake Warning at CMakeLists.txt:15 (message):
GLIB_LIBRARIES: glib-2.0
CMake Warning at CMakeLists.txt:16 (message):
GLIB_LIBRARY_DIRS:
CMake Warning at CMakeLists.txt:17 (message):
GLIB_LDFLAGS: -lglib-2.0
CMake Warning at CMakeLists.txt:18 (message):
GLIB_LDFLAGS_OTHER:
CMake Warning at CMakeLists.txt:19 (message):
GLIB_INCLUDE_DIRS:
/usr/include/glib-2.0;/usr/lib/aarch64-linux-gnu/glib-2.0/include
CMake Warning at CMakeLists.txt:20 (message):
GLIB_CFLAGS:
-I/usr/include/glib-2.0;-I/usr/lib/aarch64-linux-gnu/glib-2.0/include
CMake Warning at CMakeLists.txt:21 (message):
GLIB_CFLAGS_OTHER:
-- Checking for module 'dbus-1'
-- Found dbus-1, version 1.10.6
CMake Warning at CMakeLists.txt:28 (message):
DBUS_LIBRARIES: dbus-1
CMake Warning at CMakeLists.txt:29 (message):
DBUS_LIBRARY_DIRS:
CMake Warning at CMakeLists.txt:30 (message):
DBUS_LDFLAGS: -ldbus-1
CMake Warning at CMakeLists.txt:31 (message):
DBUS_LDFLAGS_OTHER:
CMake Warning at CMakeLists.txt:32 (message):
DBUS_INCLUDE_DIRS:
/usr/include/dbus-1.0;/usr/lib/aarch64-linux-gnu/dbus-1.0/include
CMake Warning at CMakeLists.txt:33 (message):
DBUS_CFLAGS:
-I/usr/include/dbus-1.0;-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include
CMake Warning at CMakeLists.txt:34 (message):
DBUS_CFLAGS_OTHER:
-- Checking for module 'dbus-glib-1'
-- Found dbus-glib-1, version 0.106
CMake Warning at CMakeLists.txt:41 (message):
DBUS_GLIB_LIBRARIES: dbus-glib-1;dbus-1;gobject-2.0;glib-2.0
CMake Warning at CMakeLists.txt:42 (message):
DBUS_GLIB_LIBRARY_DIRS:
CMake Warning at CMakeLists.txt:43 (message):
DBUS_GLIB_LDFLAGS: -ldbus-glib-1;-ldbus-1;-lgobject-2.0;-lglib-2.0
CMake Warning at CMakeLists.txt:44 (message):
DBUS_GLIB_LDFLAGS_OTHER:
CMake Warning at CMakeLists.txt:45 (message):
DBUS_GLIB_INCLUDE_DIRS:
/usr/include/dbus-1.0;/usr/lib/aarch64-linux-gnu/dbus-1.0/include;/usr/include/glib-2.0;/usr/lib/aarch64-linux-gnu/glib-2.0/include
CMake Warning at CMakeLists.txt:46 (message):
DBUS_GLIB_CFLAGS:
-I/usr/include/dbus-1.0;-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include;-I/usr/include/glib-2.0;-I/usr/lib/aarch64-linux-gnu/glib-2.0/include
CMake Warning at CMakeLists.txt:47 (message):
DBUS_GLIB_CFLAGS_OTHER:
CMake Warning at CMakeLists.txt:49 (message):
CMAKE_CXX_FLAGS: -std=c++11
-I/usr/include/glib-2.0;-I/usr/lib/aarch64-linux-gnu/glib-2.0/include
-I/usr/include/dbus-1.0;-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include
-I/usr/include/dbus-1.0;-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include;-I/usr/include/glib-2.0;-I/usr/lib/aarch64-linux-gnu/glib-2.0/include
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/visionpro-device-xray/src/user_device_interface/build
最佳答案
我发现了问题,它与需要包含 gtk+-2.0 有关。我不知道为什么在我链接的库中使用 gtk+-2.0,因为它不是图形程序。 CmakeLists.txt 应如下所示。
cmake_minimum_required(VERSION 3.2.2)
project(TestBLE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") #All warning
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") #Extra warning flags
#####################################################################
# Including Packages
#####################################################################
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
include_directories(${GLIB_INCLUDE_DIRS})
pkg_check_modules(GTK2 REQUIRED gtk+-2.0)
include_directories(${GTK2_INCLUDE_DIRS})
set(THREADS_PREFER_PTHREAD_FLAG ON)
FIND_PACKAGE(Threads REQUIRED)
#####################################################################
# Files to add to the executable
#####################################################################
file(GLOB SOURCES "*.cpp")
file(GLOB HEADERS "*.h")
file(GLOB GGK_SOURCES "Gobbledegook/src/*.cpp")
file(GLOB GGK_HEADERS "Gobbledegook/src/*.h")
add_executable(
${PROJECT_NAME}
${SOURCES}
${HEADERS}
#${CMAKE_SOURCE_DIR}/Gobbledegook/include/Gobbledegook.h
${GGK_SOURCES}
${GGK_HEADERS}
)
target_include_directories(
${PROJECT_NAME}
PUBLIC ${GLIB_INCLUDE_DIRS}
)
target_link_libraries(
${PROJECT_NAME}
PUBLIC ${GLIB_LIBRARIES}
PUBLIC ${GTK2_LIBRARIES}
Threads::Threads
)
希望这对尝试将 Gobbledegook 库合并到他们的构建中的其他人有所帮助。
关于c++ - CMake 链接静态库和 Glib 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55067881/
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 5 年前。 Improve
在 C# 静态方法中是否有一种方法可以引用定义该方法的类型? 在实例方法中,您可以通过以下方式确定类型: public void Foo() { Type type = this.GetTyp
WPF:静态、动态资源以及资源词典 静态资源与动态资源 我们常常会使用样式或者控件模板放在Window.Resources中,比如这样: 静态资源与动态资源使用如下: <Window
任何人都知道如何在共享/静态函数中动态加载控件?该函数本身位于 mustinherit/abstract 类中。 (这是 VB 中的 ASP.NET 项目)我想做这样的事情: VB: Publ
在我看来,静态/强类型编程语言最宝贵的一点是它有助于重构:如果/当您更改任何 API,那么编译器会告诉您该更改破坏了什么。 我可以想象用运行时/弱类型语言编写代码......但我无法想象没有编译器的帮
正如我的名字所暗示的,我是一名 .NET 开发人员,但我对 Java 的兴趣越来越大,并且我有兴趣学习更多其他语言,因为这有助于我学习更多关于编程的知识。 无论如何,我的问题是:不带参数/不使用状态的
我在java中使用WireMock来 stub POST请求。该请求返回一个存储在我本地的 json 正文文件。 stub 看起来像这样: wireMockServer.stubFor(get(url
Python 是否有类构造函数的机制,即每当首次引用类时(而不是创建该对象的实例时)调用的函数?我知道其他一些语言中也存在这种情况,但我还没有在 Python 中遇到过。 基本上,我想初始化该函数中的
Python 是否有类构造函数的机制,即每当首次引用类时(而不是创建该对象的实例时)调用的函数?我知道其他一些语言中也存在这种情况,但我还没有在 Python 中遇到过。 基本上,我想初始化该函数中的
这个问题已经有答案了: What is the difference between dynamic and static polymorphism in Java? (14 个回答) 已关闭 4 年
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Static initializer in Java 我想知道这个静态的东西(抱歉,这是我第一次遇到这个)对一个类有
如果c++应用程序是按以下方式组织的 //file1.cpp static Y sgObj = X::getInitObject(0); //declared in file scope //fil
我有一个抽象类(AvergedDataRecord),我需要进一步抽象(DataRecord),这样我就可以将它扩展到原始类和一个新的具体类(SummedDataRecord),并且我在获取某些方法时
我正在尝试制作一个字符串枚举。这是我到目前为止所得到的, private class TypedEnum : IEnumerable { public IEnumerator GetEnume
我选修了一门名为“安全代码”的类(class),在下一个作业中,我们应该对一些 C 文件和 JavaEE Web 项目进行静态/动态分析。 我检查了“源监视器”并在 C 文件上运行它,但是(除非我不知
我有两个类,一个是登录类,一个是用户类。在 loggedIn 类中,我想显示我在用户登录时所做的共享首选项。 loginPrefs = getSharedPreferences("loginprefe
我在同一个 Activity 中有两个静态 fragment ,在“fragmentA”中我有一个自定义列表,当一个项目被点击时必须在“fragmentB”中出现一个细节,细节只在我改变屏幕方向时出现
在 Java 中是未修改方法变量,缺少final,每次都重新初始化限定符 静态方法 实例方法 如果 1. 或 2.(或两者)的答案是 final 限定符允许 Java 执行优化并存储方法变量只有一次?
我有两个类相互交互。第一个是中心的,如下: public class Datenbank { double winkelPanel = 0; double groessePanel = 0; doub
我有一个 mysql 数据库,它连接基于 Web 的 php 应用程序和 FoxPro 应用程序(是的,foxpro)。在之前的“开发人员”被解雇后开始处理这个问题。 无论如何,我熟悉 AES_Enc
我是一名优秀的程序员,十分优秀!