How to statically link allegro5 (Linux, G++)? - c++

I built the latest stable version of allegro5's source code following these steps
I have the following code (main.cpp):
#include <stdint.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
int main()
{
al_init();
al_install_keyboard();
al_install_mouse();
al_init_primitives_addon();
al_set_new_display_flags(ALLEGRO_RESIZABLE);
ALLEGRO_DISPLAY* display = al_create_display(1280, 720);
al_set_window_title(display, "Allegro5 Window");
ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
al_register_event_source(queue, al_get_display_event_source(display));
al_register_event_source(queue, al_get_keyboard_event_source());
al_register_event_source(queue, al_get_mouse_event_source());
bool running = true;
while (running)
{
ALLEGRO_EVENT ev;
while (al_get_next_event(queue, &ev))
{
if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
running = false;
if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
{
al_acknowledge_resize(display);
}
}
al_clear_to_color(al_map_rgba_f(0.25, 0.25, 0.25, 1));
al_flip_display();
}
al_destroy_event_queue(queue);
al_destroy_display(display);
return 0;
}
... And I am trying to build this source file using the following command:
g++ -g $(pkg-config --libs --static allegro-static-5 allegro_primitives-static-5) main.cpp -o main
Even though pkg-config detects everything, it still doesn't work. The output is:
/usr/bin/ld: /tmp/ccmxycjk.o: in function `main':
pwd/main.cpp:7: undefined reference to `al_install_system'
/usr/bin/ld: pwd/main.cpp:8: undefined reference to `al_install_keyboard'
/usr/bin/ld: pwd/main.cpp:9: undefined reference to `al_install_mouse'
/usr/bin/ld: pwd/main.cpp:10: undefined reference to `al_init_primitives_addon'
/usr/bin/ld: pwd/main.cpp:11: undefined reference to `al_set_new_display_flags'
/usr/bin/ld: pwd/main.cpp:12: undefined reference to `al_create_display'
/usr/bin/ld: pwd/main.cpp:13: undefined reference to `al_set_window_title'
/usr/bin/ld: pwd/main.cpp:14: undefined reference to `al_create_event_queue'
/usr/bin/ld: pwd/main.cpp:15: undefined reference to `al_get_display_event_source'
/usr/bin/ld: pwd/main.cpp:15: undefined reference to `al_register_event_source'
/usr/bin/ld: pwd/main.cpp:16: undefined reference to `al_get_keyboard_event_source'
/usr/bin/ld: pwd/main.cpp:16: undefined reference to `al_register_event_source'
/usr/bin/ld: pwd/main.cpp:17: undefined reference to `al_get_mouse_event_source'
/usr/bin/ld: pwd/main.cpp:17: undefined reference to `al_register_event_source'
/usr/bin/ld: pwd/main.cpp:23: undefined reference to `al_get_next_event'
/usr/bin/ld: pwd/main.cpp:29: undefined reference to `al_acknowledge_resize'
/usr/bin/ld: pwd/main.cpp:33: undefined reference to `al_map_rgba_f'
/usr/bin/ld: pwd/main.cpp:33: undefined reference to `al_clear_to_color'
/usr/bin/ld: pwd/main.cpp:34: undefined reference to `al_flip_display'
/usr/bin/ld: pwd/main.cpp:37: undefined reference to `al_destroy_event_queue'
/usr/bin/ld: pwd/main.cpp:38: undefined reference to `al_destroy_display'
OBS: PWD = project path. Running up-to-date Debian 10
I've tried compiling with '-l:', adding all the libs, etc. Nothing would work. Any ideas?

Before you #include <allegro5/...>, add:
#define ALLEGRO_STATICLINK
You may need to link with additional libraries used by Allegro as well, such as OpenGL32.lib (on Windows), to resolve OpenGL functions.

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

OPC UA sdk linker

