Cmake not building lib correctly [duplicate] - c++

This question already has answers here:
Why can templates only be implemented in the header file?
(17 answers)
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 days ago.
I've been trying to make a c++ static library using cmake on linux, but I keep getting undefined reference errors
cmake_minimum_required(VERSION 3.0.0)
project(eecsge VERSION 0.1.0)
include(CTest)
enable_testing()
include_directories(.)
set(SRCS
EECSGE/core/src/ComponentManager.cpp
EECSGE/core/src/Coordinator.cpp
EECSGE/core/src/EntityManager.cpp
EECSGE/core/src/SystemManager.cpp
)
set(SYSTEMS
EECSGE/systems/src/animation.cpp
EECSGE/systems/src/background.cpp
EECSGE/systems/src/collision.cpp
EECSGE/systems/src/death.cpp
EECSGE/systems/src/drawable.cpp
EECSGE/systems/src/movement.cpp
EECSGE/systems/src/player.cpp
EECSGE/systems/src/sound.cpp
)
include(FetchContent)
FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.5.x)
FetchContent_MakeAvailable(SFML)
FetchContent_Declare(GTEST
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG v1.13.x)
FetchContent_MakeAvailable(GTEST)
add_library(eecsge STATIC ${SRCS} ${SYSTEMS})
target_link_libraries(eecsge sfml-audio sfml-graphics sfml-system sfml-window gtest gtest_main)
target_include_directories(eecsge PUBLIC
$<BUILD_INTERFACE:${${CMAKE_CURRENT_SOURCE_DIR}}>
PRIVATE ${${CMAKE_CURRENT_SOURCE_DIR}}/EECSGE/core/include
${${CMAKE_CURRENT_SOURCE_DIR}}/EECSGE/systems/include
${${CMAKE_CURRENT_SOURCE_DIR}}/EECSGE/components
)
Here is the directory organization
EECSGE
├── components
│ ├── collision.hpp
│ ├── Components.hpp
│ ├── drawable.hpp
│ ├── health.hpp
│ ├── input.hpp
│ ├── movement.hpp
│ ├── sound.hpp
│ └── transform.hpp
├── core
│ ├── Core.hpp
│ ├── include
│ │ ├── ComponentManager.hpp
│ │ ├── Coordinator.hpp
│ │ ├── EntityManager.hpp
│ │ ├── IComponentArray.hpp
│ │ ├── System.hpp
│ │ ├── SystemManager.hpp
│ │ └── Types.hpp
│ └── src
│ ├── ComponentManager.cpp
│ ├── Coordinator.cpp
│ ├── EntityManager.cpp
│ └── SystemManager.cpp
├── EECSGE.hpp
└── systems
├── include
│ ├── animation.hpp
│ ├── background.hpp
│ ├── collision.hpp
│ ├── death.hpp
│ ├── drawable.hpp
│ ├── movement.hpp
│ ├── player.hpp
│ └── sound.hpp
├── src
│ ├── animation.cpp
│ ├── background.cpp
│ ├── collision.cpp
│ ├── death.cpp
│ ├── drawable.cpp
│ ├── movement.cpp
│ ├── player.cpp
│ └── sound.cpp
└── Systems.hpp
Yes it's not pretty, I plan on refactoring when i'm done, but I want to be able to test what I have already.
Here is some of the errors I get when trying to use this library with another program
/usr/bin/ld: CMakeFiles/Demo.dir/demo/demo.cpp.o: in function `init_player()':
demo.cpp:(.text+0x377): undefined reference to `void Coordinator::AddComponent<Transform>(unsigned int, Transform)'
/usr/bin/ld: demo.cpp:(.text+0x3e8): undefined reference to `void Coordinator::AddComponent<Movement>(unsigned int, Movement)'
/usr/bin/ld: demo.cpp:(.text+0x471): undefined reference to `void Coordinator::AddComponent<Drawable>(unsigned int, Drawable)'
/usr/bin/ld: demo.cpp:(.text+0x4f6): undefined reference to `void Coordinator::AddComponent<InputKeys>(unsigned int, InputKeys)'
/usr/bin/ld: demo.cpp:(.text+0x516): undefined reference to `void Coordinator::AddComponent<Collision>(unsigned int, Collision)'
/usr/bin/ld: demo.cpp:(.text+0x537): undefined reference to `void Coordinator::AddComponent<Health>(unsigned int, Health)'
/usr/bin/ld: CMakeFiles/Demo.dir/demo/demo.cpp.o: in function `init_enemy()':
demo.cpp:(.text+0x91e): undefined reference to `void Coordinator::AddComponent<Transform>(unsigned int, Transform)'
/usr/bin/ld: demo.cpp:(.text+0x98f): undefined reference to `void Coordinator::AddComponent<Movement>(unsigned int, Movement)'
/usr/bin/ld: demo.cpp:(.text+0xa1b): undefined reference to `void Coordinator::AddComponent<Drawable>(unsigned int, Drawable)'
/usr/bin/ld: demo.cpp:(.text+0xa46): undefined reference to `void Coordinator::AddComponent<Collision>(unsigned int, Collision)'
/usr/bin/ld: demo.cpp:(.text+0xa67): undefined reference to `void Coordinator::AddComponent<Health>(unsigned int, Health)'
/usr/bin/ld: CMakeFiles/Demo.dir/demo/demo.cpp.o: in function `init_background(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, sf::Vector2<float>)':
demo.cpp:(.text+0xee3): undefined reference to `void Coordinator::AddComponent<Transform>(unsigned int, Transform)'
/usr/bin/ld: demo.cpp:(.text+0xf45): undefined reference to `void Coordinator::AddComponent<Movement>(unsigned int, Movement)'
/usr/bin/ld: demo.cpp:(.text+0xfd1): undefined reference to `void Coordinator::AddComponent<Drawable>(unsigned int, Drawable)'
/usr/bin/ld: CMakeFiles/Demo.dir/demo/demo.cpp.o: in function `main':
demo.cpp:(.text+0x1743): undefined reference to `void Coordinator::RegisterComponent<Movement>()'
/usr/bin/ld: demo.cpp:(.text+0x1752): undefined reference to `void Coordinator::RegisterComponent<Transform>()'
/usr/bin/ld: demo.cpp:(.text+0x1761): undefined reference to `void Coordinator::RegisterComponent<InputKeys>()'
/usr/bin/ld: demo.cpp:(.text+0x1770): undefined reference to `void Coordinator::RegisterComponent<Drawable>()'
/usr/bin/ld: demo.cpp:(.text+0x177f): undefined reference to `void Coordinator::RegisterComponent<Collision>()'
/usr/bin/ld: demo.cpp:(.text+0x178e): undefined reference to `void Coordinator::RegisterComponent<Health>()'
/usr/bin/ld: demo.cpp:(.text+0x17a7): undefined reference to `std::shared_ptr<PlayerSystem> Coordinator::RegisterSystem<PlayerSystem>()'
/usr/bin/ld: demo.cpp:(.text+0x17c0): undefined reference to `std::shared_ptr<DrawSystem> Coordinator::RegisterSystem<DrawSystem>()'
/usr/bin/ld: demo.cpp:(.text+0x17d9): undefined reference to `std::shared_ptr<CollisionSystem> Coordinator::RegisterSystem<CollisionSystem>()'
/usr/bin/ld: demo.cpp:(.text+0x17f2): undefined reference to `std::shared_ptr<MovementSystem> Coordinator::RegisterSystem<MovementSystem>()'
/usr/bin/ld: demo.cpp:(.text+0x180b): undefined reference to `std::shared_ptr<DeathSystem> Coordinator::RegisterSystem<DeathSystem>()'
/usr/bin/ld: demo.cpp:(.text+0x1824): undefined reference to `std::shared_ptr<AnimationSystem> Coordinator::RegisterSystem<AnimationSystem>()'
/usr/bin/ld: demo.cpp:(.text+0x183d): undefined reference to `std::shared_ptr<BackgroundSystem> Coordinator::RegisterSystem<BackgroundSystem>()'
/usr/bin/ld: demo.cpp:(.text+0x1857): undefined reference to `unsigned char Coordinator::GetComponentType<Movement>()'
/usr/bin/ld: demo.cpp:(.text+0x1880): undefined reference to `unsigned char Coordinator::GetComponentType<Transform>()'
/usr/bin/ld: demo.cpp:(.text+0x18b3): undefined reference to `void Coordinator::SetSystemSignature<MovementSystem>(std::bitset<32ul>)'
/usr/bin/ld: demo.cpp:(.text+0x18cd): undefined reference to `unsigned char Coordinator::GetComponentType<Transform>()'
/usr/bin/ld: demo.cpp:(.text+0x18f6): undefined reference to `unsigned char Coordinator::GetComponentType<Drawable>()'
/usr/bin/ld: demo.cpp:(.text+0x1929): undefined reference to `void Coordinator::SetSystemSignature<DrawSystem>(std::bitset<32ul>)'
/usr/bin/ld: demo.cpp:(.text+0x1943): undefined reference to `unsigned char Coordinator::GetComponentType<InputKeys>()'
/usr/bin/ld: demo.cpp:(.text+0x1976): undefined reference to `void Coordinator::SetSystemSignature<PlayerSystem>(std::bitset<32ul>)'
/usr/bin/ld: demo.cpp:(.text+0x198f): undefined reference to `void Coordinator::SetSystemSignature<AnimationSystem>(std::bitset<32ul>)'
/usr/bin/ld: demo.cpp:(.text+0x19a9): undefined reference to `unsigned char Coordinator::GetComponentType<Drawable>()'
/usr/bin/ld: demo.cpp:(.text+0x19d2): undefined reference to `unsigned char Coordinator::GetComponentType<Collision>()'
/usr/bin/ld: demo.cpp:(.text+0x19fb): undefined reference to `unsigned char Coordinator::GetComponentType<Health>()'
/usr/bin/ld: demo.cpp:(.text+0x1a2e): undefined reference to `void Coordinator::SetSystemSignature<CollisionSystem>(std::bitset<32ul>)'
/usr/bin/ld: demo.cpp:(.text+0x1a48): undefined reference to `unsigned char Coordinator::GetComponentType<Health>()'
/usr/bin/ld: demo.cpp:(.text+0x1a7b): undefined reference to `void Coordinator::SetSystemSignature<DeathSystem>(std::bitset<32ul>)'
/usr/bin/ld: demo.cpp:(.text+0x1a95): undefined reference to `unsigned char Coordinator::GetComponentType<Drawable>()'
/usr/bin/ld: demo.cpp:(.text+0x1abe): undefined reference to `unsigned char Coordinator::GetComponentType<Transform>()'
/usr/bin/ld: demo.cpp:(.text+0x1af1): undefined reference to `void Coordinator::SetSystemSignature<BackgroundSystem>(std::bitset<32ul>)'
/usr/bin/ld: _deps/eecsge-build/libeecsge.a(animation.cpp.o): in function `AnimationSystem::Update()':
animation.cpp:(.text+0x6f): undefined reference to `Transform& Coordinator::GetComponent<Transform>(unsigned int)'
/usr/bin/ld: animation.cpp:(.text+0x8a): undefined reference to `Movement& Coordinator::GetComponent<Movement>(unsigned int)'
/usr/bin/ld: animation.cpp:(.text+0xa5): undefined reference to `Drawable& Coordinator::GetComponent<Drawable>(unsigned int)'
/usr/bin/ld: _deps/eecsge-build/libeecsge.a(background.cpp.o): in function `BackgroundSystem::Update()':
background.cpp:(.text+0x6f): undefined reference to `Transform& Coordinator::GetComponent<Transform>(unsigned int)'
/usr/bin/ld: background.cpp:(.text+0x8a): undefined reference to `Drawable& Coordinator::GetComponent<Drawable>(unsigned int)'
/usr/bin/ld: _deps/eecsge-build/libeecsge.a(collision.cpp.o): in function `CollisionSystem::Update(float)':
collision.cpp:(.text+0x108): undefined reference to `Collision& Coordinator::GetComponent<Collision>(unsigned int)'
/usr/bin/ld: collision.cpp:(.text+0x12a): undefined reference to `Collision& Coordinator::GetComponent<Collision>(unsigned int)'
/usr/bin/ld: collision.cpp:(.text+0x160): undefined reference to `Drawable& Coordinator::GetComponent<Drawable>(unsigned int)'
/usr/bin/ld: collision.cpp:(.text+0x18f): undefined reference to `Drawable& Coordinator::GetComponent<Drawable>(unsigned int)'
/usr/bin/ld: collision.cpp:(.text+0x235): undefined reference to `Health& Coordinator::GetComponent<Health>(unsigned int)'
/usr/bin/ld: collision.cpp:(.text+0x25b): undefined reference to `Health& Coordinator::GetComponent<Health>(unsigned int)'
/usr/bin/ld: _deps/eecsge-build/libeecsge.a(death.cpp.o): in function `DeathSystem::Update()':
death.cpp:(.text+0x6c): undefined reference to `Health& Coordinator::GetComponent<Health>(unsigned int)'
/usr/bin/ld: _deps/eecsge-build/libeecsge.a(drawable.cpp.o): in function `DrawSystem::DrawEntities(sf::RenderWindow*)':
drawable.cpp:(.text+0x74): undefined reference to `Transform& Coordinator::GetComponent<Transform>(unsigned int)'
/usr/bin/ld: drawable.cpp:(.text+0x8f): undefined reference to `Movement& Coordinator::GetComponent<Movement>(unsigned int)'
/usr/bin/ld: drawable.cpp:(.text+0xaa): undefined reference to `Drawable& Coordinator::GetComponent<Drawable>(unsigned int)'
/usr/bin/ld: _deps/eecsge-build/libeecsge.a(movement.cpp.o): in function `MovementSystem::Update()':
movement.cpp:(.text+0x6d): undefined reference to `Movement& Coordinator::GetComponent<Movement>(unsigned int)'
/usr/bin/ld: movement.cpp:(.text+0x85): undefined reference to `Transform& Coordinator::GetComponent<Transform>(unsigned int)'
/usr/bin/ld: _deps/eecsge-build/libeecsge.a(player.cpp.o): in function `PlayerSystem::Shoot(Transform&, Movement&)':
player.cpp:(.text+0x1eb): undefined reference to `void Coordinator::AddComponent<Movement>(unsigned int, Movement)'
/usr/bin/ld: player.cpp:(.text+0x328): undefined reference to `void Coordinator::AddComponent<Drawable>(unsigned int, Drawable)'
/usr/bin/ld: player.cpp:(.text+0x46f): undefined reference to `void Coordinator::AddComponent<Transform>(unsigned int, Transform)'
/usr/bin/ld: player.cpp:(.text+0x48f): undefined reference to `void Coordinator::AddComponent<Collision>(unsigned int, Collision)'
/usr/bin/ld: player.cpp:(.text+0x4b0): undefined reference to `void Coordinator::AddComponent<Health>(unsigned int, Health)'
/usr/bin/ld: _deps/eecsge-build/libeecsge.a(player.cpp.o): in function `PlayerSystem::Update(sf::Event)':
player.cpp:(.text+0x5f6): undefined reference to `InputKeys& Coordinator::GetComponent<InputKeys>(unsigned int)'
/usr/bin/ld: player.cpp:(.text+0x611): undefined reference to `Movement& Coordinator::GetComponent<Movement>(unsigned int)'
/usr/bin/ld: player.cpp:(.text+0x62c): undefined reference to `Transform& Coordinator::GetComponent<Transform>(unsigned int)'
collect2: error: ld returned 1 exit status
Any help would be appreciated

