wjwwood / serial

Cross-platform, Serial Port library written in C++
http://wjwwood.github.com/serial/
MIT License
2.13k stars 1.04k forks source link

compiling the example ubuntu using g++ #199

Closed funvill closed 5 years ago

funvill commented 5 years ago

I am having trouble compiling the serial_example.cc. I expect that this is a issue with my understand of the g++ static and shared library and not the serial library.

  1. Clone, make and install (no errors)

    git clone https://github.com/wjwwood/serial.git
    sudo apt-get install build-essential catkin Python
    make
    make test
    make install
  2. Build the example using the following command (builds with no issues) g++ serial_example.cc -lserial -L/tmp/usr/local/lib/ -I../include -o test_serial

  3. When I try to run the example

    /test_serial /dev/ttyS5 9600

    I get the following error

    ./test_serial: symbol lookup error: ./test_serial: undefined symbol: _ZN6serial6Serial5writeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

But when following the instructions in this issue https://github.com/wjwwood/serial/issues/191 and running the example using this command

$ g++ serial_example.cc -lserial -L/tmp/usr/local/lib/ -I../include -o test_serial
$ LD_LIBRARY_PATH=`pwd`/../build/devel/lib ./test_serial /dev/ttyS5 9600

The test_serial application runs without error.

How can I run this example executable without having to include this section LD_LIBRARY_PATH=pwd/../build/devel/lib ?

How do I compile the serial_example with a statically linked serial library?

Thank you

funvill commented 5 years ago

To answer my own question.

This is how you build the libraries as static libraries https://github.com/wjwwood/serial/issues/190 The output of the build is placed in \build\devel\lib\libserial.a

I renamed the library to \build\devel\lib\libserialstatic.a

Then rebuilt the application using the following command g++ serial_example.cc -lserialstatic -L../build/devel/lib/ -I../include -o test_serial

Everything works as expected.