- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下项目/源结构:
MyProject
|-MyProject
| |-src
| | |-project.c
| |
| |-CMakeLists.txt
|
|-MyLibrary
|-include
| |-hello.h
|
|-src
| |-hello.c
|
|-CMakeLists.txt
MyProject/src/project.c
包含 MyLibrary/include/hello.h
,后者又包含来自系统的 libusb.h
(使用 CMake 找到)。
我正在使用以下代码在 MyLibrary/CMakeLists.txt
中添加 libusb 依赖项:
# Find libusb
find_package(LibUsb REQUIRED)
# Include libusb
include_directories(${LIBUSB_INCLUDE_DIR})
# Add dependencies
target_link_libraries(owi535 ${LIBUSB_LIBRARY})
然而,在编译 MyProject
(包括使用 add_subdirectory
和 target_link_libraries
的 MyLibrary
)时,我得到一个错误说明libusb.h
找不到。
我可以自己编译 MyLibrary
,但是编译 MyProject
需要 libusb.h
在它的包含路径中,而它不是.
有没有办法通过添加 MyLibrary
作为依赖项,MyProject
通过它拉动 libusb.h
?这意味着我不需要为包含 MyLibrary
的每个项目重复 find_package
代码。
我遇到的另一个问题是相似的;当我编译 MyProject
时,在 MyLibrary
中调用 libusb 函数时出现错误,指出存在 Undefined symbols
,但是在编译 MyLibrary 时
它自己,没有错误。
Undefined symbols for architecture x86_64:
"_libusb_close", referenced from:
_my_close_method in libMyLibrary.a(hello.c.o)
"_libusb_exit", referenced from:
_my_exit_method in libMyLibrary.a(hello.c.o)
"_libusb_init", referenced from:
_my_init_method in libMyLibrary.a(hello.c.o)
"_libusb_open_device_with_vid_pid", referenced from:
_my_open_method in libMyLibrary.a(hello.c.o)
ld: symbol(s) not found for architecture x86_64
最佳答案
PUBLIC
andINTERFACE
items will populate theINTERFACE_INCLUDE_DIRECTORIES
property of <target>.Targets may populate this property [
INTERFACE_INCLUDE_DIRECTORIES
] to publish the include directories required to compile against the headers for the target. Consuming targets can add entries to their ownINCLUDE_DIRECTORIES
property such as$<TARGET_PROPERTY:foo,INTERFACE_INCLUDE_DIRECTORIES>
to use the include directories specified in the interface of foo.
因此,您需要在 MyLibrary/CMakeLists.txt
中使用它:
target_include_directories(MyLibrary PUBLIC ${LIBUSB_INCLUDE_DIR})
关于CMake add_subdirectory 与 find_package?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33697505/
简介: 我正在尝试使用 CMake 获取跨平台编译脚本(适用于 Windows32 上的 VS 9.0 和适用于 Unix 的 Makefile)。 我遇到了关于 add_subdirectory()
这个问题在这里已经有了答案: CPack: Exclude INSTALL commands from subdirectory (googletest directory) (3 个回答) 去年关闭
我刚刚将一个较大的项目从 Visual Studio 解决方案迁移到 CMake,我注意到一个奇怪的行为。我有类似以下结构的东西: project/CMakeLists.txt project/cod
我正在使用以下内容编写 CMakeLists.txt: project(FullLibrary C) enable_language(C ASM) cmake_minimum_required(VER
我基本上问的问题与问过的问题相同 here .然而,这个问题还没有得到回答。 我想在我的项目中使用 googletest。为此,我使用 ExternalProject_Add(),它使用 git 克隆
我目前有以下架构 `-- system |-- CMakeLists.txt |-- dll | |-- CMakeLists.txt | |-- UnixDL
假设我有一个使用 cmake 的 C++ 单元测试项目,如下所示: $ tree . ├── C-API-ConditionVariable-unit-test │ ├── C-API-Condi
我正在关注 this教程,以便使用 C++ 在我的 android 项目中实现 firebase。我已按照教程所示的所有步骤进行操作,但是当我运行我的项目时,我收到此错误消息: CMake Erro
我有以下项目/源结构: MyProject |-MyProject | |-src | | |-project.c | | | |-CMakeLists.txt | |-MyLibrary |-i
我有一些项目遵循这个依赖关系图: Executable Main Libraries A, B, and C Main //_Depends_A_B_C A //_Depends_B B C //De
在一个项目中,我有一个外部依赖项(一个库)。这是可选的,但不太可能已经在系统上,并且可能会发生很大变化 所以我所做的是 find_package 库,如果找不到(包括特定版本)我从 Github 下载
我有一个要使用 OpenCV 和 googletest 构建的应用程序。使用我得到的 CMakeLists.txt,我得到一个无限循环,其中 CMake 不断将 googletest 目录添加到构建目
这可能是一个 xy 问题,所以这是我的情况。 背景 我有以下项目结构: -project -examples -example_that_uses_mylib_1
我有一个依赖于 Google 测试库的 CMake 项目。 我已经使用 ExternalProject_Add 添加了 Google 测试和 add_subdirectory如此处所述( https:
我正在尝试使用依赖于第三方库的 CMake 构建程序。这个第三方库包含一个 CMakeLists.txt 文件,所以我想做的是将第三方库的源代码保存在我的项目目录中,并使用 add_subdirect
我有一个这样的项目结构,我希望使用 CMake 构建它。 root\ | |--crystal\ | | | |--include\ Math.h, Window.h |
我有一个包含多个子目录的 C++ 项目,例如 src/ CMakeLists.txt main.cpp module1/ CMakeLists.txt code.cpp
我正在学习 CMake 以构建 C++ 代码,并在以下概念中苦苦挣扎。在我的根目录中,我有一些 cpp 文件和一个 CMakeLists.txt,它成功地在 gen-cpp 目录中生成了一些 Thri
我正在尝试将 Google Test 集成到更大项目的子项目中,但找不到令我满意的解决方案。 我有两个约束: Google Test 的源代码已经在项目结构中的某处(因此无法使用 URL 从 git
我的顶级 CMake 项目依赖于 some-library,我使用它包含在我的项目中 add_subdirectory (some-library) 然后使用链接到它 target_link_libr
我是一名优秀的程序员,十分优秀!