错误:包含外部库后,在程序中错误'\ 224'

时间:2016-07-05 21:53:09

标签: c++ makefile g++

我是C ++的新手。我正在尝试使用libserial

bitmap_test.cpp

#include <SerialStream.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace LibSerial ;

int main()
{
   SerialStream serial_port( "/dev/ttyS0" ) ;
   return 0;
}

错误:

    In file included from <command-line>:0:0:
    /usr/local/lib/libserial.a:118:520: error: null character(s) ignored [-Werror]
    In file included from <command-line>:0:0:
    /usr/local/lib/libserial.a:118:1: error: stray ‘\17’ in program
    In file included from <command-line>:0:0:
    /usr/local/lib/libserial.a:118:525: error: null character(s) ignored [-Werror]
    In file included from <command-line>:0:0:
    /usr/local/lib/libserial.a:118:1: error: stray ‘\231’ in program
    In file included from <command-line>:0:0:
    /usr/local/lib/libserial.a:118:529: error: null character(s) ignored [-Werror]
    /usr/local/lib/libserial.a:118:532: error: null character(s) ignored [-Werror]
    In file included from <command-line>:0:0:
    /usr/local/lib/libserial.a:118:1: error: stray ‘\10’ in program
    /usr/local/lib/libserial.a:118:1: error: stray ‘\34’ in program
...

makefile

COMPILER      = -c++
OPTIONS       = -ansi -pedantic-errors -Wall -Wall -Werror -Wextra -o
LINKER_OPT    = -L/usr/lib -lserial  -include/usr/local/lib/libserial.a -lstdc++ -lm

all: bitmap_test

bitmap_test: bitmap_test.cpp bitmap_image.hpp
    $(COMPILER) $(OPTIONS) bitmap_test bitmap_test.cpp $(LINKER_OPT)

我做了研究并了解它是编码的问题,但不知道如何解决它。 非常感谢任何帮助。

修改 图书馆走在正确的道路上:

/sbin/ldconfig -p | grep libserial
    libserial.so.0 (libc6,x86-64) => /usr/local/lib/libserial.so.0
    libserial.so.0 (libc6,x86-64) => /usr/lib/libserial.so.0
    libserial.so (libc6,x86-64) => /usr/local/lib/libserial.so
    libserial.so (libc6,x86-64) => /usr/lib/libserial.so

但是如果按照建议更改Makefile,我会遇到这个问题:

c++ -ansi -pedantic-errors -Wall -Wall -Werror -Wextra -o bitmap_test bitmap_test.cpp -L/usr/local/lib -lstdc++ -lm -lserial
bitmap_test.cpp: In function ‘int main()’:
bitmap_test.cpp:32:40: error: call of overloaded ‘SerialStream(const char [11])’ is ambiguous
 SerialStream serial_port( "/dev/ttyS0" ) ;
                                        ^
bitmap_test.cpp:32:40: note: candidates are:
In file included from bitmap_test.cpp:19:0:
/usr/local/include/SerialStream.h:98:13: note: LibSerial::SerialStream::SerialStream(std::string, LibSerial::SerialStreamBuf::BaudRateEnum, LibSerial::SerialStreamBuf::CharSizeEnum, LibSerial::SerialStreamBuf::ParityEnum, short int, LibSerial::SerialStreamBuf::FlowControlEnum)
             SerialStream( const std::string fileName,
             ^
/usr/local/include/SerialStream.h:84:22: note: LibSerial::SerialStream::SerialStream(std::string, std::ios_base::openmode)
             explicit SerialStream( const std::string fileName, 
                      ^
make: [bitmap_test] Error 1 (ignored)

1 个答案:

答案 0 :(得分:2)

杂散字符通常与源编码有关。

“忽略空字符”诊断通常表示源代码是UTF-16或UTF-32。

但是,makefile显示您将静态库视为强制包含文件:

-include/usr/local/lib/libserial.a

在Windows中使用我的g ++:

> g++ -v --help 2>&1 | find "-include "
  --include                   This switch lacks documentation
  -include <file>             Include the contents of <file> before other