Inclusion pcapplusplus in project via CMake - c++

I installed pcapplusplus on Ubuntu (Downloaded package from here: https://github.com/seladb/PcapPlusPlus/releases/tag/v21.11). The example that was in the archive compiles and works, everything is fine with it! But when I try to include the library in my project using CMake nothing works.
I write a line in CMakeLists.txt file:
include_directories("/usr/local/include/pcapplusplus")
After that, the header files are connected to the project. However, the project does not compile, various errors appear depending on the functions that I use. Most likely the linker does not see the files: libCommon++.a, libPacket++.a, and libPcap++.a.
I tried to connect them like this:
target_link_libraries(${PROJECT_NAME} libCommon++.a libPacket++.a libPcap++.a)
But it did not help.
Tried this:
find_package(pcapplusplus REQUIRED)
include_directories(${PCAPPLUSPLUS_INCLUDE_DIRS})
This didn't help either.
In fact, other people have already encountered such a problem, for example, netleap tom wrote about this on the StackOverflow. cmake linking against static libraries - do you have to tell cmake where to look?
However, no one there suggested a solution to him. I hope someone will tell me what to do.
udp.
Hello World from here for example:
#include <IPv4Layer.h>
#include <Packet.h>
#include <PcapFileDevice.h>
int main(int argc, char* argv[])
{
pcpp::PcapFileReaderDevice reader("1_packet.pcap");
if (!reader.open())
{
printf("Error opening the pcap file\n");
return 1;
}
pcpp::RawPacket rawPacket;
if (!reader.getNextPacket(rawPacket))
{
printf("Couldn't read the first packet in the file\n");
return 1;
}
if (parsedPacket.isPacketOfType(pcpp::IPv4))
{
pcpp::IPv4Address srcIP = parsedPacket.getLayerOfType<pcpp::IPv4Layer>()->getSrcIpAddress();
pcpp::IPv4Address destIP = parsedPacket.getLayerOfType<pcpp::IPv4Layer>()->getDstIpAddress();
printf("Source IP is '%s'; Dest IP is '%s'\n", srcIP.toString().c_str(), destIP.toString().c_str());
}
reader.close();
return 0;
}
If I add only this to CMake:
include_directories("/usr/local/include/pcapplusplus")
I have the following errors:
/usr/bin/ld: CMakeFiles/test.dir/main.cpp.o: in function `pcpp::Packet::~Packet()':
main.cpp:(.text._ZN4pcpp6PacketD2Ev[_ZN4pcpp6PacketD5Ev]+0x17): undefined reference to `pcpp::Packet::destructPacketData()'
/usr/bin/ld: CMakeFiles/test.dir/main.cpp.o: in function `pcpp::Packet::~Packet()':
main.cpp:(.text._ZN4pcpp6PacketD0Ev[_ZN4pcpp6PacketD5Ev]+0x17): undefined reference to `pcpp::Packet::destructPacketData()'
/usr/bin/ld: CMakeFiles/test.dir/main.cpp.o: in function `pcpp::IPv4Layer* pcpp::Packet::getLayerOfType<pcpp::IPv4Layer>(bool) const':
main.cpp:(.text._ZNK4pcpp6Packet14getLayerOfTypeINS_9IPv4LayerEEEPT_b[_ZNK4pcpp6Packet14getLayerOfTypeINS_9IPv4LayerEEEPT_b]+0x1b): undefined reference to `typeinfo for pcpp::IPv4Layer'
/usr/bin/ld: main.cpp:(.text._ZNK4pcpp6Packet14getLayerOfTypeINS_9IPv4LayerEEEPT_b[_ZNK4pcpp6Packet14getLayerOfTypeINS_9IPv4LayerEEEPT_b]+0x22): undefined reference to `typeinfo for pcpp::Layer'
/usr/bin/ld: main.cpp:(.text._ZNK4pcpp6Packet14getLayerOfTypeINS_9IPv4LayerEEEPT_b[_ZNK4pcpp6Packet14getLayerOfTypeINS_9IPv4LayerEEEPT_b]+0x4e): undefined reference to `typeinfo for pcpp::IPv4Layer'
/usr/bin/ld: main.cpp:(.text._ZNK4pcpp6Packet14getLayerOfTypeINS_9IPv4LayerEEEPT_b[_ZNK4pcpp6Packet14getLayerOfTypeINS_9IPv4LayerEEEPT_b]+0x55): undefined reference to `typeinfo for pcpp::Layer'
/usr/bin/ld: CMakeFiles/test.dir/main.cpp.o: in function `main.cold':
main.cpp:(.text.unlikely+0x58): undefined reference to `pcpp::Packet::destructPacketData()'
/usr/bin/ld: main.cpp:(.text.unlikely+0x63): undefined reference to `pcpp::RawPacket::~RawPacket()'
/usr/bin/ld: main.cpp:(.text.unlikely+0x8a): undefined reference to `pcpp::IFileDevice::~IFileDevice()'
More here: image.
If I add this to CMake:
target_link_libraries(${PROJECT_NAME} libCommon++.a libPacket++.a libPcap++.a)
I have the following errors (first five):
/usr/bin/ld: /usr/local/lib/libPacket++.a(EthLayer.o): in function `pcpp::EthLayer::toString[abi:cxx11]() const':
/tmp/cirrus-ci-build/PcapPlusPlus/Packet++/src/EthLayer.cpp:104: undefined reference to `pcpp::MacAddress::toString[abi:cxx11]() const'
/usr/bin/ld: /tmp/cirrus-ci-build/PcapPlusPlus/Packet++/src/EthLayer.cpp:104: undefined reference to `pcpp::MacAddress::toString[abi:cxx11]() const'
/usr/bin/ld: /usr/local/lib/libPacket++.a(EthDot3Layer.o): in function `pcpp::EthDot3Layer::toString[abi:cxx11]() const':
/tmp/cirrus-ci-build/PcapPlusPlus/Packet++/src/EthDot3Layer.cpp:36: undefined reference to `pcpp::MacAddress::toString[abi:cxx11]() const'
/usr/bin/ld: /tmp/cirrus-ci-build/PcapPlusPlus/Packet++/src/EthDot3Layer.cpp:36: undefined reference to `pcpp::MacAddress::toString[abi:cxx11]() const'
/usr/bin/ld: /usr/local/lib/libPacket++.a(DhcpLayer.o): in function `pcpp::DhcpLayer::getClientHardwareAddress() const':
/tmp/cirrus-ci-build/PcapPlusPlus/Packet++/src/DhcpLayer.cpp:83: undefined reference to `pcpp::MacAddress::Zero'
/usr/bin/ld: /usr/local/lib/libPacket++.a(PayloadLayer.o): in function `pcpp::PayloadLayer::PayloadLayer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/tmp/cirrus-ci-build/PcapPlusPlus/Packet++/src/PayloadLayer.cpp:24: undefined reference to `pcpp::hexStringToByteArray(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*, unsigned long)'
More here: image2
undefined reference to `pcpp::IFileReaderDevice::IFileReaderDevice(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: main.cpp:(.text.startup+0x63): undefined reference to `vtable for pcpp::PcapFileReaderDevice'
/usr/bin/ld: main.cpp:(.text.startup+0xb5): undefined reference to `pcpp::IFileDevice::~IFileDevice()'
/usr/bin/ld: CMakeFiles/test.dir/main.cpp.o:(.data.rel.ro._ZTIN4pcpp17IFileReaderDeviceE[_ZTIN4pcpp17IFileReaderDeviceE]+0x10): undefined reference to `typeinfo for pcpp::IFileDevice'
/usr/bin/ld: CMakeFiles/test.dir/main.cpp.o:(.data.rel.ro._ZTVN4pcpp17IFileReaderDeviceE[_ZTVN4pcpp17IFileReaderDeviceE]+0x28): undefined reference to `pcpp::IFileDevice::close()'
/usr/bin/ld: CMakeFiles/test.dir/main.cpp.o:(.data.rel.ro._ZTVN4pcpp17IFileReaderDeviceE[_ZTVN4pcpp17IFileReaderDeviceE]+0x38): undefined reference to `pcpp::IPcapDevice::setFilter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: CMakeFiles/test.dir/main.cpp.o:(.data.rel.ro._ZTVN4pcpp17IFileReaderDeviceE[_ZTVN4pcpp17IFileReaderDeviceE]+0x40): undefined reference to `pcpp::IPcapDevice::clearFilter()'
/usr/bin/ld: CMakeFiles/test.dir/main.cpp.o:(.data.rel.ro._ZTVN4pcpp17IFileReaderDeviceE[_ZTVN4pcpp17IFileReaderDeviceE]+0x78): undefined reference to `non-virtual thunk to pcpp::IPcapDevice::setFilter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: CMakeFiles/test.dir/main.cpp.o:(.data.rel.ro._ZTVN4pcpp17IFileReaderDeviceE[_ZTVN4pcpp17IFileReaderDeviceE]+0x80): undefined reference to `non-virtual thunk to pcpp::IPcapDevice::clearFilter()'
collect2: error: ld returned 1 exit status

try this
target_link_libraries(${PROJECT_NAME} Pcap++ Packet++ Common++ pcap pthread)
this is the order as listed in the pcapplusplus example mk file /usr/local/etc/PcapPlusPlus.mk

Solution: https://github.com/gleb-kun/pcappp_hw
As expected, errors occurred due to incorrect library connection using CMake.
A file FindPcapPlusPlus.cmake is required to connect. Add the following lines to the main file CMakeLists.txt:
find_package(PcapPlusPlus REQUIRED)
target_link_libraries(${PROJECT_NAME} ${PcapPlusPlus_LIBRARIES})
FindPcapPlusPlus.cmake file contents:
if (PC_PcapPlusPlus_INCLUDEDIR AND PC_PcapPlusPlus_LIBDIR)
set(PcapPlusPlus_FIND_QUIETLY TRUE)
endif ()
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_PcapPlusPlus REQUIRED PcapPlusPlus)
set(PcapPlusPlus_VERSION ${PC_PcapPlusPlus_VERSION})
mark_as_advanced(PcapPlusPlus_INCLUDE_DIR PcapPlusPlus_LIBRARY)
foreach (LIB_NAME ${PC_PcapPlusPlus_LIBRARIES})
find_library(${LIB_NAME}_PATH ${LIB_NAME} HINTS ${PC_PcapPlusPlus_LIBDIR})
if (${LIB_NAME}_PATH)
list(APPEND PcapPlusPlus_LIBS ${${LIB_NAME}_PATH})
endif ()
endforeach ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PcapPlusPlus
REQUIRED_VARS PC_PcapPlusPlus_INCLUDEDIR PC_PcapPlusPlus_LIBDIR
VERSION_VAR PcapPlusPlus_VERSION
)
if (PcapPlusPlus_FOUND)
set(PcapPlusPlus_INCLUDE_DIRS ${PC_PcapPlusPlus_INCLUDEDIR})
set(PcapPlusPlus_LIBRARIES ${PcapPlusPlus_LIBS})
endif ()
if (PcapPlusPlus_FOUND AND NOT TARGET PcapPlusPlus::PcapPlusPlus)
add_library(PcapPlusPlus::PcapPlusPlus INTERFACE IMPORTED)
set_target_properties(PcapPlusPlus::PcapPlusPlus PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${PcapPlusPlus_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${PcapPlusPlus_LIBRARIES}"
INTERFACE_COMPILE_FLAGS "${PC_PcapPlusPlus_CFLAGS}"
)
endif ()

Related

g++ not linking wayland methods

I was trying to create a Wayland window, and I keep getting these strange linkers errors.
Header:
#include <wayland-client.h>
#include <wayland-client-protocol.h>
#include <stdlib.h>
#include <stdio.h>
namespace dmaf
{
class WINDOW
{
private:
bool Init();
public:
void Run();
WINDOW();
~WINDOW();
};
WINDOW::WINDOW()
{
}
WINDOW::~WINDOW()
{
}
bool WINDOW::Init()
{
return 1;
}
void WINDOW::Run()
{
if (Init())
{
wl_display* display = wl_display_connect(0);
if (display)
printf("h\n");
else
printf("g\n");
if (!display)
return;
wl_display_disconnect(display);
}
}
}
Main:
#include "WAYDMAF.h"
using namespace dmaf;
int main()
{
WINDOW window;
window.Run();
}
Errors:
Package wayland-client-protocol was not found in the pkg-config search path.
Perhaps you should add the directory containing `wayland-client-protocol.pc'
to the PKG_CONFIG_PATH environment variable
No package 'wayland-client-protocol' found
/usr/bin/ld: /tmp/ccImUDBz.o: in function `dmaf::WINDOW::Run()':
dmaf_program.cxx:(.text+0x5a): undefined reference to `wl_display_connect'
/usr/bin/ld: dmaf_program.cxx:(.text+0x92): undefined reference to `wl_display_disconnect'
collect2: error: ld returned 1 exit status
Hello Wayland (more below)
#pop-os: gcc hello_wayland.c helpers.c helpers.h $(pkg-config --cflags --libs=lwayland-client) -o hello_wayland
Must specify package names on the command line
/usr/bin/ld: /tmp/ccx8fSIO.o: warning: relocation against `wl_surface_interface' in read-only section `.text'
/usr/bin/ld: /tmp/ccVVuR6n.o: in function `main':
hello_wayland.c:(.text+0xe4): undefined reference to `wl_display_dispatch'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_display_get_registry':
helpers.c:(.text+0x18): undefined reference to `wl_registry_interface'
/usr/bin/ld: helpers.c:(.text+0x2a): undefined reference to `wl_proxy_marshal_constructor'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_registry_add_listener':
helpers.c:(.text+0x5f): undefined reference to `wl_proxy_add_listener'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_registry_destroy':
helpers.c:(.text+0x79): undefined reference to `wl_proxy_destroy'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_registry_bind':
helpers.c:(.text+0xc5): undefined reference to `wl_proxy_marshal_constructor_versioned'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_compositor_destroy':
helpers.c:(.text+0xeb): undefined reference to `wl_proxy_destroy'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_compositor_create_surface':
helpers.c:(.text+0x10a): undefined reference to `wl_surface_interface'
/usr/bin/ld: helpers.c:(.text+0x11c): undefined reference to `wl_proxy_marshal_constructor'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_pool_set_user_data':
helpers.c:(.text+0x149): undefined reference to `wl_proxy_set_user_data'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_pool_get_user_data':
helpers.c:(.text+0x164): undefined reference to `wl_proxy_get_user_data'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_pool_create_buffer':
helpers.c:(.text+0x1af): undefined reference to `wl_buffer_interface'
/usr/bin/ld: helpers.c:(.text+0x1c1): undefined reference to `wl_proxy_marshal_constructor'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_pool_destroy':
helpers.c:(.text+0x1f1): undefined reference to `wl_proxy_marshal'
/usr/bin/ld: helpers.c:(.text+0x1fd): undefined reference to `wl_proxy_destroy'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_destroy':
helpers.c:(.text+0x218): undefined reference to `wl_proxy_destroy'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_create_pool':
helpers.c:(.text+0x249): undefined reference to `wl_shm_pool_interface'
/usr/bin/ld: helpers.c:(.text+0x25b): undefined reference to `wl_proxy_marshal_constructor'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_buffer_destroy':
helpers.c:(.text+0x287): undefined reference to `wl_proxy_marshal'
/usr/bin/ld: helpers.c:(.text+0x293): undefined reference to `wl_proxy_destroy'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_destroy':
helpers.c:(.text+0x2ae): undefined reference to `wl_proxy_destroy'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_get_shell_surface':
helpers.c:(.text+0x2d8): undefined reference to `wl_shell_surface_interface'
/usr/bin/ld: helpers.c:(.text+0x2ea): undefined reference to `wl_proxy_marshal_constructor'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_add_listener':
helpers.c:(.text+0x31f): undefined reference to `wl_proxy_add_listener'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_set_user_data':
helpers.c:(.text+0x344): undefined reference to `wl_proxy_set_user_data'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_get_user_data':
helpers.c:(.text+0x35f): undefined reference to `wl_proxy_get_user_data'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_destroy':
helpers.c:(.text+0x379): undefined reference to `wl_proxy_destroy'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_pong':
helpers.c:(.text+0x3a4): undefined reference to `wl_proxy_marshal'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_set_toplevel':
helpers.c:(.text+0x3c9): undefined reference to `wl_proxy_marshal'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_surface_set_user_data':
helpers.c:(.text+0x3ef): undefined reference to `wl_proxy_set_user_data'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_surface_get_user_data':
helpers.c:(.text+0x40a): undefined reference to `wl_proxy_get_user_data'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_surface_destroy':
helpers.c:(.text+0x42e): undefined reference to `wl_proxy_marshal'
/usr/bin/ld: helpers.c:(.text+0x43a): undefined reference to `wl_proxy_destroy'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_surface_attach':
helpers.c:(.text+0x476): undefined reference to `wl_proxy_marshal'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_surface_commit':
helpers.c:(.text+0x49b): undefined reference to `wl_proxy_marshal'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_seat_destroy':
helpers.c:(.text+0x4b6): undefined reference to `wl_proxy_destroy'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_seat_get_pointer':
helpers.c:(.text+0x4d5): undefined reference to `wl_pointer_interface'
/usr/bin/ld: helpers.c:(.text+0x4e7): undefined reference to `wl_proxy_marshal_constructor'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_pointer_add_listener':
helpers.c:(.text+0x51c): undefined reference to `wl_proxy_add_listener'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_pointer_set_user_data':
helpers.c:(.text+0x541): undefined reference to `wl_proxy_set_user_data'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_pointer_get_user_data':
helpers.c:(.text+0x55c): undefined reference to `wl_proxy_get_user_data'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_pointer_destroy':
helpers.c:(.text+0x576): undefined reference to `wl_proxy_destroy'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_pointer_set_cursor':
helpers.c:(.text+0x5bc): undefined reference to `wl_proxy_marshal'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `hello_setup_wayland':
helpers.c:(.text+0x5d5): undefined reference to `wl_display_connect'
/usr/bin/ld: helpers.c:(.text+0x638): undefined reference to `wl_display_roundtrip'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `hello_cleanup_wayland':
helpers.c:(.text+0x6a9): undefined reference to `wl_display_disconnect'
/usr/bin/ld: /tmp/ccx8fSIO.o: in function `registry_global':
helpers.c:(.text+0x6d2): undefined reference to `wl_compositor_interface'
/usr/bin/ld: helpers.c:(.text+0x704): undefined reference to `wl_compositor_interface'
/usr/bin/ld: helpers.c:(.text+0x71f): undefined reference to `wl_shm_interface'
/usr/bin/ld: helpers.c:(.text+0x74c): undefined reference to `wl_shm_interface'
/usr/bin/ld: helpers.c:(.text+0x767): undefined reference to `wl_shell_interface'
/usr/bin/ld: helpers.c:(.text+0x794): undefined reference to `wl_shell_interface'
/usr/bin/ld: helpers.c:(.text+0x7ac): undefined reference to `wl_seat_interface'
/usr/bin/ld: helpers.c:(.text+0x7de): undefined reference to `wl_seat_interface'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
^there may be some errors as I didn't try to add all necessary headers^
I've tried a few g++ settings, but nothing.
g++:
g++ program.cxx $(pkg-config --cflags wayland-client-protocol) -o program
g++ program.cxx $(pkg-config --cflags wayland-client) -o program
usr/include:
wayland-egl
wayland-server-protocol
wayland-client
wayland-server-core
wayland-util
wayland-version
wayland-egl-core
wayland-cursor
wayland-client-protocol
wayland-server
wayland-client-core
I've also tried compiling Hello-Wayland, but I got a mountain of the same errors. I'm using Pop!_os, and I don't remember having any problems with X when I was on Ubuntu (Haven't tried X on Pop,and I don't remember using Wayland on Ubuntu).
It seems to only do this to wl_display_connect, wl_display_disconnect, and wl_display_connect_to_fd, so I checked in all of my header files and none of them had wl_display_connect (didn't try the other methods). Is it possible I need some other header files? If so, what do I need?
-Thanks del
Just a small syntax error in your original g++ command:
pkg-config --cflags --libs=lwayland-client
> pkgconf: option doesn't take an argument -- libs
The correct syntax is the following:
pkg-config --cflags --libs wayland-client
> -lwayland-client
A simple g++ command to compile a file and link against libwayland-client.so would therefore be:
g++ waylandapp.c $(pkg-config --cflags --libs wayland-client) -o waylandapp
which will actually turn into
g++ waylandapp.c -lwayland-client -o waylandapp
-l is a universal c/c++ linker flag, for linking libraries.
To learn more about how to use pkg-config, man pkgconf will help.

Linking nghttp2 static library

I want to compile a simple server app using nghtt2_asio in C++.
It compiles perfectly under shared libraries:
g++ server.cpp -O2 -std=c++20 -Wall -Wextra -lnghttp2_asio -lboost_system -lssl -lcrypto -o server
But as I compile it statically:
g++ server.cpp -static -O2 -std=c++20 -Wall -Wextra -o server -lssl -ldl -pthread -lcrypto -ldl -pthread -lnghttp2_asio -lboost_system
the linker gives me these errors:
/usr/bin/ld: /usr/local/lib/libcrypto.a(dso_dlfcn.o): in function `dlfcn_globallookup':
(.text+0x14): attenzione: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/local/lib/libcrypto.a(b_addr.o): in function `BIO_lookup_ex':
(.text+0xd0b): attenzione: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/local/lib/libcrypto.a(b_sock.o): in function `BIO_gethostbyname':
(.text+0x72): attenzione: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_common.o): in function `nghttp2::asio_http2::nghttp2_category_impl::message[abi:cxx11](int) const':
/home/user/Downloads/nghttp2/src/asio_common.cc:40: undefined reference to `nghttp2_strerror'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server.o): in function `int nghttp2::asio_http2::server::http2_handler::on_read<8192ul>(boost::array<unsigned char, 8192ul> const&, unsigned long)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.h:103: undefined reference to `nghttp2_session_mem_recv'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server.o): in function `boost::asio::ssl::detail::engine::engine(ssl_ctx_st*)':
/usr/include/boost/asio/ssl/detail/impl/engine.ipp:55: undefined reference to `BIO_new_bio_pair'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server.o): in function `int nghttp2::asio_http2::server::http2_handler::on_write<65536ul>(boost::array<unsigned char, 65536ul>&, unsigned long&)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.h:129: undefined reference to `nghttp2_session_mem_send'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server.o): in function `int nghttp2::asio_http2::server::http2_handler::on_read<8192ul>(boost::array<unsigned char, 8192ul> const&, unsigned long)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.h:103: undefined reference to `nghttp2_session_mem_recv'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server.o): in function `int nghttp2::asio_http2::server::http2_handler::on_write<65536ul>(boost::array<unsigned char, 65536ul>&, unsigned long&)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.h:129: undefined reference to `nghttp2_session_mem_send'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server.o): in function `int nghttp2::asio_http2::server::http2_handler::on_read<8192ul>(boost::array<unsigned char, 8192ul> const&, unsigned long)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.h:103: undefined reference to `nghttp2_session_mem_recv'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::(anonymous namespace)::on_frame_not_send_callback(nghttp2_session*, nghttp2_frame const*, int, void*)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:230: undefined reference to `nghttp2_submit_rst_stream'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::http2_handler::~http2_handler()':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:258: undefined reference to `nghttp2_session_del'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::http2_handler::start()':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:274: undefined reference to `nghttp2_session_callbacks_new'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `std::_Bind<void (*(nghttp2_session_callbacks*))(nghttp2_session_callbacks*)>::_Bind(std::_Bind<void (*(nghttp2_session_callbacks*))(nghttp2_session_callbacks*)>&&)':
/usr/include/c++/11.1.0/functional:494: undefined reference to `nghttp2_session_callbacks_del'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::http2_handler::start()':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:281: undefined reference to `nghttp2_session_callbacks_set_on_begin_headers_callback'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:283: undefined reference to `nghttp2_session_callbacks_set_on_header_callback'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:285: undefined reference to `nghttp2_session_callbacks_set_on_frame_recv_callback'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:287: undefined reference to `nghttp2_session_callbacks_set_on_data_chunk_recv_callback'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:289: undefined reference to `nghttp2_session_callbacks_set_on_stream_close_callback'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:291: undefined reference to `nghttp2_session_callbacks_set_on_frame_send_callback'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:293: undefined reference to `nghttp2_session_callbacks_set_on_frame_not_send_callback'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:296: undefined reference to `nghttp2_session_server_new'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:302: undefined reference to `nghttp2_submit_settings'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::http2_handler::should_stop() const':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:333: undefined reference to `nghttp2_session_want_read'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:334: undefined reference to `nghttp2_session_want_write'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::http2_handler::stream_error(int, unsigned int)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:47: undefined reference to `nghttp2_submit_rst_stream'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::http2_handler::resume(nghttp2::asio_http2::server::stream&)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:428: undefined reference to `nghttp2_session_resume_data'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::(anonymous namespace)::on_header_callback(nghttp2_session*, nghttp2_frame const*, unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned char, void*)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:109: undefined reference to `nghttp2_submit_rst_stream'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::http2_handler::submit_trailer(nghttp2::asio_http2::server::stream&, std::multimap<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, nghttp2::asio_http2::header_value, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nghttp2::asio_http2::header_value> > >)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:387: undefined reference to `nghttp2_submit_trailer'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::http2_handler::start_response(nghttp2::asio_http2::server::stream&)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:366: undefined reference to `nghttp2_submit_response'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-asio_server_http2_handler.o): in function `nghttp2::asio_http2::server::http2_handler::push_promise(boost::system::error_code&, nghttp2::asio_http2::server::stream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::multimap<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, nghttp2::asio_http2::header_value, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nghttp2::asio_http2::header_value> > >)':
/home/user/Downloads/nghttp2/src/asio_server_http2_handler.cc:454: undefined reference to `nghttp2_submit_push_promise'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-http2.o): in function `nghttp2::http2::determine_window_update_transmission(nghttp2_session*, int)':
/home/user/Downloads/nghttp2/src/http2.cc:577: undefined reference to `nghttp2_session_get_effective_recv_data_length'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/http2.cc:578: undefined reference to `nghttp2_session_get_effective_local_window_size'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/http2.cc:580: undefined reference to `nghttp2_session_get_stream_effective_recv_data_length'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/http2.cc:582: undefined reference to `nghttp2_session_get_stream_effective_local_window_size'
/usr/bin/ld: /usr/local/lib/libnghttp2_asio.a(libnghttp2_asio_la-http2.o): in function `nghttp2::http2::check_nv(unsigned char const*, unsigned long, unsigned char const*, unsigned long)':
/home/user/Downloads/nghttp2/src/http2.cc:698: undefined reference to `nghttp2_check_header_name'
/usr/bin/ld: /home/user/Downloads/nghttp2/src/http2.cc:701: undefined reference to `nghttp2_check_header_value'
collect2: error: ld returned 1 exit status
Can someone explain me what happens?
Can someone explain me what happens?
There are several problems here.
You have unresolved symbols. As n.m. said in a comment, you need to add -libnghttp2.
Your order of libraries on the link line is wrong. Lower-level libraries should follow higher-level libraries on the link line. The right order is something like:
-lnghttp2_asio -libnghttp2 -lboost_system -lssl -lcrypto -ldl
See this blog post for explanation.
You are linking a fully-static binary.
Contrary to popular belief, such binaries (at least on Linux) are significantly less portable than dynamically linked ones.
What the warning is telling you is that IF you try to run this binary on a system that has a different version of GLIBC installed (could be a different system from the one you built on, or even the same system but after an upgrade to a different version of GLIBC), then your binary may crash (and very likely will crash).
You will be much better off not doing a fully-static link.
Note: you don't have to link against libnghttp2_asio etc. dynamically, just against the libc and libdl and libcrypto.

Compiler not finding jpeg and png libraries

I have downloaded and installed this C++ package for plotting and visulisation https://github.com/alandefreitas/matplotplusplus. I have sussessfully linked to it in my CMake file and have no linking errors when including #include <matplot/matplot.h>. However, whenever I use any functions from the library matplot.h I get the following error at compilation.
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::_cimg_jpeg_error_exit(jpeg_common_struct*)':
common.cpp:(.text._ZN12cimg_library4CImgIhE21_cimg_jpeg_error_exitEP18jpeg_common_struct[_ZN12cimg_library4CImgIhE21_cimg_jpeg_error_exitEP18jpeg_common_struct]+0x1e): undefined reference to `jpeg_destroy'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::_save_jpeg(_IO_FILE*, char const*, unsigned int) const':
common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x12b): undefined reference to `jpeg_std_error'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x152): undefined reference to `jpeg_CreateCompress'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x16d): undefined reference to `jpeg_stdio_dest'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x198): undefined reference to `jpeg_set_defaults'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x1b2): undefined reference to `jpeg_set_quality'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x1c6): undefined reference to `jpeg_start_compress'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x2cf): undefined reference to `jpeg_write_scanlines'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x2ed): undefined reference to `jpeg_finish_compress'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE10_save_jpegEP8_IO_FILEPKcj]+0x302): undefined reference to `jpeg_destroy_compress'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::_save_png(_IO_FILE*, char const*, unsigned int) const':
common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x2f4): undefined reference to `png_create_write_struct'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x309): undefined reference to `png_create_info_struct'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x32b): undefined reference to `png_set_longjmp_fn'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x34f): undefined reference to `png_destroy_write_struct'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x409): undefined reference to `png_init_io'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x474): undefined reference to `png_set_IHDR'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x485): undefined reference to `png_write_info'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0xc36): undefined reference to `png_write_image'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0xc43): undefined reference to `png_write_end'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0xc50): undefined reference to `png_destroy_write_struct'
/usr/bin/ld: common.cpp:(.text._ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj[_ZNK12cimg_library4CImgIhE9_save_pngEP8_IO_FILEPKcj]+0x1830): undefined reference to `png_destroy_write_struct'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::save_cimg(char const*, bool) const':
common.cpp:(.text._ZNK12cimg_library4CImgIhE9save_cimgEPKcb[_ZNK12cimg_library4CImgIhE9save_cimgEPKcb]+0x3bb): undefined reference to `compress'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::_load_png(_IO_FILE*, char const*, unsigned int*)':
common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x88): undefined reference to `png_sig_cmp'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0xa2): undefined reference to `png_create_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0xb7): undefined reference to `png_create_info_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0xcd): undefined reference to `png_create_info_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0xef): undefined reference to `png_set_longjmp_fn'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x14a): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x1c9): undefined reference to `png_init_io'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x1d7): undefined reference to `png_set_sig_bytes'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x1e4): undefined reference to `png_read_info'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x20e): undefined reference to `png_get_IHDR'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x252): undefined reference to `png_get_valid'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x280): undefined reference to `png_set_filler'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x28d): undefined reference to `png_read_update_info'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x2c2): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x369): undefined reference to `png_set_expand_gray_1_2_4_to_8'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x389): undefined reference to `png_set_gray_to_rgb'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x3a9): undefined reference to `png_set_tRNS_to_alpha'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x41f): undefined reference to `png_read_image'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x42c): undefined reference to `png_read_end'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x461): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x4f1): undefined reference to `png_set_palette_to_rgb'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x683): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x84a): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj[_ZN12cimg_library4CImgIhE9_load_pngEP8_IO_FILEPKcPj]+0x9d3): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImgList<unsigned char>::_load_cimg(_IO_FILE*, char const*)':
common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0x404): undefined reference to `uncompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0x70c): undefined reference to `uncompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0x93b): undefined reference to `uncompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0xce5): undefined reference to `uncompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0x10f7): undefined reference to `uncompress'
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o):common.cpp:(.text._ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc[_ZN12cimg_library8CImgListIhE10_load_cimgEP8_IO_FILEPKc]+0x1506): more undefined references to `uncompress' follow
/usr/bin/ld: /usr/local/lib/libmatplot.a(common.cpp.o): in function `cimg_library::CImg<unsigned char>::_load_jpeg(_IO_FILE*, char const*)':
common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0x67): undefined reference to `jpeg_std_error'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0xb3): undefined reference to `jpeg_CreateDecompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0xc5): undefined reference to `jpeg_stdio_src'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0xd2): undefined reference to `jpeg_read_header'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0xda): undefined reference to `jpeg_start_decompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0x1f8): undefined reference to `jpeg_read_scanlines'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0x278): undefined reference to `jpeg_finish_decompress'
/usr/bin/ld: common.cpp:(.text._ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc[_ZN12cimg_library4CImgIhE10_load_jpegEP8_IO_FILEPKc]+0x284): undefined reference to `jpeg_destroy_decompress'
/usr/bin/ld: /usr/local/lib/libmatplot.a(network.cpp.o): in function `matplot::network::process_force_layout()':
network.cpp:(.text+0x304e): undefined reference to `nodesoup::size_radiuses(std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, double, double)'
/usr/bin/ld: network.cpp:(.text+0x312a): undefined reference to `nodesoup::fruchterman_reingold(std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, unsigned int, unsigned int, unsigned int, double, std::function<void (std::vector<nodesoup::Point2D, std::allocator<nodesoup::Point2D> > const&, int)>)'
/usr/bin/ld: /usr/local/lib/libmatplot.a(network.cpp.o): in function `matplot::network::process_kawai_layout()':
network.cpp:(.text+0x3842): undefined reference to `nodesoup::size_radiuses(std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, double, double)'
/usr/bin/ld: network.cpp:(.text+0x390c): undefined reference to `nodesoup::kamada_kawai(std::vector<std::vector<unsigned long, std::allocator<unsigned long> >, std::allocator<std::vector<unsigned long, std::allocator<unsigned long> > > > const&, unsigned int, unsigned int, double, double)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/example.dir/build.make:84: example] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/example.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
The errors are plenty, but they are all of the form undefined reference to png_... or undefined reference to jpeg_... except for those that are undefined reference to 'uncompress'. It seems as though CMake is not finding png and jpeg. I definitely do have libjpeg and libpng installed. Why are these errors ocurring? Do I need to add lines to my CMakeLists.txt to find jpeg and png? I am running Ubuntu 20.04, g++ 9.3.0, and cmake 3.16.3.
Here is a very simple example that prodces the error. This is the cmake file
cmake_minimum_required(VERSION 3.10)
project(example)
set(CMAKE_CXX_COMPILER "c++")
find_package(Matplot++)
add_executable(example example.cpp)
target_link_libraries(example PUBLIC matplot)
Here is an example c++ code (pulled directly from the examples on the linked site).
#include <cmath>
#include <matplot/matplot.h>
int main() {
using namespace matplot;
std::vector<double> x = linspace(0, 10, 150);
std::vector<double> y = transform(x, [](auto x) { return cos(5 * x); });
plot(x, y)->color({0, 0.7, 0.9});
title("2-D Line Plot");
xlabel("x");
ylabel("cos(5x)");
show();
return 0;
}
I had the same problem (with Windows MinGW). Thanks to #drescherjm hint (add the option -DBUILD_SHARED_LIBS=ON), these are the steps I used to solve the problem:
git clone http://github.com/alandefreitas/matplotplusplus
cd matplotplusplus/
mkdir compil-release && cd compil-release
rm CMakeCache.txt # if already exists
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX="${YOUR_LIB_PATH}/matplot1.0.1"
make -j4 && make install
Then, and I guess that is a bug, I had to manually copy the .dll to the install path
cp source/matplot/libmatplot.dll ${YOUR_LIB_PATH}/matplot1.0.1/lib/
Hope this works for you.

How to fix "undefined reference to `YAML::operator<<(std::ostream&, YAML::Node const&)'" in cmake

I did a project in manjaro, then decided to switch to ubuntu and everything flew to hell. I've installed libpoco-dev, libtinyxml2-dev and libyaml-cpp-dev
my cmakelist file:
cmake_minimum_required(VERSION 3.13)
project(auchan_handler_microservice)
set(CMAKE_CXX_STANDARD 17)
set(GCC_COVERAGE_COMPILE_FLAGS "-Wall -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set(LIB_DIR "${PROJECT_SOURCE_DIR}/extern")
add_executable(auchan_handler_microservice main.cc)
include_directories(src)
add_subdirectory(src)
option(PACKAGE_TESTS "Build the tests" ON)
if (PACKAGE_TESTS)
enable_testing()
add_subdirectory(tests)
endif ()
find_package(Poco REQUIRED Foundation Net Util DataMySQL)
target_link_libraries(auchan_handler_microservice src)
target_link_libraries(auchan_handler_microservice yaml-cpp tinyxml2)
target_link_libraries(auchan_handler_microservice Poco::Net Poco::Util Poco::DataMySQL)
error:
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `Application::main(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)':
/home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:29: undefined reference to `YAML::LoadFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:31: undefined reference to `YAML::operator<<(std::ostream&, YAML::Node const&)'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:38: undefined reference to `Poco::Net::HTTPServerParams::HTTPServerParams()'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:38: undefined reference to `Poco::Net::ServerSocket::ServerSocket(unsigned short, int)'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:38: undefined reference to `Poco::Net::HTTPServer::HTTPServer(Poco::SharedPtr<Poco::Net::HTTPRequestHandlerFactory, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::Net::HTTPRequestHandlerFactory> >, Poco::Net::ServerSocket const&, Poco::AutoPtr<Poco::Net::HTTPServerParams>)'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:38: undefined reference to `Poco::Net::ServerSocket::~ServerSocket()'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:39: undefined reference to `Poco::Net::TCPServer::start()'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:41: undefined reference to `Poco::Util::ServerApplication::waitForTerminationRequest()'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:38: undefined reference to `Poco::Net::HTTPServer::~HTTPServer()'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:38: undefined reference to `Poco::Net::ServerSocket::~ServerSocket()'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.cc:38: undefined reference to `Poco::Net::HTTPServer::~HTTPServer()'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `Poco::Net::Impl::IPv4SocketAddressImpl::host() const':
/usr/include/Poco/Net/SocketAddressImpl.h:81: undefined reference to `Poco::Net::IPAddress::IPAddress(void const*, unsigned int)'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `Poco::Net::Impl::IPv6SocketAddressImpl::host() const':
/usr/include/Poco/Net/SocketAddressImpl.h:143: undefined reference to `Poco::Net::IPAddress::IPAddress(void const*, unsigned int, unsigned int)'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::Exception::Exception(YAML::Mark const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/include/yaml-cpp/exceptions.h:122: undefined reference to `vtable for YAML::Exception'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::RepresentationException::RepresentationException(YAML::Mark const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/include/yaml-cpp/exceptions.h:155: undefined reference to `vtable for YAML::RepresentationException'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::InvalidNode::InvalidNode()':
/usr/include/yaml-cpp/exceptions.h:198: undefined reference to `vtable for YAML::InvalidNode'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::BadSubscript::BadSubscript()':
/usr/include/yaml-cpp/exceptions.h:228: undefined reference to `vtable for YAML::BadSubscript'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::detail::memory_holder::create_node()':
/usr/include/yaml-cpp/node/detail/memory.h:37: undefined reference to `YAML::detail::memory::create_node()'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::detail::node_ref::mark_defined()':
/usr/include/yaml-cpp/node/detail/node_ref.h:30: undefined reference to `YAML::detail::node_data::mark_defined()'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::detail::node_ref::set_null()':
/usr/include/yaml-cpp/node/detail/node_ref.h:36: undefined reference to `YAML::detail::node_data::set_null()'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::detail::node_ref::set_scalar(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/include/yaml-cpp/node/detail/node_ref.h:37: undefined reference to `YAML::detail::node_data::set_scalar(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::Node::EnsureNodeExists() const':
/usr/include/yaml-cpp/node/impl.h:54: undefined reference to `YAML::InvalidNode::~InvalidNode()'
/usr/bin/ld: /usr/include/yaml-cpp/node/impl.h:54: undefined reference to `typeinfo for YAML::InvalidNode'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::Node::Type() const':
/usr/include/yaml-cpp/node/impl.h:78: undefined reference to `YAML::InvalidNode::~InvalidNode()'
/usr/bin/ld: /usr/include/yaml-cpp/node/impl.h:78: undefined reference to `typeinfo for YAML::InvalidNode'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::Node::Scalar[abi:cxx11]() const':
/usr/include/yaml-cpp/node/impl.h:158: undefined reference to `YAML::InvalidNode::~InvalidNode()'
/usr/bin/ld: /usr/include/yaml-cpp/node/impl.h:158: undefined reference to `typeinfo for YAML::InvalidNode'
/usr/bin/ld: /usr/include/yaml-cpp/node/impl.h:159: undefined reference to `YAML::detail::node_data::empty_scalar[abi:cxx11]'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `void YAML::Node::Assign<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/include/yaml-cpp/node/impl.h:222: undefined reference to `YAML::InvalidNode::~InvalidNode()'
/usr/bin/ld: /usr/include/yaml-cpp/node/impl.h:222: undefined reference to `typeinfo for YAML::InvalidNode'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `HandlerFactory::HandlerFactory()':
/home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler_factory/handler_factory.h:9: undefined reference to `Poco::Net::HTTPRequestHandlerFactory::HTTPRequestHandlerFactory()'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::Node YAML::Node::operator[]<char [5]>(char const (&) [5])':
/usr/include/yaml-cpp/node/impl.h:388: undefined reference to `YAML::InvalidNode::~InvalidNode()'
/usr/bin/ld: /usr/include/yaml-cpp/node/impl.h:388: undefined reference to `typeinfo for YAML::InvalidNode'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::detail::node& YAML::detail::node_data::get<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<YAML::detail::memory_holder>)':
/usr/include/yaml-cpp/node/detail/impl.h:112: undefined reference to `YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>)'
/usr/bin/ld: /usr/include/yaml-cpp/node/detail/impl.h:115: undefined reference to `YAML::BadSubscript::~BadSubscript()'
/usr/bin/ld: /usr/include/yaml-cpp/node/detail/impl.h:115: undefined reference to `typeinfo for YAML::BadSubscript'
/usr/bin/ld: /usr/include/yaml-cpp/node/detail/impl.h:126: undefined reference to `YAML::detail::node_data::insert_map_pair(YAML::detail::node&, YAML::detail::node&)'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `YAML::detail::node& YAML::detail::node_data::convert_to_node<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<YAML::detail::memory_holder>)':
/usr/include/yaml-cpp/node/detail/impl.h:179: undefined reference to `YAML::detail::memory_holder::merge(YAML::detail::memory_holder&)'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTV11Application[_ZTV11Application]+0x20): undefined reference to `Poco::Util::Application::name() const'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTV11Application[_ZTV11Application]+0x28): undefined reference to `Poco::Util::Application::initialize(Poco::Util::Application&)'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTV11Application[_ZTV11Application]+0x30): undefined reference to `Poco::Util::Application::uninitialize()'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTV11Application[_ZTV11Application]+0x38): undefined reference to `Poco::Util::Application::reinitialize(Poco::Util::Application&)'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTV11Application[_ZTV11Application]+0x40): undefined reference to `Poco::Util::ServerApplication::defineOptions(Poco::Util::OptionSet&)'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTV11Application[_ZTV11Application]+0x48): undefined reference to `Poco::Util::ServerApplication::run()'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTV11Application[_ZTV11Application]+0x50): undefined reference to `Poco::Util::Application::handleOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `Application::~Application()':
/home/sschiz/CLionProjects/auchan-handler-microservice/src/server_application/app.h:11: undefined reference to `Poco::Util::ServerApplication::~ServerApplication()'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTVN4Poco3Net4Impl21IPv6SocketAddressImplE[_ZTVN4Poco3Net4Impl21IPv6SocketAddressImplE]+0x50): undefined reference to `Poco::Net::Impl::IPv6SocketAddressImpl::toString[abi:cxx11]() const'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `Poco::Net::Impl::IPv6SocketAddressImpl::~IPv6SocketAddressImpl()':
/usr/include/Poco/Net/SocketAddressImpl.h:118: undefined reference to `Poco::Net::Impl::SocketAddressImpl::~SocketAddressImpl()'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTVN4Poco3Net4Impl21IPv4SocketAddressImplE[_ZTVN4Poco3Net4Impl21IPv4SocketAddressImplE]+0x50): undefined reference to `Poco::Net::Impl::IPv4SocketAddressImpl::toString[abi:cxx11]() const'
/usr/bin/ld: ../src/libsrc.a(app.cc.o): in function `Poco::Net::Impl::IPv4SocketAddressImpl::~IPv4SocketAddressImpl()':
/usr/include/Poco/Net/SocketAddressImpl.h:56: undefined reference to `Poco::Net::Impl::SocketAddressImpl::~SocketAddressImpl()'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTIN4Poco3Net4Impl21IPv6SocketAddressImplE[_ZTIN4Poco3Net4Impl21IPv6SocketAddressImplE]+0x10): undefined reference to `typeinfo for Poco::Net::Impl::SocketAddressImpl'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTIN4Poco3Net4Impl21IPv4SocketAddressImplE[_ZTIN4Poco3Net4Impl21IPv4SocketAddressImplE]+0x10): undefined reference to `typeinfo for Poco::Net::Impl::SocketAddressImpl'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.ro._ZTI11Application[_ZTI11Application]+0x10): undefined reference to `typeinfo for Poco::Util::ServerApplication'
/usr/bin/ld: ../src/libsrc.a(app.cc.o):(.data.rel.local.DW.ref._ZTIN4YAML9ExceptionE[DW.ref._ZTIN4YAML9ExceptionE]+0x0): undefined reference to `typeinfo for YAML::Exception'
/usr/bin/ld: ../src/libsrc.a(handler_factory.cc.o): in function `RequestHandler::RequestHandler()':
/home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.h:9: undefined reference to `Poco::Net::HTTPRequestHandler::HTTPRequestHandler()'
/usr/bin/ld: ../src/libsrc.a(handler_factory.cc.o): in function `HandlerFactory::~HandlerFactory()':
/home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler_factory/handler_factory.h:9: undefined reference to `Poco::Net::HTTPRequestHandlerFactory::~HTTPRequestHandlerFactory()'
/usr/bin/ld: ../src/libsrc.a(handler_factory.cc.o):(.data.rel.ro._ZTI14HandlerFactory[_ZTI14HandlerFactory]+0x10): undefined reference to `typeinfo for Poco::Net::HTTPRequestHandlerFactory'
/usr/bin/ld: ../src/libsrc.a(request_handler.cc.o): in function `RequestHandler::handleRequest(Poco::Net::HTTPServerRequest&, Poco::Net::HTTPServerResponse&)':
/home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.cc:20: undefined reference to `Poco::Net::HTTPMessage::getContentLength() const'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.cc:22: undefined reference to `Poco::Net::HTTPResponse::setStatus(Poco::Net::HTTPResponse::HTTPStatus)'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.cc:24: undefined reference to `Poco::Net::HTTPMessage::getContentLength() const'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.cc:27: undefined reference to `Poco::Net::HTTPRequest::HTTP_POST[abi:cxx11]'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.cc:29: undefined reference to `Poco::Net::HTTPMessage::getContentLength() const'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.cc:32: undefined reference to `tinyxml2::XMLDocument::XMLDocument(bool, tinyxml2::Whitespace)'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.cc:33: undefined reference to `tinyxml2::XMLDocument::Parse(char const*, unsigned long)'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.cc:36: undefined reference to `tinyxml2::XMLElement::GetText() const'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.cc:32: undefined reference to `tinyxml2::XMLDocument::~XMLDocument()'
/usr/bin/ld: /home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.cc:32: undefined reference to `tinyxml2::XMLDocument::~XMLDocument()'
/usr/bin/ld: ../src/libsrc.a(request_handler.cc.o): in function `RequestHandler::~RequestHandler()':
/home/sschiz/CLionProjects/auchan-handler-microservice/src/request_handler/request_handler.h:9: undefined reference to `Poco::Net::HTTPRequestHandler::~HTTPRequestHandler()'
/usr/bin/ld: ../src/libsrc.a(request_handler.cc.o):(.data.rel.ro._ZTI14RequestHandler[_ZTI14RequestHandler]+0x10): undefined reference to `typeinfo for Poco::Net::HTTPRequestHandler'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/CMakeFiles/list_status_path_test.dir/build.make:100: tests/list_status_path_test] Ошибка 1
make[1]: *** [CMakeFiles/Makefile2:190: tests/CMakeFiles/list_status_path_test.dir/all] Ошибка 2
make: *** [Makefile:141: all]

openGL superbible source code compilation error

I've just started to learn openGL programming with the openGL Superbible. Unfortunately I'm not able compile any example. I'm on Ubuntu 18.10 and I prepared the development environment with these packages from the official repository:
mesa-common-dev (with these package you get header files in /usr/include/GL/)
libglfw3-dev (header files in /usr/include/GLFW/)
The book uses a small framework with an entry point in the sb7.h header (in the book source code), sb7.h then points to glfw3 and gl3w (the latter given with the book's source code, so you don't need to download it).
This is the first example from the book:
#ifndef _LINUX
#define _LINUX
#endif
// Include the "sb7.h" header file
#include "sb7.h"
// Derive my_application from sb7::application
class my_application : public sb7::application
{
public:
// Our rendering function
void render(double currentTime)
{
// Simply clear the window with red
static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, red);
}
};
// Our one and only instance of DECLARE_MAIN
DECLARE_MAIN(my_application);
If I try to compile it (the file is called 'main.cpp') with g++ main.cpp -lglfw I get this error:
/usr/bin/ld: /tmp/ccDOdloQ.o: in function `sb7::application::run(sb7::application*)':
main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x27e): undefined reference to `gl3wInit'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x29f): undefined reference to `gl3wIsSupported'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2af): undefined reference to `gl3wDebugMessageCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2bd): undefined reference to `sb7::application::debug_callback(unsigned int, unsigned int, unsigned int, unsigned int, int, char const*, void*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2c9): undefined reference to `gl3wEnable'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2de): undefined reference to `sb6IsExtensionSupported(char const*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2ee): undefined reference to `gl3wDebugMessageCallbackARB'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2fc): undefined reference to `sb7::application::debug_callback(unsigned int, unsigned int, unsigned int, unsigned int, int, char const*, void*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x308): undefined reference to `gl3wEnable'
/usr/bin/ld: /tmp/ccDOdloQ.o: in function `sb7::application::glfw_onResize(GLFWwindow*, int, int)':
main.cpp:(.text._ZN3sb711application13glfw_onResizeEP10GLFWwindowii[_ZN3sb711application13glfw_onResizeEP10GLFWwindowii]+0x15): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application13glfw_onResizeEP10GLFWwindowii[_ZN3sb711application13glfw_onResizeEP10GLFWwindowii]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: /tmp/ccDOdloQ.o: in function `sb7::application::glfw_onKey(GLFWwindow*, int, int, int, int)':
main.cpp:(.text._ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii[_ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii[_ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii]+0x23): undefined reference to `sb7::application::app'
/usr/bin/ld: /tmp/ccDOdloQ.o: in function `sb7::application::glfw_onMouseButton(GLFWwindow*, int, int, int)':
main.cpp:(.text._ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii[_ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii]+0x18): undefined reference to `sb7::application::app'
/usr/bin/ld: /tmp/ccDOdloQ.o:main.cpp:(.text._ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii[_ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii]+0x1f): more undefined references to `sb7::application::app' follow
/usr/bin/ld: /tmp/ccDOdloQ.o: in function `my_application::render(double)':
main.cpp:(.text._ZN14my_application6renderEd[_ZN14my_application6renderEd]+0x14): undefined reference to `gl3wClearBufferfv'
collect2: error: ld returned 1 exit status
Reading the messages I thought that something was wrong with the gl3w library, so I downloaded it from the github repository and I put it and glcorearb.h in /usr/include/GL/, pointing the #include in sb7.h to that folder. Eventually I compiled gl3w.c and linked it to main.cpp with g++ as written here:
g++ -c gl3w.c
g++ -c main.cpp
g++ gl3w.o main.o
but when I execute 3) I get other errors:
/usr/bin/ld: gl3w.o: in function `open_libgl()':
gl3w.c:(.text+0x16): undefined reference to `dlopen'
/usr/bin/ld: gl3w.c:(.text+0x4d): undefined reference to `dlsym'
/usr/bin/ld: gl3w.o: in function `close_libgl()':
gl3w.c:(.text+0x6f): undefined reference to `dlclose'
/usr/bin/ld: gl3w.o: in function `get_proc(char const*)':
gl3w.c:(.text+0xc5): undefined reference to `dlsym'
/usr/bin/ld: main.o: in function `sb7::application::run(sb7::application*)':
main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x21): undefined reference to `glfwInit'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x7c): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x92): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0xb3): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0xd4): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0xe3): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.o:main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0xf2): more undefined references to `glfwWindowHint' follow
/usr/bin/ld: main.o: in function `sb7::application::run(sb7::application*)':
main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x13f): undefined reference to `glfwGetPrimaryMonitor'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x172): undefined reference to `glfwCreateWindow'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x1c8): undefined reference to `glfwMakeContextCurrent'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x1e2): undefined reference to `glfwSetWindowSizeCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x1fc): undefined reference to `glfwSetKeyCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x216): undefined reference to `glfwSetMouseButtonCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x230): undefined reference to `glfwSetCursorPosCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x24a): undefined reference to `glfwSetScrollCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x279): undefined reference to `glfwSetInputMode'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2af): undefined reference to `gl3wDebugMessageCallback'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2bd): undefined reference to `sb7::application::debug_callback(unsigned int, unsigned int, unsigned int, unsigned int, int, char const*, void*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2c9): undefined reference to `gl3wEnable'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2de): undefined reference to `sb6IsExtensionSupported(char const*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2ee): undefined reference to `gl3wDebugMessageCallbackARB'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x2fc): undefined reference to `sb7::application::debug_callback(unsigned int, unsigned int, unsigned int, unsigned int, int, char const*, void*)'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x308): undefined reference to `gl3wEnable'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x339): undefined reference to `glfwGetTime'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x355): undefined reference to `glfwSwapBuffers'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x35a): undefined reference to `glfwPollEvents'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x372): undefined reference to `glfwGetKey'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x39b): undefined reference to `glfwWindowShouldClose'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x3e7): undefined reference to `glfwDestroyWindow'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application3runEPS0_[_ZN3sb711application3runEPS0_]+0x3ec): undefined reference to `glfwTerminate'
/usr/bin/ld: main.o: in function `sb7::application::glfw_onResize(GLFWwindow*, int, int)':
main.cpp:(.text._ZN3sb711application13glfw_onResizeEP10GLFWwindowii[_ZN3sb711application13glfw_onResizeEP10GLFWwindowii]+0x15): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application13glfw_onResizeEP10GLFWwindowii[_ZN3sb711application13glfw_onResizeEP10GLFWwindowii]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: main.o: in function `sb7::application::glfw_onKey(GLFWwindow*, int, int, int, int)':
main.cpp:(.text._ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii[_ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii]+0x1c): undefined reference to `sb7::application::app'
/usr/bin/ld: main.cpp:(.text._ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii[_ZN3sb711application10glfw_onKeyEP10GLFWwindowiiii]+0x23): undefined reference to `sb7::application::app'
/usr/bin/ld: main.o: in function `sb7::application::glfw_onMouseButton(GLFWwindow*, int, int, int)':
main.cpp:(.text._ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii[_ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii]+0x18): undefined reference to `sb7::application::app'
/usr/bin/ld: main.o:main.cpp:(.text._ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii[_ZN3sb711application18glfw_onMouseButtonEP10GLFWwindowiii]+0x1f): more undefined references to `sb7::application::app' follow
/usr/bin/ld: main.o: in function `my_application::render(double)':
main.cpp:(.text._ZN14my_application6renderEd[_ZN14my_application6renderEd]+0x14): undefined reference to `gl3wClearBufferfv'
collect2: error: ld returned 1 exit status
At this point I tried with the single file version of gl3w.h which already includes gl3w.c. I put the two headers in /usr/include/GL/ and then I pointed sb7.h to that version of the library, but other errors appeared with g++ main.cpp -lglfw:
In file included from main.cpp:6:
sb7.h: In member function ‘virtual void sb7::application::run(sb7::application*)’:
sb7.h:137:9: error: ‘gl3wInit’ was not declared in this scope
gl3wInit();
^~~~~~~~
sb7.h:137:9: note: suggested alternative: ‘glfwInit’
gl3wInit();
^~~~~~~~
glfwInit
sb7.h:147:17: error: ‘gl3wIsSupported’ was not declared in this scope
if (gl3wIsSupported(4, 3))
^~~~~~~~~~~~~~~
sb7.h:147:17: note: suggested alternative: ‘gl3w_is_supported’
if (gl3wIsSupported(4, 3))
^~~~~~~~~~~~~~~
gl3w_is_supported
I also added #define GL3W_IMPLEMENTATION before #include "GL/gl3w.h" as suggested in the documentation of the single file version of gl3w but with no luck.
I get the same errors with the other book's source codes.
Hope that someone can help me.
Thank you.