android - CMake 构建失败,因为找不到 STL 库
问题描述
我正在尝试在 Android Studio 项目中使用 .c 和 .cpp 文件,我已经使用我包含的所有文件配置了 CMakeList。
我的 CMakeList 是这样的:
file(GLOB SOURCES "src/main/cpp/B/*.cpp")
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
src/main/cpp/native-lib.cpp
src/main/cpp/A/B/src/a.c
src/main/cpp/A/B/src/b.c
src/main/cpp/A/B/src/c.c
src/main/cpp/A/B/src/d.c
src/main/cpp/A/a.cpp
src/main/cpp/A/B/src/e.c
src/main/cpp/B/a.cpp
${SOURCES})
考虑到我有这样的目录:
+--- /cpp
| +--- /A
| | +--- /B
| | | +--- /include
| | | | +-- *.h
| | | +--- /src
| | | +-- *.c
| | |
| | |
| +--- /B
| | +--- /include
| | | +-- *.h
| | +--- /src
| | +-- *.cpp
当我运行项目时,我得到了这个
../include/a.h:68:10: fatal error: 'algorithm' file not found
在啊我有这个声明
#include <algorithm>
另外,在我拥有的一行中:使用命名空间std,IDE说使用无法解析类型
我认为 cmake 有点以不正确的方式混合 .c 和 .cpp 文件。
解决方案
.c
您在 C 源文件 ( )中包含 C++ 标头。你不能指望gcc
Cmake在遇到时调用的C源编译器.c
能理解C++。
它之所以有效g++
,是因为那是一个 C++ 编译器。请注意,g++ 会将.c
文件视为 C++(它对.cxx
and的处理方式.cpp
)。CMake 不这样做是因为C 和 C++ 之间存在许多不同的不兼容性。
推荐阅读
- vue.js - 没有在 Vue 和 Vuex 中获取更新链接的数据
- excel - Excel 宏复制粘贴在右侧直到左侧单元格中的数据
- html - 显示:Flex 不在其下生成内容
- java - AutoValue 无法解析为类型 - Eclipse
- java - 如何将当前字符串格式化为日期/时间格式?
- php - 如何按字母顺序对php结果进行排序?
- reactjs - Elixir Pheonix Channels (FunctionClauseError) 在 ProjectName.ModuleName.handle_in/3 中没有函数子句匹配
- javascript - Select2 获取文本 onchange -逗号分隔
- r - R - 预测多个类别的相同结果的值
- json - 处理非常大的 JSON 数据集?