Hi all, apologies if this is obvious or a commonly asked question but I feel truly helpless right now; I’ve searched what feels like countless similar questions and am unable to figure out what I’m doing wrong for what I want to do.
I’m trying to simply include header files in my project and their implementations without having to make separate .lib files (which I’m under the impression is a thing that is possible?). Here’s the project structure:
build (files not relevant)
bin (files not relevant)
src
----main.cpp
----CMakeLists.txt
----types
--------types.hpp
----radius
--------radius.cpp
--------radius.hpp
test (files not relevant)
CMakeLists.txt
Here’s the root CMakeLists file:
cmake_minimum_required(VERSION 3.31.0)
project(lwradius)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.86 REQUIRED PATHS C:/Boost)
link_libraries(${Boost_LIBRARIES})
link_libraries(${WORKING_DIRECTORY})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${WORKING_DIRECTORY})
add_subdirectory(src/)
add_subdirectory(test/)
Here’s the CMakeLists in src/
cmake_minimum_required(VERSION 3.31.0)
add_executable(lwradius main.cpp radius/radius.cpp)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.86 REQUIRED PATHS C:/Boost)
link_libraries(${Boost_LIBRARIES})
include_directories(${Boost_INCLUDE_DIRS})
target_include_directories(lwradius PRIVATE ./types ./radius)
install(TARGETS lwradius)
target_compile_options(lwradius PUBLIC -std:c++20)
My radius.cpp has the line #include “radius.hpp” and my main.cpp has #include “radius/radius.hpp” but I still keep getting the error:
main.obj : error LNK2019: unresolved external symbol "struct lwradius::types::radius_packet __cdecl lwradius::radius::decode(class std::array<enum std::byte,4096> const &,unsigned __int64)" (?decode@radius@lwradius@@YA
?AUradius_packet@types@2@AEBV?$array@W4byte@std@@$0BAAA@@std@@_K@Z) referenced in function "class boost::asio::awaitable<void,class boost::asio::any_io_executor> __cdecl handle_packet$_ResumeCoro$1(class boost::asio::b
asic_datagram_socket<class boost::asio::ip::udp,class boost::asio::any_io_executor>)" (?handle_packet$_ResumeCoro$1@@YA?AV?$awaitable@XVany_io_executor@asio@boost@@@asio@boost@@V?$basic_datagram_socket@Vudp@ip@asio@boo
st@@Vany_io_executor@34@@23@@Z)
Yet if I #include “radius/radius.cpp” somehow it works. What gives?