c++ - 'SerialStream' does not name a type -
i'm using ubuntu 14.04. want use libserial
project described here. installed library using sudo apt-get install libserial-dev
.
i've written little program (well, it's not program):
#include "serialstream.h" #include <iostream> #define port "/dev/ttyusb0" serialstream ardu; using namespace std; using namespace libserial;
but compiler says: ‘serialstream’ not name type
any help?
edit: after placing serialstream ardu
after namespace-line problem more strange:
g++ main.cpp -o arducom /tmp/ccnzzing.o: in funktion `main': main.cpp:(.text+0x7a): not defined reference `libserial::serialstream::open(std::string, std::_ios_openmode)' main.cpp:(.text+0x12d): not defined reference `libserial::serialstream::setbaudrate(libserial::serialstreambuf::baudrateenum)' main.cpp:(.text+0x181): not defined reference `libserial::serialstream::setcharsize(libserial::serialstreambuf::charsizeenum)' main.cpp:(.text+0x1d5): not defined reference `libserial::serialstream::setparity(libserial::serialstreambuf::parityenum)' main.cpp:(.text+0x229): not defined reference `libserial::serialstream::setnumofstopbits(short)' main.cpp:(.text+0x27d): not defined reference `libserial::serialstream::setflowcontrol(libserial::serialstreambuf::flowcontrolenum)' /tmp/ccnzzing.o:(.rodata._ztvn9libserial15serialstreambufe[_ztvn9libserial15serialstreambufe]+0x48): not defined reference `libserial::serialstreambuf::showmanyc()' /tmp/ccnzzing.o:(.rodata._ztvn9libserial15serialstreambufe[_ztvn9libserial15serialstreambufe]+0x50): not defined reference `libserial::serialstreambuf::xsgetn(char*, long)' /tmp/ccnzzing.o:(.rodata._ztvn9libserial15serialstreambufe[_ztvn9libserial15serialstreambufe]+0x58): not defined reference `libserial::serialstreambuf::underflow()' /tmp/ccnzzing.o:(.rodata._ztvn9libserial15serialstreambufe[_ztvn9libserial15serialstreambufe]+0x68): not defined reference `libserial::serialstreambuf::pbackfail(int)' /tmp/ccnzzing.o:(.rodata._ztvn9libserial15serialstreambufe[_ztvn9libserial15serialstreambufe]+0x70): not defined reference `libserial::serialstreambuf::xsputn(char const*, long)' /tmp/ccnzzing.o:(.rodata._ztvn9libserial15serialstreambufe[_ztvn9libserial15serialstreambufe]+0x78): not defined reference `libserial::serialstreambuf::overflow(int)'
first of have defined object of type serialstream
namespace libserial
without qualifying it:
#include "serialstream.h" #include <iostream> #define port "/dev/ttyusb0" serialstream ardu; // error type unqualified using namespace std; using namespace libserial;
there number of ways qualify type. 1 placing definition after using declaration of namespace type defined in:
#include "serialstream.h" #include <iostream> #define port "/dev/ttyusb0" using namespace std; using namespace libserial; // qualified compiler searching through // declared namespaces , finding in `namespace libserial`. serialstream ardu;
another way qualify typename explicitly belonging in specific namespace:
libserial::serialstream ardu; // qualifies name
having done that, second problem compiler needs know libserial
library located in file system in order able link it.
assuming installed library default place maybe enough:
g++ main.cpp -o arducom -lserial
otherwise may have specify library using -l switch:
g++ main.cpp -o arducom -wl,-rpath,/path/to/library/folder -l/path/to/library/folder -lserial
the libserial
library built using autotools so, if built , installed source provides linking instructions part of install process.
the instructions this:
---------------------------------------------------------------------- libraries have been installed in: /path/to/libserial/lib if ever happen want link against installed libraries in given directory, libdir, must either use libtool, , specify full pathname of library, or use '-llibdir' flag during linking , @ least 1 of following: - add libdir 'ld_library_path' environment variable during execution - add libdir 'ld_run_path' environment variable during linking - use '-wl,-rpath -wl,libdir' linker flag - have system administrator add libdir '/etc/ld.so.conf' see operating system documentation shared libraries more information, such ld(1) , ld.so(8) manual pages. ----------------------------------------------------------------------
Comments
Post a Comment