Search code examples
c++boostc++11g++boost-thread

Error "Error: stray character" when using C++11


I'm running into a strange issue when I try to compile the following simple C++11 code on my machine:

#include <boost/thread/thread.hpp>

It compiles fine with g++ foo.cpp -o foo but chokes on g++ -c -std=c++11 foo.cpp -o foo with the following error:

In file included from /usr/local/lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/functional:56:0,
             from /usr/local/lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/memory:81,
             from /usr/local/include/boost/config/no_tr1/memory.hpp:21,
             from /usr/local/include/boost/smart_ptr/shared_ptr.hpp:27,
             from /usr/local/include/boost/shared_ptr.hpp:17,
             from /usr/local/include/boost/thread/pthread/thread_data.hpp:10,
             from /usr/local/include/boost/thread/thread.hpp:17,
             from foo.cpp:1:
./tuple:1:1: error: stray ‘\317’ in program
./tuple:1:1: error: stray ‘\372’ in program
./tuple:1:1: error: stray ‘\355’ in program
./tuple:1:1: error: stray ‘\376’ in program
... Additional lines omitted

I'm at a loss. Especially since I've been able to compile other programs against C++11 without any issue. Any ideas?

I'm running OS X v10.7.4 (Lion) and GCC 4.7.1.


Solution

  • That's because you have a file in your current directory named tuple that is included instead of the standard tuple header. Probably because of some -I. in the compilation line.

    The strays characters in the error messages are simply the first bytes of the file not in the allowed character set, in octal.