Git breaks my program?

有些话、适合烂在心里 提交于 2019-12-08 08:26:30

问题


I have several programs that I have been writing under a master branch, which I compile using GNUmakefile. Today, right after I created a new branch, v4.3, and switched onto the new branch, and then compile, I get the following error message:

lucerne:lucerne$ make primes
g++-mp-4.8 -std=gnu++0x -g -O2 -W -Wall -Wextra  -MD -MF .deps/primes.d -MP  -I. -c -o primes.o primes.cpp
In file included from primes.cpp:2:0:
./vector:1:1: error: stray '\317' in program
 ????_TEXT
 ^
./vector:1:1: error: stray '\372' in program
./vector:1:1: error: stray '\355' in program
./vector:1:1: error: stray '\376' in program
./vector:1:1: error: stray '\7' in program
./vector:1:6: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\1' in program
./vector:1:1: error: stray '\3' in program
./vector:1:10: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\200' in program

I get the same error message when I switch to master branch. However, if I rename the file to something else, like "new_primes.cpp", then make file does not cause any problem. Neither GNUmakefile or prime.cpp has been modified. I also have not installed any additional packages. It is also not the editor - I am using emacs and TextWrangler. What is causing this problem?


回答1:


The error generated by GCC occurs when the source file, or in this case, included file is a binary file. This is easily reproduced by creating a source file with a single include to a binary file, /bin/ls for example. Create stray.c with:

#include "/bin/ls"

A quick complie:

gcc -c stray.c

Yields the following output:

In file included from stray.c:1:0:
/bin/ls:1:1: error: stray '\177' in program
/bin/ls:1:1: error: stray '\2' in program
/bin/ls:1:1: error: stray '\1' in program
/bin/ls:1:1: error: stray '\1' in program
/bin/ls:1:8: warning: null character(s) ignored [enabled by default]
/bin/ls:1:1: error: stray '\2' in program
/bin/ls:1:18: warning: null character(s) ignored [enabled by default]

It appears that 'vector' is a binary file.

There are two possible causes that come to mind:

  1. The C++ 'vector' header file is corrupt.
  2. There is another 'vector' in your search path.

I'm guessing its the second. Check and make sure you don't have a binary called vector within the compiler include path.



来源:https://stackoverflow.com/questions/22469431/git-breaks-my-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!