Suppose you have a meson project like this:
meson.build
:
project('example','cpp',version:'1.0',license:'…',default_options:['warning_level=everything','cpp_std=c++17'])subdir('example')
example/meson.build
:
test_example = executable('example-test', ['main.cc'])
example/string.h
:
/* This file intentionally left empty */
example/main.cc
:
#include<cstring>intmain(intargc,constchar*argv[]){std::stringfoo("foo");return0;}
This builds fine with autotools and cmake, but not meson:
$mesonsetupbuilddirTheMesonbuildsystemVersion:1.0.1Sourcedir:/home/enrico/dev/deb/wobble-reprBuilddir:/home/enrico/dev/deb/wobble-repr/builddirBuildtype:nativebuildProjectname:exampleProjectversion:1.0C++compilerforthehostmachine:ccachec++(gcc12.2.0"c++ (Debian 12.2.0-14) 12.2.0")C++linkerforthehostmachine:c++ld.bfd2.40Hostmachinecpufamily:x86_64Hostmachinecpu:x86_64Buildtargetsinproject:1Foundninja-1.11.1at/usr/bin/ninja$ninja-Cbuilddirninja:Enteringdirectory`builddir'[1/2]CompilingC++objectexample/example-test.p/main.cc.oFAILED:example/example-test.p/main.cc.occachec++-Iexample/example-test.p-Iexample-I../example-fdiagnostics-color=always-D_FILE_OFFSET_BITS=64-Wall-Winvalid-pch-Wextra-Wpedantic-Wcast-qual-Wconversion-Wfloat-equal-Wformat=2-Winline-Wmissing-declarations-Wredundant-decls-Wshadow-Wundef-Wuninitialized-Wwrite-strings-Wdisabled-optimization-Wpacked-Wpadded-Wmultichar-Wswitch-default-Wswitch-enum-Wunused-macros-Wmissing-include-dirs-Wunsafe-loop-optimizations-Wstack-protector-Wstrict-overflow=5-Warray-bounds=2-Wlogical-op-Wstrict-aliasing=3-Wvla-Wdouble-promotion-Wsuggest-attribute=const-Wsuggest-attribute=noreturn-Wsuggest-attribute=pure-Wtrampolines-Wvector-operation-performance-Wsuggest-attribute=format-Wdate-time-Wformat-signedness-Wnormalized=nfc-Wduplicated-cond-Wnull-dereference-Wshift-negative-value-Wshift-overflow=2-Wunused-const-variable=2-Walloca-Walloc-zero-Wformat-overflow=2-Wformat-truncation=2-Wstringop-overflow=3-Wduplicated-branches-Wattribute-alias=2-Wcast-align=strict-Wsuggest-attribute=cold-Wsuggest-attribute=malloc-Wanalyzer-too-complex-Warith-conversion-Wbidi-chars=ucn-Wopenacc-parallelism-Wtrivial-auto-var-init-Wctor-dtor-privacy-Weffc++-Wnon-virtual-dtor-Wold-style-cast-Woverloaded-virtual-Wsign-promo-Wstrict-null-sentinel-Wnoexcept-Wzero-as-null-pointer-constant-Wabi-tag-Wuseless-cast-Wconditionally-supported-Wsuggest-final-methods-Wsuggest-final-types-Wsuggest-override-Wmultiple-inheritance-Wplacement-new=2-Wvirtual-inheritance-Waligned-new=all-Wnoexcept-type-Wregister-Wcatch-value=3-Wextra-semi-Wdeprecated-copy-dtor-Wredundant-move-Wcomma-subscript-Wmismatched-tags-Wredundant-tags-Wvolatile-Wdeprecated-enum-enum-conversion-Wdeprecated-enum-float-conversion-Winvalid-imported-macros-std=c++17-O0-g-MD-MQexample/example-test.p/main.cc.o-MFexample/example-test.p/main.cc.o.d-oexample/example-test.p/main.cc.o-c../example/main.ccInfileincludedfrom../example/main.cc:1:/usr/include/c++/12/cstring:77:11:error:‘memchr’hasnotbeendeclaredin‘::’77|using::memchr;|^~~~~~/usr/include/c++/12/cstring:78:11:error:‘memcmp’hasnotbeendeclaredin‘::’78|using::memcmp;|^~~~~~/usr/include/c++/12/cstring:79:11:error:‘memcpy’hasnotbeendeclaredin‘::’79|using::memcpy;|^~~~~~/usr/include/c++/12/cstring:80:11:error:‘memmove’hasnotbeendeclaredin‘::’80|using::memmove;|^~~~~~~…
It turns out that meson adds the current directory to the include path by default:
Another thing to note is that
include_directories
adds both the source directory and corresponding build directory to include path, so you don't have to care.
It seems that I have to care after all.
Thankfully there is an implicit_include_directories
setting
that can turn this off if needed.
Its documentation is not as easy to find as I'd like (kudos to Kangie on IRC), and hopefully this blog post will make it easier for me to find it in the future.