Then I believe it's a duplicate of this: Why can templates only be implemented in the header file? –
drescherjm
19 mins ago
Because I had implemented the Core files in .cpp, it caused problems. Re-implementing them in the .hpp files worked.

Related

Inclusion pcapplusplus in project via CMake

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 ()

Can't find libpq library for C++ program using libpqxx

I'm not a C++ developer and I don't know very much about compiling projects or makefiles, but I'm trying to compile and run someone else's C++ program. I'm using Ubuntu. Here's the makefile I have so far, based on this:
TARGET_EXEC ?= a.out
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP
CC = gcc
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CC) $(OBJS) -o $# $(LDFLAGS) /usr/lib/x86_64-linux-gnu/libstdc++.so.6 -I/usr/local/include/boost -I/usr/local/include/pqxx -I/usr/lib/postgresql/13/lib -I/usr/include/postgresql -I/usr/include/postgresql/libpq -I/usr/include/postgresql/internal -I/usr/include/postgresql/internal/libpq -L/usr/local/lib -lboost_filesystem -lpqxx
# assembly
$(BUILD_DIR)/%.s.o: %.s
$(MKDIR_P) $(dir $#)
$(AS) $(ASFLAGS) -c $< -o $#
# c source
# $(BUILD_DIR)/%.c.o: %.c
# $(MKDIR_P) $(dir $#)
# $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $# -lstdc++
# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
$(MKDIR_P) $(dir $#)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $#
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR)
-include $(DEPS)
MKDIR_P ?= mkdir -p
The part commented # c++ source seems to complete without issue, but then I run into problems with the long line above $(CC) $(OBJS) -o $# $(LDFLAGS) ...:
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::backendpid() const':
/usr/local/include/pqxx/src/connection_base.cxx:121: undefined reference to `PQbackendPID'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::sock() const':
/usr/local/include/pqxx/src/connection_base.cxx:129: undefined reference to `PQsocket'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::protocol_version() const':
/usr/local/include/pqxx/src/connection_base.cxx:214: undefined reference to `PQprotocolVersion'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::consume_input()':
/usr/local/include/pqxx/src/connection_base.cxx:501: undefined reference to `PQconsumeInput'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::is_busy() const':
/usr/local/include/pqxx/src/connection_base.cxx:507: undefined reference to `PQisBusy'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::set_verbosity(pqxx::connection_base::error_verbosity)':
/usr/local/include/pqxx/src/connection_base.cxx:551: undefined reference to `PQsetErrorVerbosity'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::err_msg() const':
/usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::set_notice_processor()':
/usr/local/include/pqxx/src/connection_base.cxx:672: undefined reference to `PQsetNoticeProcessor'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::clear_notice_processor()':
/usr/local/include/pqxx/src/connection_base.cxx:666: undefined reference to `PQsetNoticeProcessor'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::internal_set_trace()':
/usr/local/include/pqxx/src/connection_base.cxx:957: undefined reference to `PQtrace'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:958: undefined reference to `PQuntrace'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::unesc_raw[abi:cxx11](char const*)':
/usr/local/include/pqxx/src/connection_base.cxx:1152: undefined reference to `PQunescapeBytea'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::internal::wait_read(pg_conn const*)':
/usr/local/include/pqxx/src/connection_base.cxx:129: undefined reference to `PQsocket'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::internal::wait_read(pg_conn const*, long, long)':
/usr/local/include/pqxx/src/connection_base.cxx:129: undefined reference to `PQsocket'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::internal::wait_write(pg_conn const*)':
/usr/local/include/pqxx/src/connection_base.cxx:129: undefined reference to `PQsocket'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::cancel_query()':
/usr/local/include/pqxx/src/connection_base.cxx:526: undefined reference to `PQgetCancel'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:535: undefined reference to `PQcancel'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:530: undefined reference to `PQfreeCancel'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::read_capabilities()':
/usr/local/include/pqxx/src/connection_base.cxx:1360: undefined reference to `PQserverVersion'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::protocol_version() const':
/usr/local/include/pqxx/src/connection_base.cxx:214: undefined reference to `PQprotocolVersion'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::set_client_encoding(char const*)':
/usr/local/include/pqxx/src/connection_base.cxx:1395: undefined reference to `PQsetClientEncoding'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::encoding_id() const':
/usr/local/include/pqxx/src/connection_base.cxx:1419: undefined reference to `PQclientEncoding'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::encrypt_password(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/local/include/pqxx/src/connection_base.cxx:94: undefined reference to `PQencryptPassword'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::quote_name(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:1180: undefined reference to `PQescapeIdentifier'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::clear_notice_processor()':
/usr/local/include/pqxx/src/connection_base.cxx:666: undefined reference to `PQsetNoticeProcessor'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::set_up_state()':
/usr/local/include/pqxx/src/connection_base.cxx:321: undefined reference to `PQsendQuery'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:324: undefined reference to `PQgetResult'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::err_msg() const':
/usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::register_prepared(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:800: undefined reference to `PQprepare'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::start_exec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:1079: undefined reference to `PQsendQuery'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::esc_raw[abi:cxx11](unsigned char const*, unsigned long)':
/usr/local/include/pqxx/src/connection_base.cxx:1139: undefined reference to `PQescapeByteaConn'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::reset()':
/usr/local/include/pqxx/src/connection_base.cxx:889: undefined reference to `PQreset'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::esc[abi:cxx11](char const*, unsigned long)':
/usr/local/include/pqxx/src/connection_base.cxx:1108: undefined reference to `PQescapeStringConn'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::end_copy_write()':
/usr/local/include/pqxx/src/connection_base.cxx:1054: undefined reference to `PQputCopyEnd'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:1070: undefined reference to `PQgetResult'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::read_copy_line(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
/usr/local/include/pqxx/src/connection_base.cxx:999: undefined reference to `PQgetCopyData'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:1007: undefined reference to `PQgetResult'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:1009: undefined reference to `PQgetResult'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::consume_input()':
/usr/local/include/pqxx/src/connection_base.cxx:501: undefined reference to `PQconsumeInput'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::get_notifs()':
/usr/local/include/pqxx/src/connection_base.cxx:565: undefined reference to `PQnotifies'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:565: undefined reference to `PQnotifies'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::parameterized_exec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const* const*, int const*, int const*, int)':
/usr/local/include/pqxx/src/connection_base.cxx:1448: undefined reference to `PQexecParams'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::exec_params(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pqxx::internal::params const&)':
/usr/local/include/pqxx/src/connection_base.cxx:1460: undefined reference to `PQexecParams'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::prepared_exec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const* const*, int const*, int const*, int)':
/usr/local/include/pqxx/src/connection_base.cxx:836: undefined reference to `PQexecPrepared'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::exec_prepared(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pqxx::internal::params const&)':
/usr/local/include/pqxx/src/connection_base.cxx:852: undefined reference to `PQexecPrepared'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::exec(char const*, int)':
/usr/local/include/pqxx/src/connection_base.cxx:715: undefined reference to `PQexec'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::exec(char const*, int)':
/usr/local/include/pqxx/src/connection_base.cxx:721: undefined reference to `PQexec'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::write_copy_line(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:1041: undefined reference to `PQputCopyData'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::err_msg() const':
/usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::write_copy_line(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:1046: undefined reference to `PQendcopy'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::add_receiver(pqxx::notification_receiver*)':
/usr/local/include/pqxx/src/connection_base.cxx:452: undefined reference to `PQexec'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::clear_notice_processor()':
/usr/local/include/pqxx/src/connection_base.cxx:666: undefined reference to `PQsetNoticeProcessor'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::set_notice_processor()':
/usr/local/include/pqxx/src/connection_base.cxx:672: undefined reference to `PQsetNoticeProcessor'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::get_result()':
/usr/local/include/pqxx/src/connection_base.cxx:1086: undefined reference to `PQgetResult'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::dbname()':
/usr/local/include/pqxx/src/connection_base.cxx:627: undefined reference to `PQdb'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:627: undefined reference to `PQdb'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::username()':
/usr/local/include/pqxx/src/connection_base.cxx:636: undefined reference to `PQuser'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:636: undefined reference to `PQuser'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::hostname()':
/usr/local/include/pqxx/src/connection_base.cxx:645: undefined reference to `PQhost'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:645: undefined reference to `PQhost'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::port()':
/usr/local/include/pqxx/src/connection_base.cxx:654: undefined reference to `PQport'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:654: undefined reference to `PQport'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::err_msg() const':
/usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::cancel_query() [clone .cold]':
/usr/local/include/pqxx/src/connection_base.cxx:530: undefined reference to `PQfreeCancel'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::err_msg() const':
/usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connectionpolicy::do_disconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:72: undefined reference to `PQfinish'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connect_async::do_startconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:116: undefined reference to `PQconnectStart'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:118: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:121: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connect_async::do_completeconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:164: undefined reference to `PQconnectPoll'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:164: undefined reference to `PQconnectPoll'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connectionpolicy::normalconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:38: undefined reference to `PQconnectdb'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:40: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:42: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:43: undefined reference to `PQfinish'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connect_direct::do_startconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:88: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:90: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connect_async::do_completeconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:146: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(encodings.o): in function `pqxx::internal::name_encoding(int)':
/usr/local/include/pqxx/src/encodings.cxx:633: undefined reference to `pg_encoding_to_char'
/usr/bin/ld: /usr/local/include/pqxx/src/encodings.cxx:633: undefined reference to `pg_encoding_to_char'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::size() const':
/usr/local/include/pqxx/src/result.cxx:96: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/include/pqxx/src/result.cxx:96: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::empty() const':
/usr/local/include/pqxx/src/result.cxx:102: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::size() const':
/usr/local/include/pqxx/src/result.cxx:96: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/include/pqxx/src/result.cxx:96: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o):/usr/local/include/pqxx/src/result.cxx:96: more undefined references to `PQntuples' follow
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::cmd_status() const':
/usr/local/include/pqxx/src/result.cxx:273: undefined reference to `PQcmdStatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::affected_rows() const':
/usr/local/include/pqxx/src/result.cxx:294: undefined reference to `PQcmdTuples'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::get_is_null(unsigned long, unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:312: undefined reference to `PQgetisnull'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::get_length(unsigned long, unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:319: undefined reference to `PQgetlength'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::errorposition() const':
/usr/local/include/pqxx/src/result.cxx:375: undefined reference to `PQresultErrorField'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::ThrowSQLError(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&) const':
/usr/local/include/pqxx/src/result.cxx:153: undefined reference to `PQresultErrorField'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::columns() const':
/usr/local/include/pqxx/src/result.cxx:402: undefined reference to `PQnfields'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::column_type(unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:325: undefined reference to `PQftype'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::column_table(unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:336: undefined reference to `PQftable'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::columns() const':
/usr/local/include/pqxx/src/result.cxx:402: undefined reference to `PQnfields'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::table_column(unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:352: undefined reference to `PQftablecol'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::columns() const':
/usr/local/include/pqxx/src/result.cxx:402: undefined reference to `PQnfields'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::size() const':
/usr/local/include/pqxx/src/result.cxx:96: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::StatusError[abi:cxx11]() const':
/usr/local/include/pqxx/src/result.cxx:245: undefined reference to `PQresultStatus'
/usr/bin/ld: /usr/local/include/pqxx/src/result.cxx:259: undefined reference to `PQresultErrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::inserted_oid() const':
/usr/local/include/pqxx/src/result.cxx:288: undefined reference to `PQoidValue'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::column_name(unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:386: undefined reference to `PQfname'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::internal::clear_result(pg_result const*)':
/usr/local/include/pqxx/src/result.cxx:32: undefined reference to `PQclear'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::GetValue(unsigned long, unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:304: undefined reference to `PQgetvalue'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::columns() const':
/usr/local/include/pqxx/src/result.cxx:402: undefined reference to `PQnfields'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::internal::clear_result(pg_result const*)':
/usr/local/include/pqxx/src/result.cxx:32: undefined reference to `PQclear'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::StatusError[abi:cxx11]() const':
/usr/local/include/pqxx/src/result.cxx:265: undefined reference to `PQresultStatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::columns() const':
/usr/local/include/pqxx/src/result.cxx:402: undefined reference to `PQnfields'
/usr/bin/ld: /usr/local/lib/libpqxx.a(row.o): in function `pqxx::result::column_number(char const*) const':
/usr/local/include/pqxx/src/row.cxx:209: undefined reference to `PQfnumber'
/usr/bin/ld: /usr/local/lib/libpqxx.a(util.o): in function `pqxx::describe_thread_safety()':
/usr/local/include/pqxx/src/util.cxx:35: undefined reference to `PQisthreadsafe'
/usr/bin/ld: /usr/local/lib/libpqxx.a(util.o): in function `pqxx::internal::freepqmem(void const*)':
/usr/local/include/pqxx/src/util.cxx:108: undefined reference to `PQfreemem'
collect2: error: ld returned 1 exit status
make: *** [Makefile:17: build/a.out] Error 1
From what I can tell, some necessary parts of the libpq library can't be found. I don't know if I'm supposed to be using -I or -L, /usr/lib/postgresql/13/ or /usr/include/postgresql or something else, so I've just been trying different combinations, but to no avail. In addition to installing PostgreSQL, I installed libpq-dev with apt-get, but I don't know what that actually did.

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.

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.

How to fix undefined reference to v8 error?

I'm trying to configure and build a sample of node.js addon. The sample was taken from node.js documentation and the source code can be found here
https://github.com/nodejs/node-addon-examples/tree/master/8_passing_wrapped/node_0.12
When I try to compile this in CLion (on Ubuntu 14.04) or when I use node-gyp to build it I've got some errors:
/home/smorzhov/Documents/clion-2016.1/bin/cmake/bin/cmake --build /home/smorzhov/.CLion2016.1/system/cmake/generated/test4-94ee4803/94ee4803/Debug --target all -- -j 4
[ 25%] Linking CXX executable test4
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::Init(v8::Isolate*)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:26: undefined reference to `v8::FunctionTemplate::New(v8::Isolate*, void (*)(v8::FunctionCallbackInfo<v8::Value> const&), v8::Local<v8::Value>, v8::Local<v8::Signature>, int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:27: undefined reference to `v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::String::NewStringType, int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:27: undefined reference to `v8::FunctionTemplate::SetClassName(v8::Local<v8::String>)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:28: undefined reference to `v8::FunctionTemplate::InstanceTemplate()'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:28: undefined reference to `v8::ObjectTemplate::SetInternalFieldCount(int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:30: undefined reference to `v8::FunctionTemplate::GetFunction()'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:30: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Function>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Function>::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7176: undefined reference to `v8::V8::GlobalizeReference(v8::internal::Isolate*, v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `Reset<v8::Function>':
/usr/include/node/v8.h:7235: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::New(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:38: undefined reference to `v8::Value::NumberValue() const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::PersistentBase<v8::Function> const&)':
/usr/include/node/v8.h:7124: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::New(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:47: undefined reference to `v8::Function::NewInstance(int, v8::Local<v8::Value>*) const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::PersistentBase<v8::Function> const&)':
/usr/include/node/v8.h:7124: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::NewInstance(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:57: undefined reference to `v8::Function::NewInstance(int, v8::Local<v8::Value>*) const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `ClearWeak<void>':
/usr/include/node/v8.h:7298: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::Wrap(v8::Local<v8::Object>)':
/usr/include/node/node_object_wrap.h:56: undefined reference to `v8::Object::InternalFieldCount()'
/usr/include/node/node_object_wrap.h:57: undefined reference to `v8::Object::SetAlignedPointerInInternalField(int, void*)'
/usr/include/node/node_object_wrap.h:58: undefined reference to `v8::Isolate::GetCurrent()'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::New(v8::Isolate*, v8::Object*)':
/usr/include/node/v8.h:7176: undefined reference to `v8::V8::GlobalizeReference(v8::internal::Isolate*, v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `SetWeak<v8::Object, node::ObjectWrap>':
/usr/include/node/v8.h:7257: undefined reference to `v8::V8::MakeWeak(v8::internal::Object**, void*, void (*)(v8::WeakCallbackData<v8::Value, void> const&))'
CMakeFiles/test4.dir/myobject.cpp.o: In function `ClearWeak<void>':
/usr/include/node/v8.h:7298: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::WeakCallback(v8::WeakCallbackData<v8::Object, node::ObjectWrap> const&)':
/usr/include/node/node_object_wrap.h:101: undefined reference to `v8::HandleScope::HandleScope(v8::Isolate*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Object>::New(v8::Isolate*, v8::Object*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::WeakCallback(v8::WeakCallbackData<v8::Object, node::ObjectWrap> const&)':
/usr/include/node/node_object_wrap.h:108: undefined reference to `v8::HandleScope::~HandleScope()'
/usr/include/node/node_object_wrap.h:108: undefined reference to `v8::HandleScope::~HandleScope()'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::Add(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:27: undefined reference to `v8::Number::New(v8::Isolate*, double)'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::InitAll(v8::Local<v8::Object>)':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:31: undefined reference to `v8::Object::GetIsolate()'
CMakeFiles/test4.dir/addon.cpp.o: In function `_register_addon':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:37: undefined reference to `node_module_register'
CMakeFiles/test4.dir/addon.cpp.o: In function `v8::Value::ToObject() const':
/usr/include/node/v8.h:7778: undefined reference to `v8::Isolate::GetCurrent()'
/usr/include/node/v8.h:7778: undefined reference to `v8::Isolate::GetCurrentContext()'
/usr/include/node/v8.h:7779: undefined reference to `v8::Value::ToObject(v8::Local<v8::Context>) const'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::MyObject* node::ObjectWrap::Unwrap<demo::MyObject>(v8::Local<v8::Object>)':
/usr/include/node/node_object_wrap.h:29: undefined reference to `v8::Object::InternalFieldCount()'
CMakeFiles/test4.dir/addon.cpp.o: In function `v8::Object::GetAlignedPointerFromInternalField(int)':
/usr/include/node/v8.h:7636: undefined reference to `v8::Object::SlowGetAlignedPointerFromInternalField(int)'
CMakeFiles/test4.dir/addon.cpp.o: In function `void node::NODE_SET_METHOD<v8::Local<v8::Object> >(v8::Local<v8::Object> const&, char const*, void (*)(v8::FunctionCallbackInfo<v8::Value> const&))':
/usr/include/node/node.h:239: undefined reference to `v8::Isolate::GetCurrent()'
/usr/include/node/node.h:240: undefined reference to `v8::HandleScope::HandleScope(v8::Isolate*)'
/usr/include/node/node.h:242: undefined reference to `v8::FunctionTemplate::New(v8::Isolate*, void (*)(v8::FunctionCallbackInfo<v8::Value> const&), v8::Local<v8::Value>, v8::Local<v8::Signature>, int)'
/usr/include/node/node.h:243: undefined reference to `v8::FunctionTemplate::GetFunction()'
/usr/include/node/node.h:244: undefined reference to `v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::String::NewStringType, int)'
/usr/include/node/node.h:245: undefined reference to `v8::Function::SetName(v8::Local<v8::String>)'
/usr/include/node/node.h:246: undefined reference to `v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)'
/usr/include/node/node.h:246: undefined reference to `v8::HandleScope::~HandleScope()'
/usr/include/node/node.h:246: undefined reference to `v8::HandleScope::~HandleScope()'
collect2: error: ld returned 1 exit status
make[2]: *** [test4] Error 1
make[1]: *** [CMakeFiles/test4.dir/all] Error 2
make: *** [all] Error 2
Maybe it is important, the IDE don't understand
#include node.h
and I have to change it to #include node/node.h
It seems, that compiler sees only node and v8 headers and cannot find their sources.
Can somebody help me to fix that? How to make compiler to see node and v8 sources?
PS. My CmakeLists.txt file
cmake_minimum_required(VERSION 3.3)
project(test4)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES addon.cpp main.cpp myobject.cpp myobject.h)
add_executable(test4 ${SOURCE_FILES})
If you follow the README and use node-gyp with the -v flag, you can see that compilation looks like this:
g++ '-DNODE_GYP_MODULE_NAME=addon' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/home/yannick/.node-gyp/5.9.0/include/node -I/home/yannick/.node-gyp/5.9.0/src -I/home/yannick/.node-gyp/5.9.0/deps/uv/include -I/home/yannick/.node-gyp/5.9.0/deps/v8/include -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF ./Release/.deps/Release/obj.target/addon/myobject.o.d.raw -c -o Release/obj.target/addon/myobject.o ../myobject.cc
So it's a tad more complex that just specifying a few sources : there are several include dirs to be used, that seems specific to the node version you are running, and include an external dependency (libuv)
Why don't you use the build methods suggested by the README ?