I've my discord bot project. The file structure of the relevant files are listed as below:
include/
cpp-dotenv/
dotenv.h
lib/
libcpp_dotenv.a
src/
CMakeLists.txt
My simplified CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
set(BOT_NAME "tavernbot")
project(${BOT_NAME})
aux_source_directory(src mainsrc)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
add_executable(
${BOT_NAME}
${mainsrc})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
target_include_directories(${BOT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(${BOT_NAME}
cpp_dotenv
)
When I'm building I'm getting the following errors:
/usr/bin/ld: /mnt/e/my_bot/lib/libcpp_dotenv.a(dotenv.cpp.o): in function `dotenv::dotenv::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
dotenv.cpp:(.text+0x24): undefined reference to `dotenv::getenv(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: /mnt/e/my_bot/lib/libcpp_dotenv.a(dotenv.cpp.o): in function `dotenv::dotenv::load_dotenv(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool)':
dotenv.cpp:(.text+0x1e1): undefined reference to `dotenv::Parser::Parser()'
/usr/bin/ld: dotenv.cpp:(.text+0x1f6): undefined reference to `dotenv::Parser::parse(std::istream&, bool, bool)'
/usr/bin/ld: dotenv.cpp:(.text+0x220): undefined reference to `antlr4::tree::ParseTreeWalker::~ParseTreeWalker()'
/usr/bin/ld: /mnt/e/my_bot/lib/libcpp_dotenv.a(dotenv.cpp.o): in function `dotenv::Parser::~Parser()':
dotenv.cpp:(.text._ZN6dotenv6ParserD2Ev[_ZN6dotenv6ParserD5Ev]+0x1b): undefined reference to `antlr4::tree::ParseTreeWalker::~ParseTreeWalker()'
/usr/bin/ld: /mnt/e/my_bot/lib/libcpp_dotenv.a(dotenv.cpp.o): in function `dotenv::Parser::~Parser()':
dotenv.cpp:(.text._ZN6dotenv6ParserD0Ev[_ZN6dotenv6ParserD5Ev]+0x1b): undefined reference to `antlr4::tree::ParseTreeWalker::~ParseTreeWalker()'
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/tavernbot.dir/build.make:134: tavernbot] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:139: CMakeFiles/tavernbot.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:146: CMakeFiles/tavernbot.dir/rule] Error 2
gmake: *** [Makefile:169: tavernbot] Error 2
Could you tell me where I'm wrong in my CMakeLists.txt and why?