Build library libtorrent debian and link it to program c++ - c++

I always have problems when building libraries and linking them, so I hope someone can give me a hand.
I downloaded libtorrent from here and I've built it like they explain here in the building with autotools section (skipping step 1). The building process was successfull I think, but when I did make check the output was:
============================================================================
Testsuite summary for libtorrent-rasterbar 1.0.5
============================================================================
# TOTAL: 0
# PASS: 0
# SKIP: 0
# XFAIL: 0
# FAIL: 0
# XPASS: 0
# ERROR: 0
============================================================================
Maybe it should say: total X?
I did a little program where I added #include <libtorrent/session.hpp> and when I compile with g++ file.cpp -o file it says libtorrent/session.hpp: No such file or directory.
Should I add some flags to g++ such as -lpthread for other projects and thinks like that?
Thanks
UPDATE:
When installing without building using sudo apt-get install libtorrent-rasterbar-dev and compiling my main.cpp file I get this error:
g++ main.cpp -o file
In file included from /usr/include/libtorrent/session.hpp:49:0,
from main.cpp:2:
/usr/include/libtorrent/config.hpp:46:2: error: #error you must define either BOOST_ASIO_SEPARATE_COMPILATION or BOOST_ASIO_DYN_LINK in your project in order for asio's declarations to be correct. If you're linking dynamically against libtorrent, define BOOST_ASIO_DYN_LINK otherwise BOOST_ASIO_SEPARATE_COMPILATION. You can also use pkg-config or boost build, to automatically apply these defines
#error you must define either BOOST_ASIO_SEPARATE_COMPILATION or BOOST_ASIO_DYN_LINK in your project in \
UPDATE 2:
Modified the main.cpp file to add the the following above the libtorrent #include directives:
#ifndef BOOST_ASIO_DYN_LINK
#define BOOST_ASIO_DYN_LINK
#endif
But then I have this problem:
$ g++ main.cpp
/tmp/ccM2ItFb.o: In function `main':
main.cpp:(.text+0x57): undefined reference to `libtorrent::default_storage_constructor(libtorrent::file_storage const&, libtorrent::file_storage const*, std::string const&, libtorrent::file_pool&, std::vector<unsigned char, std::allocator<unsigned char> > const&)'
main.cpp:(.text+0xb9): undefined reference to `libtorrent::session::~session()'
main.cpp:(.text+0x105): undefined reference to `libtorrent::session::~session()'
/tmp/ccM2ItFb.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x162): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x16e): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x17a): undefined reference to `boost::system::system_category()'
main.cpp:(.text+0x192): undefined reference to `boost::asio::error::get_netdb_category()'
main.cpp:(.text+0x19e): undefined reference to `boost::asio::error::get_addrinfo_category()'
main.cpp:(.text+0x1aa): undefined reference to `boost::asio::error::get_misc_category()'
/tmp/ccM2ItFb.o: In function `boost::asio::error::get_system_category()':
main.cpp (.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
/tmp/ccM2ItFb.o: In function `libtorrent::session::session(libtorrent::fingerprint const&, int, unsigned int)':
main.cpp:(.text._ZN10libtorrent7sessionC2ERKNS_11fingerprintEij[_ZN10libtorrent7sessionC5ERKNS_11fingerprintEij]+0x3c): undefined reference to `libtorrent::rel_clocktime_pools_nolog_resolvecountries_deprecated_dht_ext_()'
main.cpp:(.text._ZN10libtorrent7sessionC2ERKNS_11fingerprintEij[_ZN10libtorrent7sessionC5ERKNS_11fingerprintEij]+0x75): undefined reference to `libtorrent::session::init(std::pair<int, int>, char const*, libtorrent::fingerprint const&, int, unsigned int)'
/tmp/ccM2ItFb.o: In function `void boost::checked_delete<libtorrent::torrent_info const>(libtorrent::torrent_info const*)':
main.cpp:(.text._ZN5boost14checked_deleteIKN10libtorrent12torrent_infoEEEvPT_[_ZN5boost14checked_deleteIKN10libtorrent12torrent_infoEEEvPT_]+0x1a): undefined reference to `libtorrent::torrent_info::~torrent_info()'
collect2: error: ld returned 1 exit status
Also tried compiling using: g++ -I /usr/include/ -L /usr/local/lib -lboost_system -lpthread -lboost_thread main.cpp with the same result.
UPDATE 3:
I was able to solve the problem. I had to compile using:
g++ -I /usr/include/ -L /usr/local/lib -lboost_system -lpthread -lboost_thread main.cpp and add also the link library -ltorrent-rasterbar

