5

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.

Pietro
  • 12,086
  • 26
  • 100
  • 193
  • (not using clang nor meson, so I may be wrong, but) have you checked if you need to link libc++fs with clang if you use std::filesystem? – roalz Sep 26 '18 at 11:04
  • @roalz - I think Meson should deal with it, and choose `libc++fs` or `libstdc++fs` depending on the compiler (clang or gcc). – Pietro Sep 26 '18 at 11:12

1 Answers1

3

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.

pmod
  • 10,450
  • 1
  • 37
  • 50