I compiled source code and make .o files, but linker still returns mistakes below.
There is undefined reference to constructor UaMutexLocker and others as you can see below. I added path to library -luabasecppd where is this contained, but I don't have any idea, why it doesn't work.
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:244: undefined reference to `UaMutex::UaMutex()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:247: undefined reference to `UaThread::start()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:244: undefined reference to `UaMutex::~UaMutex()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:244: undefined reference to `UaThread::~UaThread()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpoint::~UaReverseEndpoint()':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:252: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:254: undefined reference to `UaMutexLocker::unlock()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:257: undefined reference to `UaThread::wait(unsigned int)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:261: undefined reference to `UaMutexLocker::lock(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:268: undefined reference to `UaMutexLocker::unlock()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:252: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:249: undefined reference to `UaMutex::~UaMutex()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:249: undefined reference to `UaThread::~UaThread()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpoint::registerSession(UaString const&, UaClientSdk::UaReverseEndpointCallback*)':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:280: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:280: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:280: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpoint::registerDiscovery(UaClientSdk::UaReverseEndpointCallback*)':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:297: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:297: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:297: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpoint::unregisterSession(UaString const&, UaClientSdk::UaReverseEndpointCallback*)':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:319: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:319: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:319: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpoint::unregisterDiscovery(UaClientSdk::UaReverseEndpointCallback*)':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:339: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:339: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:339: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpoint::run()':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:349: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:369: undefined reference to `UaMutexLocker::unlock()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:379: undefined reference to `UaThread::msleep(unsigned int)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:381: undefined reference to `UaMutexLocker::lock(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:349: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:349: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpoint::beginConnect()':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:393: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:406: undefined reference to `UaMutexLocker::unlock()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:445: undefined reference to `UaMutexLocker::lock(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:447: undefined reference to `UaMutexLocker::unlock()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:451: undefined reference to `UaMutexLocker::lock(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:393: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:393: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpoint::disconnect()':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:468: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:468: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:468: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpoint::removeChannel(void*)':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:492: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:492: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:492: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpoint::invalidateChannel(void*)':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:505: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:505: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:505: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpointList::UaReverseEndpointList()':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:524: undefined reference to `UaMutex::UaMutex()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpointList::~UaReverseEndpointList()':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:527: undefined reference to `UaMutex::~UaMutex()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpointList::getReverseEndpoint(UaString const&)':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:534: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:534: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:534: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpointList::decrementEndpoint(UaClientSdk::UaReverseEndpoint*)':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:552: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:560: undefined reference to `UaMutexLocker::unlock()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:552: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:552: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o): in function `UaClientSdk::UaReverseEndpointList::endpointCount()':
/home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:567: undefined reference to `UaMutexLocker::UaMutexLocker(UaMutex*)'
/usr/bin/ld: /home/buildbot/work/uasdkcpp/src/uaclient/uaclientcpp/uareverseconnect.cpp:567: undefined reference to `UaMutexLocker::~UaMutexLocker()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o):(.data.rel.ro._ZTVN11UaClientSdk17UaReverseEndpointE[_ZTVN11UaClientSdk17UaReverseEndpointE]+0x48): undefined reference to `UaThread::start()'
/usr/bin/ld: /home/michal/Dokumenty/OPCUA_adapter/sdk/lib/libuaclientcppd.a(uareverseconnect.cpp.o):(.data.rel.ro._ZTIN11UaClientSdk17UaReverseEndpointE[_ZTIN11UaClientSdk17UaReverseEndpointE]+0x28): undefined reference to `typeinfo for UaThread'
collect2: error: ld returned 1 exit status
make: *** [Makefile:30: aplikace] Chyba 1
The terminal process "bash '-c', '/home/michal/Dokumenty/OPCUA_adapter/sdk/examples/client_gettingstarted/lesson01/build.sh'" terminated with exit code: 2.
Terminal will be reused by tasks, press any key to close it.
My Makefile is. Does anyone have
cc=g++
cflags=-g -Wall
libflags=-L/home/michal/Dokumenty/OPCUA_adapter/sdk/lib -luamoduled -luamodelsd -lcoremoduled -luabasecppd -luastackd -lxmlparsercppd -luapkicppd -luaclientcppd -lxml2 -lssl -lcrypto
includes=-I/home/michal/Dokumenty/OPCUA_adapter/sdk/include/uabasecpp\
-I/home/michal/Dokumenty/OPCUA_adapter/sdk/include/uastack\
-I/home/michal/Dokumenty/OPCUA_adapter/sdk/include/uaclientcpp\
-I/home/michal/Dokumenty/OPCUA_adapter/sdk/include/uapkicpp\
objfiles=client_cpp_sdk_tutorial.o sampleclient.o
vystup=aplikace
%.o : %.cpp
$(cc) $(cflags) $(includes) -c $<
# startovaci pravidlo
vychozi: $(vystup)
# zavislosti
dep:
$(cc) -MM *.cpp >dep.list
-include dep.list
clean:
rm aplikace $(objfiles)
# slinkování aplikace
$(vystup): $(objfiles)
$(cc) $(cflags) $(objfiles) $(libflags) $(includes) -o $#

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.

ERROR while debugging SFML code in Visual Studio Code

I made a project that is using SFML library on linux, it's working pretty fine. I start it by launching this script exec.sh:
g++ -c main.cpp -I/usr/include
g++ main.o -o sfml-app -L/usr/lib -lsfml-graphics -lsfml-window -lsfml-system
export LD_LIBRARY_PATH=/usr/lib && ./sfml-app
And here is the code de in the main.cpp file:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Blue);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
But the problem is that i can't debug it and i always have an error when trying it. Can someone give me an advice or explain how can i properly do it? I need the solution exactly for linux, i'm a newbie in this OC and IDE.
Here's the ERROR, after debugging using g++:
Starting build...
Build finished with error:
/usr/bin/ld: /tmp/ccnkqRHk.o: in function `main':
/home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::String::String(char const*, std::locale const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:6: undefined reference to `sf::CircleShape::CircleShape(float, unsigned long)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:7: undefined reference to `sf::Color::Blue'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:7: undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:9: undefined reference to `sf::Window::isOpen() const'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:12: undefined reference to `sf::Window::pollEvent(sf::Event&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:15: undefined reference to `sf::Window::close()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:18: undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:18: undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:19: undefined reference to `sf::RenderStates::Default'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:19: undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:20: undefined reference to `sf::Window::display()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: /tmp/ccnkqRHk.o: in function `sf::CircleShape::~CircleShape()':
/usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
/usr/bin/ld: /usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
/usr/bin/ld: /usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `sf::Shape::~Shape()'
collect2: error: ld returned 1 exit status
Try installing library to your system path.
For Arch based Linux -
sudo pacman -S sfml
For Debian based Linux -
sudo apt-get install sfml-dev
And just use following g++ command -
g++ -c main.cpp -o main.o
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
It is better to use a IDE for it. You can use
Code Blocks
Code Lite
Apache netbeans
Eclipse
And if you are familiar with cmake you can use-
Kdevelop

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.