代码之家  ›  专栏  ›  技术社区  ›  Jesse Beder

奇怪的gcc错误:程序中有杂散的\nnn'

  •  6
  • Jesse Beder  · 技术社区  · 15 年前

    下面的问题出现在我的开源库中,我不知道发生了什么。

    我的两个用户有(gcc)编译器错误,如下所示:

    /home/someone/Source/src/._regex.cpp:1:1: warning: null character(s) ignored
    /home/someone/Source/src/._regex.cpp:1: error: stray ‘\5’ in program
    /home/someone/Source/src/._regex.cpp:1: error: stray ‘\26’ in program
    /home/someone/Source/src/._regex.cpp:1: error: stray ‘\7’ in program
    /home/someone/Source/src/._regex.cpp:1:5: warning: null character(s) ignored
    /home/someone/Source/src/._regex.cpp:1: error: stray ‘\2’ in program
    ...
    

    我无法重现这些错误;代码在我测试过的所有机器上都能很好地编译。

    谷歌搜索似乎表明这通常是一个奇怪的编码或奇怪的格式的结果,但我通过十六进制编辑器运行所有的源代码,并且所有的字符要么是可打印的ASCII(0x20-0x7e),要么是制表符,要么是换行符。就是这样。

    另外,两个用户都成功地编译了库的前一个版本;但是有问题的特定文件( regex.cpp )它的头文件从那时起就没有被修改过!

    请看 here 有关详细信息,包括下载代码的链接(如果需要)。但只要有一个指向某个可能的方向的指针,我会很高兴的。

    5 回复  |  直到 11 年前
        1
  •  7
  •   Jonathan Leffler    15 年前

    巴夫·博伊瓦得到了正确的答案——你的规则一定做得太多了。

    在MacOS X 10.5.8(Leopard)上,我得到:

    Osiris JL: cmake ..
    -- The C compiler identification is GNU
    -- The CXX compiler identification is GNU
    -- Check for working C compiler: /usr/bin/gcc
    -- Check for working C compiler: /usr/bin/gcc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /Users/jleffler/tmp/yaml-cpp-0.2.3/build
    Osiris JL: make
    Scanning dependencies of target yaml-cpp
    [  2%] Building CXX object CMakeFiles/yaml-cpp.dir/src/._conversion.cpp.o
    /tmp/yaml-cpp-0.2.3/src/._conversion.cpp:1:1: warning: null character(s) ignored
    /tmp/yaml-cpp-0.2.3/src/._conversion.cpp:1: error: stray ‘\5’ in program
    /tmp/yaml-cpp-0.2.3/src/._conversion.cpp:1: error: stray ‘\22’ in program
    /tmp/yaml-cpp-0.2.3/src/._conversion.cpp:1: error: stray ‘\7’ in program
    /tmp/yaml-cpp-0.2.3/src/._conversion.cpp:1:5: warning: null character(s) ignored
    /tmp/yaml-cpp-0.2.3/src/._conversion.cpp:1: error: stray ‘\2’ in program
    /tmp/yaml-cpp-0.2.3/src/._conversion.cpp:1:7: warning: null character(s) ignored
    /tmp/yaml-cpp-0.2.3/src/._conversion.cpp:1:17: warning: null character(s) ignored
    ...
    

    您应该列出需要编译的文件;您不应该只编译所有的和杂项的文件。

    问题似乎出现在cmakelists.txt中:

    file(GLOB public_headers include/*.h)
    file(GLOB private_headers src/*.h)
    file(GLOB sources src/*.cpp)
    

    要么是CMakeGlobal有点太热情了(我使用的是2.6版补丁4),要么是当你的客户使用MacOSX时,你买不起它。

    环球公司正在做的扩展工作包括以“.”开头的文件,这是任何人的猜测;我倾向于将其视为cmake中的一个bug。

    但是,作为一种解决方法,我编辑了cmakelists.txt并使其生效:

    file(GLOB public_headers include/[a-z]*.h)
    file(GLOB private_headers src/[a-z]*.h)
    file(GLOB sources src/[a-z]*.cpp)
    

    这不是完整的解决方案:我在yaml reader目录中遇到了代码问题的延续。我以基本相同的方式修改了yaml reader/cmakelists.txt文件。

    FWIW:

    $ file ._*
    ._conversion.cpp: AppleDouble encoded Macintosh file
    ._exp.cpp:        AppleDouble encoded Macintosh file
    ._map.cpp:        AppleDouble encoded Macintosh file
    ._map.h:          AppleDouble encoded Macintosh file
    ._node.cpp:       AppleDouble encoded Macintosh file
    ._null.cpp:       AppleDouble encoded Macintosh file
    ._ostream.cpp:    AppleDouble encoded Macintosh file
    ._parser.cpp:     AppleDouble encoded Macintosh file
    ._regex.cpp:      AppleDouble encoded Macintosh file
    ._regeximpl.h:    AppleDouble encoded Macintosh file
    ._scanner.cpp:    AppleDouble encoded Macintosh file
    ._scanner.h:      AppleDouble encoded Macintosh file
    ._scanscalar.cpp: AppleDouble encoded Macintosh file
    ._scanscalar.h:   AppleDouble encoded Macintosh file
    ._sequence.cpp:   AppleDouble encoded Macintosh file
    ._simplekey.cpp:  AppleDouble encoded Macintosh file
    ._stream.cpp:     AppleDouble encoded Macintosh file
    ._token.h:        AppleDouble encoded Macintosh file
    $ odx ._con*.cpp 
    0x0000: 00 05 16 07 00 02 00 00 4D 61 63 20 4F 53 20 58   ........Mac OS X
    0x0010: 20 20 20 20 20 20 20 20 00 02 00 00 00 09 00 00           ........
    0x0020: 00 32 00 00 00 79 00 00 00 02 00 00 00 AB 00 00   .2...y..........
    0x0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
    *
    0x0050: 00 00 00 00 41 54 54 52 00 3C E0 2B 00 00 00 AB   ....ATTR.<.+....
    0x0060: 00 00 00 9C 00 00 00 0F 00 00 00 00 00 00 00 00   ................
    0x0070: 00 00 00 00 00 00 00 01 00 00 00 9C 00 00 00 0F   ................
    0x0080: 00 00 17 63 6F 6D 2E 61 70 70 6C 65 2E 54 65 78   ...com.apple.Tex
    0x0090: 74 45 6E 63 6F 64 69 6E 67 00 00 00 55 54 46 2D   tEncoding...UTF-
    0x00A0: 38 3B 31 33 34 32 31 37 39 38 34                  8;134217984
    0x00AB:
    $
    

    一个奇怪的细节-“src”目录中的一些文件没有阴影文件。当我执行“tar-tvf yaml-cpp-0.2.3.tar.gz”操作时,我会看到源文件附带的文件:

    Osiris JL: tar -tvf yaml-cpp-0.2.3.tar.gz
    drwxr-xr-x beder/staff       0 2009-10-22 15:13:52 ./
    -rw-r--r-- beder/staff    1750 2009-10-22 15:09:05 ./CMakeLists.txt
    drwxr-xr-x beder/staff       0 2009-10-19 16:40:15 ./include/
    -rw-r--r-- beder/staff     171 2009-09-06 13:41:54 ./include/._conversion.h
    -rw-r--r-- beder/staff    1118 2009-09-06 13:41:54 ./include/conversion.h
    -rw-r--r-- beder/staff     302 2009-07-29 15:25:23 ./include/crt.h
    -rw-r--r-- beder/staff    2254 2009-10-19 16:40:14 ./include/emitter.h
    -rw-r--r-- beder/staff    1660 2009-10-19 16:40:14 ./include/emittermanip.h
    -rw-r--r-- beder/staff     171 2009-08-18 22:07:22 ./include/._exceptions.h
    -rw-r--r-- beder/staff    5638 2009-08-18 22:07:22 ./include/exceptions.h
    -rw-r--r-- beder/staff     765 2009-07-29 15:25:23 ./include/iterator.h
    -rw-r--r-- beder/staff     444 2009-07-29 15:25:23 ./include/mark.h
    -rw-r--r-- beder/staff     171 2009-09-06 12:25:12 ./include/._node.h
    -rw-r--r-- beder/staff    3467 2009-09-06 12:25:12 ./include/node.h
    -rw-r--r-- beder/staff     171 2009-09-15 20:54:20 ./include/._nodeimpl.h
    ...
    -rw-r--r-- beder/staff     171 2009-07-29 21:28:26 ./include/._yaml.h
    -rw-r--r-- beder/staff     321 2009-07-29 21:28:26 ./include/yaml.h
    -rw-r--r-- beder/staff     167 2009-09-05 16:01:06 ./._install.txt
    -rw-r--r-- beder/staff     652 2009-09-05 16:01:06 ./install.txt
    -rw-r--r-- beder/staff    1073 2009-05-29 19:31:21 ./license.txt
    drwxr-xr-x beder/staff       0 2009-10-22 14:49:11 ./src/
    -rw-r--r-- beder/staff    1697 2009-08-24 16:28:46 ./src/aliascontent.cpp
    -rw-r--r-- beder/staff    1171 2009-08-24 16:28:46 ./src/aliascontent.h
    -rw-r--r-- beder/staff     112 2009-05-29 19:31:21 ./src/content.cpp
    -rw-r--r-- beder/staff    1557 2009-08-24 16:28:46 ./src/content.h
    -rw-r--r-- beder/staff     171 2009-09-06 13:31:56 ./src/._conversion.cpp
    -rw-r--r-- beder/staff    2027 2009-09-06 13:31:56 ./src/conversion.cpp
    ...
    

    因此,错误文件随产品tar文件一起提供。你在某个地方感染了-不知道怎么感染的。

        2
  •  13
  •   Baffe Boyois    15 年前

    错误在 ._regex.cpp 不是 regex.cpp . 文件以 ._ 由MacOS自动生成。似乎您的构建系统试图编译以.cpp结尾的所有文件。它可能不应该编译任何以点开头的内容。

        3
  •  0
  •   Glen    15 年前

    可能是一个损坏的文件。

    他们系统上的regex.cpp第1行上有什么。

    如果存在下载/编码问题,则必须查看文件系统中的内容,而不是代码存储库中的内容。

        4
  •  0
  •   Ben Gartner    15 年前

    确保您的构建目录中只有.o文件。我有这个问题,原因是我的makefile(实际上是一个scons文件)中的一个错误,它将一个源文件构建为.c文件而不是.o文件。生成的文件是一个二进制文件,但我假设gcc试图将其解释为.c文件。

        5
  •  0
  •   BostonGeorge    11 年前

    我刚刚在我的C++程序中发生了这样的事情。当我从一个pdf文件中复制双重散列的公式时,发生了这种情况。

    return (randomNumber % (tableSize - 2)) + 1;
    

    我通过它得到的是modulo运算符,但结果却是编码或其他东西,但我通过删除它并手动键入来解决这个问题。