Pedro Torres
Pedro Torres

Reputation: 11

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 a.h 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.

Upvotes: 0

Views: 814

Answers (1)

Cinder Biscuits
Cinder Biscuits

Reputation: 5261

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++.

Upvotes: 1

Related Questions