首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Clang 7在Ubuntu18.04上找不到<filesystem>头文件

Clang 7在Ubuntu18.04上找不到<filesystem>头文件
EN

Stack Overflow用户
提问于 2019-04-18 13:45:39
回答 1查看 1.6K关注 0票数 1

为了使用C++17 <filesystem>,我写了类似下面的CMakeLists.txt文件。这是他们的一部分。

代码语言:javascript
运行
复制
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"),但不起作用。

错误代码为

代码语言:javascript
运行
复制
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.
EN

回答 1

Stack Overflow用户

发布于 2019-04-18 17:26:43

尽管official libc++ 7中包含了<filesystem>,但许多发行版都不包含它。

我刚刚看了一下Xcode10.2(它也附带了libc++ 7),我遇到了同样的问题:安装中缺少filesystem头文件。

你可以看看你的libc++安装,它应该在Ubuntu系统的/usr中的某个地方(如果你不知道确切的位置,只需要运行find /usr -name cstdint,这会指向你的位置)。如果在该文件夹中找不到filesystem头文件,您可以使用boost::filesystem或尽快安装clang8。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55739773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档