Sounds like you've compiled the library but not actually installed it anywhere. An #include directive looks in /usr/include by default, but the libtorrent headers are somewhere in the directory where you built the library. You'll need to either install the library's files into the system directories, or give the compiler an -I option pointing to the libtorrent build directory. (You'll probably also need an -L option when linking, for the same reason.)

Related

boost: mingw: windows 10: undefined reference

How do I add boost logging to a c++ project?
I'm trying to add Boost to my home development environment for the first time. All I want to do right now is be able to use boost's logging implementation to log some errors I'm currently printing to stdout to a file. I started by getting the lambda sample code to build and now I'm trying to add the logging sample code but I'm getting this error:
C:\boost_1_62_0/libs/log/src/text_file_backend.cpp:597: undefined reference to `boost::filesystem::absolute(boost::filesystem::path const&, boost::filesystem::path const&)'
My code is:
/* for logging */
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
namespace logging = boost::log;
void init(){
logging::add_file_log("sample.log");
logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::info
);
}
If I comment out 'logging::add_file_log("sample.log");' it builds just fine
Full build output:
22:15:12 **** Rebuild of configuration Debug for project foo ****
Info: Internal Builder is used for build
g++ -std=c++1y "-IC:\\boost_1_62_0" "-IC:\\boost_1_62_0\\stage\\lib" -O0 -g3 -Wall -c -fmessage-length=0 -DBOOST_LOG_USE_NATIVE_SYSLOG -lboost_filesystem -lboost_system -lboost_thread-mt -lboost_log_setup -lboost_log -o foo_main.o "..\\foo_main.cpp"
g++ -static-libgcc -static-libstdc++ -static "-LC:\\boost_1_62_0\\stage\\lib" -lboost_regex-mgw53-mt-d-1_62 -LC:/boost_1_62_0/stage/lib/ -lboost_regex-mgw53-mt-d-1_62 -o foo.exe foo_main.o -lboost_atomic-mgw53-mt-d-1_62 -lboost_chrono-mgw53-mt-d-1_62 -lboost_container-mgw53-mt-d-1_62 -lboost_context-mgw53-mt-d-1_62 -lboost_coroutine-mgw53-mt-d-1_62 -lboost_date_time-mgw53-mt-d-1_62 -lboost_exception-mgw53-mt-d-1_62 -lboost_filesystem-mgw53-mt-d-1_62 -lboost_graph-mgw53-mt-d-1_62 -lboost_iostreams-mgw53-mt-d-1_62 -lboost_locale-mgw53-mt-d-1_62 -lboost_log_setup-mgw53-mt-d-1_62 -lboost_log-mgw53-mt-d-1_62 -lboost_iostreams-mgw53-mt-d-1_62 -lboost_math_tr1f-mgw53-mt-d-1_62 -lboost_math_tr1l-mgw53-mt-d-1_62 -lboost_math_tr1-mgw53-mt-d-1_62 -lboost_prg_exec_monitor-mgw53-mt-d-1_62 -lboost_program_options-mgw53-mt-d-1_62 -lboost_system-mgw53-mt-d-1_62 -lboost_random-mgw53-mt-d-1_62 -lboost_serialization-mgw53-mt-d-1_62 -lboost_signals-mgw53-mt-d-1_62 -lboost_system-mgw53-mt-d-1_62 -lboost_test_exec_monitor-mgw53-mt-d-1_62 -lboost_thread-mgw53-mt-d-1_62 -lboost_timer-mgw53-mt-d-1_62 -lboost_type_erasure-mgw53-mt-d-1_62 -lboost_unit_test_framework-mgw53-mt-d-1_62 -lboost_wave-mgw53-mt-d-1_62 -lboost_wserialization-mgw53-mt-d-1_62
C:\boost_1_62_0\stage\lib\libboost_log-mgw53-mt-d-1_62.a(text_file_backend.o): In function `make_absolute':
C:\boost_1_62_0/libs/log/src/text_file_backend.cpp:597: undefined reference to `boost::filesystem::absolute(boost::filesystem::path const&, boost::filesystem::path const&)'
C:\boost_1_62_0\stage\lib\libboost_log-mgw53-mt-d-1_62.a(text_file_backend.o): In function `ZN5boost3log10v2s_mt_nt55sinks17text_file_backend30set_file_name_pattern_internalERKNS_10filesystem4pathE':
C:\boost_1_62_0/libs/log/src/text_file_backend.cpp:1264: undefined reference to `boost::filesystem::absolute(boost::filesystem::path const&, boost::filesystem::path const&)'
C:\boost_1_62_0\stage\lib\libboost_log-mgw53-mt-d-1_62.a(text_file_backend.o): In function `ZN5boost10filesystem6existsERKNS0_4pathE':
...enter code here
C:\boost_1_62_0/./boost/filesystem/operations.hpp:872: undefined reference to `boost::filesystem::detail::dir_itr_close(void*&)'
C:\boost_1_62_0\stage\lib\libboost_log-mgw53-mt-d-1_62.a(text_file_backend.o): In function `ZN5boost10filesystem18directory_iteratorC1ERKNS0_4pathE':
C:\boost_1_62_0/./boost/filesystem/operations.hpp:903: undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
C:\boost_1_62_0\stage\lib\libboost_log-mgw53-mt-d-1_62.a(text_file_backend.o): In function `ZN5boost10filesystem18directory_iterator9incrementEv':
C:\boost_1_62_0/./boost/filesystem/operations.hpp:939: undefined reference to `boost::filesystem::detail::directory_iterator_increment(boost::filesystem::directory_iterator&, boost::system::error_code*)'
C:\boost_1_62_0\stage\lib\libboost_log-mgw53-mt-d-1_62.a(text_file_backend.o): In function `ZN5boost10filesystem4pathaSINS0_15directory_entryEEENS_9enable_ifINS0_11path_traits11is_pathableINS_5decayIT_E4typeEEERS1_E4typeERKS8_':
C:\boost_1_62_0/./boost/filesystem/path.hpp:202: undefined reference to `boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)'
collect2.exe: error: ld returned 1 exit status
22:15:18 Build Finished (took 5s.607ms)
I am doing this on a windows 10 machine running Eclipse Version: Neon.1a Release (4.6.1). I am using a mingw compiler, gcc (GCC) version 5.3.0.
I built my boost libraries using this command:
b2 toolset=gcc cxxflags=-std=c++1y -a
The absolute path to my boost_filesystem library is:
C:\boost_1_62_0\stage\lib\libboost_filesystem-mgw53-mt-d-1_62.a

