简体   繁体   中英

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.

My CMakeList is like this:

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

I think that cmake is kinda of mixing .c and .cpp files in a incorrect way.

You are including a C++ header in a C source file ( .c ). You cannot expect gcc , the C source compiler invoked by Cmake when it encounters .c , to understand C++.

It works in g++ because that is a C++ compiler. Do note, g++ will treat .c files as if they were C++ (The way it does for .cxx and .cpp ). CMake does not do this because there are many different incompatibilities between C and C++ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM