Pietro
Pietro

Reputation: 13164

Cannot use the C++ `std::filesystem` library with Meson build

I am trying to build a piece of C++ code that uses the new C++17 Filesystem library, using the Meson build system.

This is the piece of meson.build file involved:

if not compiler.has_header('filesystem')   # This is OK
    warning('The compiler has no <filesystem> header file')
endif

filesystem_dep = dependency('libc++fs', modules : ['filesystem'])

test_exe = executable('test', test_src,
                      include_directories : include_dirs,
                      dependencies : filesystem_dep
                     )

In case the boost::filesystem library is used, this should be the correct syntax:

filesystem_dep = dependency('boost', modules : ['filesystem'])

How can I specify I want the version contained in the Standard C++ library? This is what I tried without success: 'libc++fs', 'stdlib', 'stdc++', 'libc++', 'c++', 'c++17'.

This is the error message I get from Meson:

src/meson.build:33:0: ERROR: Native dependency 'libc++fs' not found

The compiler I am currently using is LLVM/clang.

Upvotes: 5

Views: 3014

Answers (1)

pmod
pmod

Reputation: 10997

dependency() is for external libraries. Standard libraries should be configured using compiler command line with special functions like add_XXX_arguments(). So, try

add_project_arguments(['-stdlib=libc++'], language : 'cpp')
add_project_link_arguments(['-stdlib=libc++','-lstdc++fs'], language : 'cpp')

However, '-lstdc++fs' maybe not needed in your case.

Upvotes: 3

Related Questions