Poco library linking errors in ubuntu platform

I have downloaded the latest Poco library poco-1.7.3.tar. Configured with few properties and did make install.
Tried the following sample helloworld program.
#include <iostream>
#include <Poco/Util/Application.h>
class HelloPocoApplication : public Poco::Util::Application
{
protected:
virtual int main(const std::vector<std::string> &args)
{
std::cout << "Hello, POCO C++ Libraries!" << std::endl;
return EXIT_OK;
}
};
POCO_APP_MAIN(HelloPocoApplication);
Compiled it using
g++ -I poco-1.7.3/Util/include -I poco-1.7.3/XML/include -I poco-1.7.3/JSON/include -I poco-1.7.3/Foundation/include -L poco-1.7.3/lib/Linux/x86_64 -lPocoUtil -lPocoFoundation -lPocoXML -lPocoJSON helloworld.cpp -o prog
But it is throwing following errors
/tmp/ccFvl4ll.o: In function `main':
helloworld.cpp:(.text+0x4f): undefined reference to `Poco::Util::Application::init(int, char**)'
helloworld.cpp:(.text+0xd9): undefined reference to `Poco::Logger::log(Poco::Exception const&)'
/tmp/ccFvl4ll.o: In function `Poco::RefCountedObject::release() const':
helloworld.cpp:(.text._ZNK4Poco16RefCountedObject7releaseEv[_ZNK4Poco16RefCountedObject7releaseEv]+0x6e): undefined reference to `Poco::Bugcheck::unexpected(char const*, int)'
/tmp/ccFvl4ll.o: In function `Poco::Util::Application::logger() const':
helloworld.cpp:(.text._ZNK4Poco4Util11Application6loggerEv[_ZNK4Poco4Util11Application6loggerEv]+0x2c): undefined reference to `Poco::Bugcheck::nullPointer(char const*, char const*, int)'
/tmp/ccFvl4ll.o: In function `HelloPocoApplication::HelloPocoApplication()':
helloworld.cpp:(.text._ZN20HelloPocoApplicationC2Ev[_ZN20HelloPocoApplicationC5Ev]+0x14): undefined reference to `Poco::Util::Application::Application()'
/tmp/ccFvl4ll.o:(.gcc_except_table+0x2c): undefined reference to `typeinfo for Poco::Exception'
/tmp/ccFvl4ll.o: In function `Poco::AutoPtr<HelloPocoApplication>::operator->()':
helloworld.cpp:(.text._ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv[_ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv]+0x3a): undefined reference to `Poco::NullPointerException::NullPointerException(int)'
helloworld.cpp:(.text._ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv[_ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv]+0x3f): undefined reference to `Poco::NullPointerException::~NullPointerException()'
helloworld.cpp:(.text._ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv[_ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv]+0x44): undefined reference to `typeinfo for Poco::NullPointerException'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x20): undefined reference to `Poco::Util::Application::name() const'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x28): undefined reference to `Poco::Util::Application::initialize(Poco::Util::Application&)'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x30): undefined reference to `Poco::Util::Application::uninitialize()'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x38): undefined reference to `Poco::Util::Application::reinitialize(Poco::Util::Application&)'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x40): undefined reference to `Poco::Util::Application::defineOptions(Poco::Util::OptionSet&)'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x48): undefined reference to `Poco::Util::Application::run()'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x50): undefined reference to `Poco::Util::Application::handleOption(std::string const&, std::string const&)'
/tmp/ccFvl4ll.o: In function `HelloPocoApplication::~HelloPocoApplication()':
helloworld.cpp:(.text._ZN20HelloPocoApplicationD2Ev[_ZN20HelloPocoApplicationD5Ev]+0x1f): undefined reference to `Poco::Util::Application::~Application()'
/tmp/ccFvl4ll.o:(.rodata._ZTI20HelloPocoApplication[_ZTI20HelloPocoApplication]+0x10): undefined reference to `typeinfo for Poco::Util::Application'
collect2: error: ld returned 1 exit status
Can you please help me?
I managed to run exactly that code but using CMake rather than Makefile and it worked. you have just to change the paths according to your machine.
Here's my CMakeLists.txt :
cmake_minimum_required(VERSION 2.8.3)
project(tutocpp14)
set(Poco_DIR "/usr/local/lib/cmake/Poco/")
set(Poco_INCLUDE_DIRS "/usr/include/Poco/")
find_package(Poco REQUIRED COMPONENTS Foundation Net XML Util) # add other components here
# check c++11 / c++0x
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11 " COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "-std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "-std=c++0x")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
include_directories( ${Poco_INCLUDE_DIRS})
add_executable(publisher src/publisher.cpp)
target_link_libraries(publisher ${Poco_LIBRARIES})
Cheers,
Checking with Poco documents it seems it should work. Looking at an example here, and its makefile, I suspect the order of your library is reversed. Assuming that paths are correct (since ld didn't report on that) I would say that linking order is incorrect. See here Why.
So I suggest you change your command to
g++ -I poco-1.7.3/Util/include -I poco-1.7.3/Foundation/include -L poco-1.7.3/lib/Linux/x86_64 -lPocoFoundation -lPocoUtil helloworld.cpp -o prog
in case those examples goes out of scope somehow in future, here is the code and makefile copied.
#include <iostream>
#include <Poco/Util/Application.h>
class HelloPocoApplication : public Poco::Util::Application
{
protected:
virtual int main(const std::vector<std::string> &args)
{
std::cout << "Hello, POCO C++ Libraries!" << std::endl;
return EXIT_OK;
}
};
POCO_APP_MAIN(HelloPocoApplication);
Note: Remember to restore the tabs instead of spaces in makefile code!
POCO_LIBS=-lPocoFoundation -lPocoUtil
all: hello-poco
clean:
rm -f hello-poco
hello-poco: hello-poco.cpp
$(CXX) $(POCO_LIBS) -o hello-poco hello-poco.cpp
Update:
With all above said, I have to put a note on strangeness of your error especially Poco::Logger which is found in foundation library. So it seems that library does not get linked. I would suggest two things:
1. Check if its not corrupted. You can do that by cleaning and recompiling
2. Try to install in standard path so that you avoid linking paths
I know all these are not definitive (guess works at best) but will be useful to provide you hints of where the issue lies.
Your original library linking order was fine, but you are missing XML and JSON (Util depends on these libraries). Although, the link errors you've got indicate that you may be either missing Foundation library or mixing library versions.
$ echo $POCO_BASE
/tmp/poco
$ pwd
/tmp/poco/test
$ g++ -I $POCO_BASE/Util/include -I $POCO_BASE/Foundation/include -L $POCO_BASE/lib/Linux/x86_64 -lPocoUtil -lPocoXML -lPocoJSON -lPocoFoundation helloworld.cpp -o prog
try this command to compile.
g++ <src_file>.cpp -lPocoFoundation -lPocoJSON -lPocoUtil -lPocoJWT
-o <binary_name>

Boost.test cannot find main

I'm working with gcc 4.8, boost 1.59 on kubuntu 12.04.
I wrote a simple main.cpp file:
#define BOOST_TEST_MODULE My_Module
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE( foo )
{}
This doesn't work when I build with
g++ -std=c++11 main.cpp -I/usr/local/include -L/usr/local/lib -lboost_unit_test_framework -o test
I get a bunch of linker errors:
/usr/lib/x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to 'main'
/tmp/cc57ppN0.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x131): undefined reference to `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, unsigned long)'
/tmp/cc57ppN0.o: In function `boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&, boost::unit_test::basic_cstring<char const>)':
main.cpp:(.text._ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE[_ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE]+0x6d): undefined reference to `boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>, boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&)'
collect2: erreur: ld a retourné 1 code d'état d'exécution
What does undefined reference to 'main' means??? Well, I know that it is because it could not find main() but why? AFAIK the syntax of my file is correct. It should link, no?
You need to insert the following directive at the top of main.cpp:
#define BOOST_TEST_DYN_LINK
It seems that the example in the Boost.test documentation works for static linking only: the directive above is required, however, for dynamic linking.
See e.g C++ Unit Testing With Boost.Test for further details.
OK, I found the solution!
It seems that, since 1.34.1, boost.test no longer contains main() in dynamic (.so) version. See here. So I wanted to link with the static and I also learned that gcc prefers the dynamic libraries over the static ones for the same name!. Thus, I changed my compile command to:
g++ -std=c++11 main.cpp -I/usr/local/include -L/usr/local/lib -lboost_unit_test_framework -static -o test
...and it worked fine!
I also tested with two files ... main.cpp test1.cpp and the run executed all the test cases correctly.
Thank you, I hope this can help someone else!

