簡體   English   中英

CMake構建失敗,因為找不到STL庫

[英]CMake fails in build because cannot find STL libs

我正在嘗試在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

啊,我有這個宣言

#include <algorithm> 

此外,在我擁有的一行中:使用命名空間std,IDE表示使用無法解析類型

我認為cmake有點以不正確的方式混合了.c和.cpp文件。

您正在C源文件( .c )中包含C ++標頭。 您不能期望gcc (當Cmake遇到.c時由Cmake調用的C源代碼編譯器)理解C ++。

它可以在g++工作,因為它是C ++編譯器。 請注意,g ++會將.c文件當作C ++處理( .cxx.cpp )。 CMake不會這樣做,因為C和C ++之間存在許多不同的不兼容性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM