skip to Main Content

I am developping a little bot to handle friendly bets with my friends on discord. I use the D++ library for the discord server part.

Until now, I have been working using Visual Studio with WSL and it was working fine. But since I would like to try C++ modules I would need a CMake version higher than 3.19 and it seems that VS-WSL can’t go higher (but that’s another question). So I decided to simply get my repository in my WSL session and to compile it manually. I also took the opportunity to update to clang 18.

CMake generation works fine, the compilations works fine but when it comes to the link I have the following error:

/usr/bin/ld: CMakeFiles/BetBot.dir/src/SaveManager.cpp.o: undefined reference to symbol ‘_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1ERKNSt7__cxx1112basic_stringIcS1_SaIcEEESt13_Ios_Openmode@@GLIBCXX_3.4.21’
/usr/bin/ld: /lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
clang-18: error: linker command failed with exit code 1 (use -v to see invocation)

My CMake :

cmake_minimum_required(VERSION 3.28)
project(BetBot VERSION 1.0 DESCRIPTION "A simple discord bot to handle friendly bets.")
 
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
add_executable(${PROJECT_NAME}
    "src/main.cpp"
    "src/AddBetCommand.cpp"
    "src/AddBetCommand.h"
    "src/AddMatchCommand.cpp"
    "src/AddMatchCommand.h"
    "src/AddResultCommand.cpp"
    "src/AddResultCommand.h"
    "src/Bet.cpp"
    "src/Bet.h"
    "src/BettorResults.cpp"
    "src/BettorResults.h"
    "src/ICommand.cpp"
    "src/ICommand.h"
    "src/ICommandReceiver.cpp"
    "src/ICommandReceiver.h"
    "src/BotData.cpp"
    "src/BotData.h"
    "src/Match.cpp"
    "src/Match.h"
    "src/MatchScore.h"
    "src/ShowBetsCommand.cpp"
    "src/ShowBetsCommand.h"
    "src/ShowBettorsResultsCommand.cpp"
    "src/ShowBettorsResultsCommand.h"
    "src/ShowMatchesCommand.cpp"
    "src/ShowMatchesCommand.h"
    "src/JsonSerializer.cpp"
    "src/JsonSerializer.h"
    "src/SaveManager.cpp"
    "src/SaveManager.h"
    "src/BetBot.cpp"
    "src/BetBot.h"
    )
 
find_package(DPP REQUIRED)
 
target_link_libraries(${PROJECT_NAME} 
    ${DPP_LIBRARIES}
)
 
target_include_directories(${PROJECT_NAME} PRIVATE
    ${DPP_INCLUDE_DIR}
)
 
set_target_properties(${PROJECT_NAME} PROPERTIES
    CXX_STANDARD 20
    CXX_STANDARD_REQUIRED ON
)

I am very new to CMake so I must admit that I don’t fully understand what each command of my file does, but it was working when I was working with WSL.

From what I have found on the net, there might be a problem with my target_link_libraries but I don’t see what else I could do here.

EDIT : Here is the content of the SaveManager.cpp

#include "SaveManager.h"

#include <fstream>

#include "BotData.h"
#include "JsonSerializer.h"

SaveManager::SaveManager(std::string filePath, BotData& data): m_SaveFilePath(std::move(filePath)), m_Data(data)
{
    m_Serializer = std::make_unique<JsonSerializer>();
}

void SaveManager::Save() const
{
    std::ofstream os(m_SaveFilePath, std::ofstream::out);
    m_Serializer->Serialize(m_Data, os);
    os.close();
}

void SaveManager::Load() const
{
    if (std::ifstream is(m_SaveFilePath); is.good()) // does file exists ?
    {
        m_Serializer->UnSerialize(is, m_Data);
        is.close();
    }
}

Edit 2: The full command used to build