Program with protocol-buffers don't compile with MinGW-w64: "undefined reference to google::protobuf:: ..."

I have installed the libprotobuf-dev=2.6.0-4 and protobuf-compiler=2.6.0-4 packages from Debian Jessie repository. Now I'm trying to compile a program that use the 'addressbook.proto' file from the Google Developers example with the MinGW-w64 compiler. I'm using Ubuntu 14.04.
With this command the program works:
$ g++ main.cpp addressbook.pb.cc -lprotobuf
But I want to compile for Windows too.
I added the symlink: /usr/include/google -> /usr/i686-w64-mingw32/include/google.
$ i686-w64-mingw32-g++ main.cpp addressbook.pb.cc -lprotobuf
/usr/bin/i686-w64-mingw32-ld: cannot find -lprotobuf
collect2: error: ld returned 1 exit status
With the library location still not working:
$ i686-w64-mingw32-g++ -L /usr/lib/i386-linux-gnu/ main.cpp addressbook.pb.cc -lprotobuf
/tmp/ccB1VJyR.o:main.cpp:(.text$_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv[__ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv]+0x7): undefined reference to `google::protobuf::internal::empty_string_'
/tmp/ccB1VJyR.o:main.cpp:(.text$_ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv[__ZN6google8protobuf8internal27GetEmptyStringAlreadyInitedEv]+0x2f): undefined reference to `google::protobuf::internal::empty_string_'
/tmp/ccPz4uiI.o:addressbook.pb.cc:(.text+0x78): undefined reference to `google::protobuf::DescriptorPool::generated_pool()'
/tmp/ccPz4uiI.o:addressbook.pb.cc:(.text+0x87): undefined reference to `google::protobuf::DescriptorPool::FindFileByName(std::string const&) const'
...
libprotobuf-dev contains library headers and pre-built binaries for your system. If you are cross-compiling you need to compile library from sources to target system as well. Something like "./configure CC=i686-w64-mingw32-g++" in library sources directory should do the job.

