I've looked and tried the solutions provided in the many other posts regarding my issue but none of them worked for me. So I've been working on a project that requires the use of librealsense, a library which allows realsense camera users to do many things with their cameras. In order to understand better the potential of this library, I tried building some of their examples with a CMakeLists.txt on Visual Studio 2022 (I can't have a Linux OS). I successfully built and executed the first example "Hello-Realsense" so I think it's possible to build with a CMakeList on Visual Studio. However, the second project ( https://github.com/IntelRealSense/librealsense/tree/master/examples/capture ) gives me 42 unresolved externals, here is a few :
[...]tuto_librealsense\2_capture\out\build\x64-Debug\LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
[...]tuto_librealsense\2_capture\out\build\x64-Debug\rs-capture.cpp.obj : error LNK2019: unresolved external symbol __imp_glBegin referenced in function "void __cdecl draw_pointcloud(float,float,struct glfw_state &,class rs2::points &)" (?draw_pointcloud@@YAXMMAEAUglfw_state@@AEAVpoints@rs2@@@Z)
[...]tuto_librealsense\2_capture\out\build\x64-Debug\rs-capture.cpp.obj : error LNK2019: unresolved external symbol __imp_glBindTexture referenced in function "void __cdecl draw_pointcloud(float,float,struct glfw_state &,class rs2::points &)" (?draw_pointcloud@@YAXMMAEAUglfw_state@@AEAVpoints@rs2@@@Z)
There is also that warning which says there might be a conflict between my OS libs and the libs I try to link as you can see.
Here is an overview of my project organization : my CMakeLists.txt, example.hpp and rs-capture.cpp
The example.hpp file is a header which must be included in the project according to the example creator. It is this file which forces me to use the GLFW library which I guess I must be linking incorrectly, although I followed the same logic which allowed me to build correctly the Hello-Realsense project which is placing the .lib files in the DEPENDENCIES macro and the header files of my libs in the PATH_TO_HEADERS macro. Also I took the glfw3.lib file from the lib-vc2022 folder since my Visual Studio version is 2022 but I admit this is a little arbitrary.
cmake_minimum_required(VERSION 3.1.0)
project(RealsenseExamplesCapture)
add_executable(rs-capture rs-capture.cpp example.hpp)
set_property(TARGET rs-capture PROPERTY CXX_STANDARD 11)
set(DEPENDENCIES "C:/Program Files (x86)/Intel RealSense SDK 2.0/lib/x64/realsense2.lib" "C:/Program Files/GL/GLFWx64/lib-vc2022/glfw3.lib")
set(PATH_TO_HEADERS "C:/Program Files (x86)/Intel RealSense SDK 2.0/include/" "C:/Program Files/GL/GLFWx64/include/GLFW" "C:/Program Files (x86)/Intel RealSense SDK 2.0/samples")
target_link_libraries(rs-capture ${DEPENDENCIES})
INCLUDE_DIRECTORIES(${PATH_TO_HEADERS})
install(TARGETS rs-capture RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Also, I put the glfw3.dll file in the C:\Windows\System32 directory as I saw on a WikiHow tutorial.