@DESKTOP-VP8IL4T:/mnt/c/Users/Benjamin/wsl/LoLBetBot/out$ make VERBOSE=1
/mnt/c/Users/Benjamin/cmake/cmake-3.29.2-linux-x86_64/bin/cmake -S/mnt/c/Users/Benjamin/wsl/LoLBetBot -B/mnt/c/Users/Benjamin/wsl/LoLBetBot/out --check-build-system CMakeFiles/Makefile.cmake 0
/mnt/c/Users/Benjamin/cmake/cmake-3.29.2-linux-x86_64/bin/cmake -E cmake_progress_start /mnt/c/Users/Benjamin/wsl/LoLBetBot/out/CMakeFiles /mnt/c/Users/Benjamin/wsl/LoLBetBot/out//CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/mnt/c/Users/Benjamin/wsl/LoLBetBot/out'
make  -f CMakeFiles/BetBot.dir/build.make CMakeFiles/BetBot.dir/depend
make[2]: Entering directory '/mnt/c/Users/Benjamin/wsl/LoLBetBot/out'
cd /mnt/c/Users/Benjamin/wsl/LoLBetBot/out && /mnt/c/Users/Benjamin/cmake/cmake-3.29.2-linux-x86_64/bin/cmake -E cmake_depends "Unix Makefiles" /mnt/c/Users/Benjamin/wsl/LoLBetBot /mnt/c/Users/Benjamin/wsl/LoLBetBot /mnt/c/Users/Benjamin/wsl/LoLBetBot/out /mnt/c/Users/Benjamin/wsl/LoLBetBot/out /mnt/c/Users/Benjamin/wsl/LoLBetBot/out/CMakeFiles/BetBot.dir/DependInfo.cmake "--color="
make[2]: Leaving directory '/mnt/c/Users/Benjamin/wsl/LoLBetBot/out'
make  -f CMakeFiles/BetBot.dir/build.make CMakeFiles/BetBot.dir/build
make[2]: Entering directory '/mnt/c/Users/Benjamin/wsl/LoLBetBot/out'
[  5%] Linking CXX executable BetBot
/mnt/c/Users/Benjamin/cmake/cmake-3.29.2-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/BetBot.dir/link.txt --verbose=1
/usr/bin/clang-18 CMakeFiles/BetBot.dir/src/main.cpp.o CMakeFiles/BetBot.dir/src/AddBetCommand.cpp.o CMakeFiles/BetBot.dir/src/AddMatchCommand.cpp.o CMakeFiles/BetBot.dir/src/AddResultCommand.cpp.o CMakeFiles/BetBot.dir/src/Bet.cpp.o CMakeFiles/BetBot.dir/src/BettorResults.cpp.o CMakeFiles/BetBot.dir/src/ICommand.cpp.o CMakeFiles/BetBot.dir/src/ICommandReceiver.cpp.o CMakeFiles/BetBot.dir/src/BotData.cpp.o CMakeFiles/BetBot.dir/src/Match.cpp.o CMakeFiles/BetBot.dir/src/ShowBetsCommand.cpp.o CMakeFiles/BetBot.dir/src/ShowBettorsResultsCommand.cpp.o CMakeFiles/BetBot.dir/src/ShowMatchesCommand.cpp.o CMakeFiles/BetBot.dir/src/JsonSerializer.cpp.o CMakeFiles/BetBot.dir/src/SaveManager.cpp.o CMakeFiles/BetBot.dir/src/BetBot.cpp.o -o BetBot  /usr/lib/libdpp.so
/usr/bin/ld: CMakeFiles/BetBot.dir/src/SaveManager.cpp.o: undefined reference to symbol '_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1ERKNSt7__cxx1112basic_stringIcS1_SaIcEEESt13_Ios_Openmode@@GLIBCXX_3.4.21'
/usr/bin/ld: /lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
clang-18: error: linker command failed with exit code 1 (use -v to see invocation)

2

Answers


  1. Chosen as BEST ANSWER

    Comment from @Tsyvarev

    "Then I used export CXX=clang-18" - So you have assigned C compiler to the variable which is intended for C++ compiler. See e.g. stackoverflow.com/a/49258166/3440745

    Thanks for the help !


  2. Yes it looks like a link error while trying to link the object file created for SaveManager.cpp. The linker could not find the symbol Ios_Openmode used in the SaveManager.cpp. Could you please check whether this function is called within the mentioned .cpp file. If it is used, then you need to add the proper library name in the target_link_libraries section to resolve that symbol.

    Or else could you upload the .cpp file for more reference?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search