-2

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.

Dakom
  • 11
  • 5

1 Answers1

0

Someone helped me IRL so I'll share my newly acquired knowledge. As you probably know, when there is an "unresolved external symbol" error it means the compiler cannot find where is the symbol. Below are the steps to fix this :

  1. Find the name of the function or symbol which isn't found. Example :

[...]\tuto_librealsense\2_capture\out\build\x64-Debug\rs-capture.cpp.obj: error LNK2019: unresolved external symbol gluPerspective referenced in function "void __cdecl draw_pointcloud(float,float,struct glfw_state &,class rs2::points &)" (?draw_pointcloud@@YAXMMAEAUglfw_state@@AEAVpoints@rs2@@@Z)

Here you can see the symbol "draw_pointcloud" isn't resolved which leads us to the next step : research.

  1. So you first search for it in your solution. In my case I found it in example.hpp and it was a function definition :
void draw_pointcloud(float width, float height, glfw_state& app_state, rs2::points& points)
{
    if (!points)
        return;

    // OpenGL commands that prep screen for the pointcloud
    glLoadIdentity();
    glPushAttrib(GL_ALL_ATTRIB_BITS);

Now you can see they are some other symbols which are not standard C++ syntax such as glLoadIdentity so you search glLoadIdentity on the internet : in my case the first result I got was the Microsoft website because it's a native Windows library. On this page I found that this function belongs to the Opengl32 library and the corresponding file is Opengl32.lib which leads us to the next step :

  1. Locate the .lib file on your PC or download it. In this case it's a native library so you go and search it in C:\Program Files\ or C:\Program Files (x86)\. Notice that the 32 at the end the filename indicates you to search it on the the directory ending by (x86) since it means it's a 32 bit library.

  2. Give the location of the .lib file to your CMakeLists.txt ( or in the property pages of your C++ project). Example : the two lines I modified in my CMakeLists.txt :

set(DEPENDENCIES "C:/Program Files (x86)/Intel RealSense SDK 2.0/lib/x64/realsense2.lib" "C:/Program Files/GL/GLFWx64/lib-vc2022/glfw3.lib" "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.19041.0/um/x64/OpenGL32.Lib"   "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.19041.0/um/x64/GlU32.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")

output of the code :D

E_net4
  • 27,810
  • 13
  • 101
  • 139
Dakom
  • 11
  • 5