【问题标题】:Clang 7 cannot find <filesystem> header on Ubuntu 18.04Clang 7 在 Ubuntu 18.04 上找不到 <filesystem> 标头
【发布时间】:2019-04-18 05:45:39
【问题描述】:

我为使用 C++17 &lt;filesystem&gt; 编写了如下CMakeLists.txt 文件。这些是它们的一部分。

cmake_minimum_required(VERSION 3.14)

...

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

include(functions)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

enable_cxx_compiler_flag_if_supported("-Wall")
enable_cxx_compiler_flag_if_supported("-pedantic")

...

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
find_package(Boost 1.65.1 COMPONENTS filesystem regex system thread)
if(Boost_FOUND)
    add_executable(daemon 
                ...)
    target_compile_features(daemon PRIVATE cxx_std_17)
    target_include_directories(daemon PRIVATE ...)
    target_link_libraries(daemon ${Boost_LIBRARIES}) 

    # OS specific instructions.
    if(APPLE)
        find_library(CoreFoundation CoreFoundation)
        find_library(IOKit IOKit)
        target_link_libraries(daemon ${CoreFoundation} ${IOKit}) 
    elseif(WIN32)
        # Windows developer environment specific instructions.
        if(MINGW)
        elseif(MSYS)
        elseif(CYGWIN)
        endif()
    elseif(UNIX)
        // The problem is here. Why Clang cannot find <filesystem>???
        target_link_libraries(daemon c++fs dl)
    else()
    endif()
endif()

我尝试了target_link_libraries(daemon stdc++fs dl)set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi"),但没有成功。

错误代码是

cmake --build .
[1/2] Building CXX object CMakeFiles/daemon.dir/src/thread/serial_manager.cpp.o
FAILED: CMakeFiles/daemon.dir/src/thread/serial_manager.cpp.o 
/usr/bin/clang++   -I/home/koriel/.conan/data/boost/1.65.1/conan/stable/package/f410c60ac3ae66f96115aab74b1c5fbc1a6a4a45/include -I/home/koriel/.conan/data/bzip2/1.0.6/conan/stable/package/abc45b7dce3f5194dea2377c33229fa4f20706b4/include -I/home/koriel/.conan/data/zlib/1.2.11/conan/stable/package/abc45b7dce3f5194dea2377c33229fa4f20706b4/include -I../include/json -I../include/queue -I../src/base64 -I../src/message -I../src/serial -I../src/thread -Wall -pedantic   -DBOOST_USE_STATIC_LIBS -std=gnu++17 -MD -MT CMakeFiles/daemon.dir/src/thread/serial_manager.cpp.o -MF CMakeFiles/daemon.dir/src/thread/serial_manager.cpp.o.d -o CMakeFiles/daemon.dir/src/thread/serial_manager.cpp.o -c ../src/thread/serial_manager.cpp
../src/thread/serial_manager.cpp:43:10: fatal error: 'filesystem' file not found
#include <filesystem>
         ^~~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.

【问题讨论】:

    标签: ubuntu cmake clang c++17 ninja


    【解决方案1】:

    尽管&lt;filesystem&gt; 包含在official libc++ 7 中,但许多发行版并未包含它。

    我刚刚查看了 Xcode 10.2(它还附带了 libc++ 7)并且遇到了同样的情况:安装中缺少 filesystem 标头。

    您可以查看您的 libc++ 安装,对于 Ubuntu 系统,它应该位于 /usr 中的某个位置(如果您不知道确切的位置,只需运行 find /usr -name cstdint,它将指向您所在的位置)。如果在该文件夹中找不到 filesystem 标头,您可以使用 boost::filesystem 或安装 clang 8。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2019-01-12
      相关资源
      最近更新 更多