undefined referance to LibSerial

So i'm writing a serial transmision program, and have just changed over to using C++, it been a while since I used C++
(I've been working with C recently, and before that java)
Now I need to use LibSerial,
(it seems much simpler to use than C's termios)
my code is:
//gen1.cpp
#include "string2num.h" // a custom header
#include <iostream>
#include <SerialStream.h>
using namespace LibSerial;
//using namespace std;
int main(int argc, char*argv[])
{
if (argc<2)
{
std::cout<<argv[0]<<"requires the device name eg \"dev/tty0\" as a parameter\nterminating.\n";
return 1;
}
SerialStream theSerialStream(argv[1]); //open the device
return 0;
}
When I compile the output:
g++ -Wall -o gen1 gen1.cpp string2num.o
/tmp/cchPBWgx.o: In function `main':
gen1.cpp:(.text+0x121): undefined reference to `LibSerial::SerialStream::SerialStream(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Ios_Openmode)'
/tmp/cchPBWgx.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x24): undefined reference to `LibSerial::SerialStreamBuf::showmanyc()'
/tmp/cchPBWgx.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x28): undefined reference to `LibSerial::SerialStreamBuf::xsgetn(char*, int)'
/tmp/cchPBWgx.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x2c): undefined reference to `LibSerial::SerialStreamBuf::underflow()'
/tmp/cchPBWgx.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x34): undefined reference to `LibSerial::SerialStreamBuf::pbackfail(int)'
/tmp/cchPBWgx.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x38): undefined reference to `LibSerial::SerialStreamBuf::xsputn(char const*, int)'
/tmp/cchPBWgx.o:(.rodata._ZTVN9LibSerial15SerialStreamBufE[vtable for LibSerial::SerialStreamBuf]+0x3c): undefined reference to `LibSerial::SerialStreamBuf::overflow(int)'
collect2: ld returned 1 exit status
make: *** [gen1] Error 1
This is the linker complaining that it cannot find the functions referenced by the libserial header file.
If I look on my Linux system to see how the shared library is called:
$ dpkg -L libserial0
...
/usr/lib/libserial.so.0.0.0
/usr/lib/libserial.so.0
On my system this implies I would add -lserial as a g++ option (aka link with libserial.so) this would turn your compilation command into
g++ -Wall -lserial -o gen1 gen1.cpp string2num.o
Including the header file is not enough - you also need to link with the library that implements SerialStream. Assuming it is a static library called serstream.a (it is almost certainly actually called something else):
g++ -Wall -o gen1 gen1.cpp string2num.o serstream.a
old thread, but i still use Libserial. here the completed answer
My working setup.
Ubuntu 18.04
g++ 7.3.0
1) Install package for libserial
apt install libserial-dev
2) check for your headers(.h) and .so files
dpkg -l libserial0
dpkg -l libserial-dev
the first command give you the directory of shared library and the second gives you the headers location.
3) Your code.
I have to change a little your code, first i delete the custom header and modifing the constuctor call to this.
SerialStream theSerialStream;
4) compile with g++
Here my compiling command
g++ -o test -I/usr/include test.cpp -L/usr/lib/x86_64-linux-gnu -lserial -lpthread
check for the -lpthread linking option, beacuse Libserial uses mutex.
In Ubuntu/Debian make sure you have to libserial-dev package installed and use the '-lserial' flag for gcc.