[英]CMake fails in build because cannot find STL libs
I'm trying to use .c and .cpp files in an Android Studio project, i already configure CMakeList with all files that i included. 我正在尝试在Android Studio项目中使用.c和.cpp文件,我已经使用包含的所有文件配置了CMakeList。
My CMakeList is like this: 我的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})
Considering that i have directories like this: 考虑到我有这样的目录:
+--- /cpp
| +--- /A
| | +--- /B
| | | +--- /include
| | | | +-- *.h
| | | +--- /src
| | | +-- *.c
| | |
| | |
| +--- /B
| | +--- /include
| | | +-- *.h
| | +--- /src
| | +-- *.cpp
When i run the project i get this 当我运行项目时,我得到了这个
../include/a.h:68:10: fatal error: 'algorithm' file not found
in the ah i have this declaration 在啊,我有这个宣言
#include <algorithm>
also, in one line that i have: using namespace std, the IDE says that using can't resolve type 此外,在我拥有的一行中:使用命名空间std,IDE表示使用无法解析类型
I think that cmake is kinda of mixing .c and .cpp files in a incorrect way. 我认为cmake有点以不正确的方式混合了.c和.cpp文件。
You are including a C++ header in a C source file ( .c
). 您正在C源文件( .c
)中包含C ++标头。 You cannot expect gcc
, the C source compiler invoked by Cmake when it encounters .c
, to understand C++. 您不能期望gcc
(当Cmake遇到.c
时由Cmake调用的C源代码编译器)理解C ++。
It works in g++
because that is a C++ compiler. 它可以在g++
工作,因为它是C ++编译器。 Do note, g++ will treat .c
files as if they were C++ (The way it does for .cxx
and .cpp
). 请注意,g ++会将.c
文件当作C ++处理( .cxx
和.cpp
)。 CMake does not do this because there are many different incompatibilities between C and C++ . CMake不会这样做,因为C和C ++之间存在许多不同的不兼容性 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.