简体   繁体   English

CMake构建失败,因为找不到STL库

[英]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.

相关问题 生成签名的 apk 失败并出现 build\app\intermediates\flutter\profile\libs.jar(系统找不到指定的路径) - Generate signed apk fails with build\app\intermediates\flutter\profile\libs.jar (The system cannot find the path specified) Android Studio构建失败,因为它无法合并Renderscript文件 - Android Studio build fails because it cannot merge Renderscript files gradle 说因为找不到所有文件而无法构建? - gradle says it fails to build because it couldnt find all files? Gradle 无法使用 OBJECT 库构建 CMake 项目,因为它需要一个 Z78E6221F6393D1356688 文件文件1DBCEDZF8 - Gradle fails to build a CMake project with OBJECT libraries because it expects a output file ndk-build在导入路径中找不到带有标签“ cxx-stl / system”的模块 - ndk-build cannot find module with tag 'cxx-stl/system' in import path Dagger构建失败,带有realm插件,无法找到符号类DaggerApplicationComponent - Dagger build fails with realm plugin, Cannot find symbol class DaggerApplicationComponent Cordova构建失败,“无法找到模块lodash / object / assign” - Cordova build fails with “Cannot find module lodash/object/assign” React本机构建开始失败,因为Gradle找不到找不到play-services-basement - React native build started failing because Gradle cannot find Could not find play-services-basement Gradle 同步因 cmake 失败“原因:为 cmake 执行外部本机构建” - Gradle sync fails with cmake "cause: executing external native build for cmake" Cordova Local Build是否由于应用程序大小而失败? - Cordova Local Build Fails because of app size?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM