我正在尝试在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
在 A.H 我有这个声明
#include <algorithm>
另外,在我有的一行中:使用命名空间 std,IDE 说使用无法解析类型
我认为 cmake 有点以不正确的方式混合 .c 和 .cpp 文件。
您在 C 源文件 ( .c
) 中包含 C++ 标头。你不能指望Cmake在遇到.c
时调用的C源代码编译器gcc
理解C++。
它可以g++
工作,因为这是一个C++编译器。请注意,g++ 会将.c
文件视为C++文件(就像它对.cxx
和.cpp
所做的那样)。CMake 不这样做,因为 C 和 C++ 之间存在许多不同的不兼容性。