Search code examples
c++ninjameson-build

Why do I get weird stray errors with file 'cxxopts.hpp' and Meson + Ninja build?


I'm currently working on this project. I'm using cxxopts.hpp in order to parse cli options, but since I added it, I get some error that I now list how to reproduce:

  1. Build the project

    meson build
    cd build
    ninja
    
  2. Everything good so far, it builds without any errors.

  3. I can change anything other than test/vector.cpp and test/random.cpp (that are the places where I'm using cxxopts.hpp) and build with ninja without any problems.

  4. Then when I edit test/vector.cpp or test/random.cpp and do ninja these error appears:

    [1/4] Compiling C++ object test/random.p/random.cpp.o
    FAILED: test/random.p/random.cpp.o
    c++ -Itest/random.p -Itest -I../test -I../include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -O0 -g -MD -MQ test/random.p/random.cpp.o -MF test/random.p/random.cpp.o.d -o test/random.p/random.cpp.o -c ../test/random.cpp
    In file included from ../include/cxxopts.hpp:43,
                     from ../test/random.cpp:6:
    test/vector:1:1: error: stray ‘\177’ in program
        1 | <U+007F>ELF<U+0002><U+0001><U+0001><U+0003><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0003><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000> F<U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>@<U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><90><91><U+0015><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>@<U+0000>8<U+0000><U+000D><U+0000>@<U+0000>(<U+0000>'<U+0000><U+0006><U+0000><U+0000><U+0000><U+0004><U+0000><U+0000><U+0000>@<U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>@<U+0000><U+0000><U+0000><U+0000>...
        (a very lengthy error up to 400 MB in a file)
    

How can I fix this or why does this happen in the first place?


Solution

  • As pointed out by KamilCuk in their comment, this error emerged from a name collision between the standard library #include <vector> and the binary vector I was creating from vector.cpp.

    Changing the name of my binary solves the issue.

    The desired behavior can be also achieved by setting the option implicit_include_directories to false like this:

    vector = executable('vector', 'vector.cpp', include_directories: incdir, implicit_include_directories: false)