0

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MaxWell
  • 7
  • 7
  • 2
    It seems one of your executables is called `vector` and you are adding include path with that executable and including an executable file with `#include ` – KamilCuk Aug 18 '22 at 23:11
  • @KamilCuk Thanks! This solved it! It seems like a very dumb mistake. – MaxWell Aug 18 '22 at 23:15
  • Nah. This has some subtlety to it. A dumb mistake is swapping `i` and `j` in a `for` loop or trying to eat a can of Coke. – user4581301 Aug 18 '22 at 23:20
  • "[ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format)" is a hint. Here is another one where the compiler to chew on binary data: *[Daemon on embedded Linux device using Busybox be written in C or as a script](https://stackoverflow.com/questions/28759855/daemon-on-embedded-linux-device-using-busybox-be-written-in-c-or-as-a-script)* – Peter Mortensen May 01 '23 at 18:16
  • Here is one where a build system is involved: *[Android NDK build errors, \221, etc](https://stackoverflow.com/questions/13065790/android-ndk-build-errors-221-etc)* – Peter Mortensen May 01 '23 at 18:23

1 Answers1

0

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)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MaxWell
  • 7
  • 7
  • Is there any way of avoiding this without renaming my binary name? – MaxWell Aug 18 '22 at 23:29
  • You could change the output directory. If all of the generated files go into a bin folder, your vector becomes bin/vector and no longer collides. Plus separating the source and output is generally good from a sanitation standpoint. – user4581301 Aug 19 '22 at 14:52
  • @user4581301 I'll search how to do that. Thing is that's the default behavior of meson, it does separate code from binaries I don't know why it includes the binaries folder. – MaxWell Aug 19 '22 at 15:15