2016-07-05 79 views
0

我是C++新手。我試圖使用libserial錯誤:在包含外部庫後程序中出現' 224'

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 
... 

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) 
+2

究竟應該選擇'-include/usr/local/lib/libserial.a'實際上是這樣嗎?我很確定這是罪魁禍首。 –

+0

由eclipse生成的生成文件顯示該選項,因爲我包含來自C/C++構建/設置/工具設置/包括 –

+0

的文件我覺得我只是將include內部make文件更改爲這個-L/usr/local/lib/libserial.la –

回答

2

流浪人物通常有與源編碼有關。

「空字符忽略」診斷通常會指示源代碼是UTF-16或UTF-32。

然而,makefile文件顯示您處理一個靜態庫作爲強制包含文件:

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

隨着我的G ++在Windows中:

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

感謝您的回覆。你能告訴我應該如何包含.a庫文件嗎?正如你所看到的,我也嘗試過-lserial,並且在/ usr/local/lib中,我有libserial.a和libserial.so,但它不起作用 –

+0

希望'-lserial'能做到這一點。請注意,前綴'lib'和文件擴展名'.a'被刪除。鏈接器添加,因爲它搜索。 –

+0

@HakeemSaad,我唯一能想到的就是在命令末尾加上'-lserial'。這有時可以幫助解決問題。你也可以參考http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-doi-i-fix。 – chris

相關問題