我已经看过并尝试了许多有关我的问题的其他文章中提供的解决方案,但它们都不适合我。因此,我一直在研究一个需要使用librealsense的项目,该项目允许Realsense Camera用户使用相机来做很多事情。为了更好地了解该库的潜力,我尝试使用CMakelists.txt在Visual Studio 2022上构建他们的一些示例(我没有Linux OS)。我成功地构建并执行了第一个示例“ Hello-Realsense”,因此我认为可以在Visual Studio上使用Cmakelist构建。但是,第二个项目()给了我42个未解决的外部,这里有几个:
[...]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)
也有警告说我的OS libs和我尝试链接的Libs之间可能存在冲突。
这是我项目组织的概述:
我的cmakelists.txt,exampe.hpp和rs-capture.cpp
example.hpp文件是根据示例创建者必须包含在项目中的标题。正是这个文件迫使我使用GLFW库,我想我必须错误地链接,尽管我遵循了相同的逻辑,这使我能够正确地构建Hello-Realsense Project,该项目将.lib文件放置在依赖项宏和我的libs的标头文件在path_to_headers宏中。另外,由于我的Visual Studio版本是2022,因此我从LIB-VC2022文件夹中获取了Glfw3.lib文件,但我承认这是任意的。
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})
另外,我将glfw3.dll文件放在c:\ windows \ system32目录中,如我在wikihow教程上所见。
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.
发布评论
评论(1)
有人帮助我IRL,所以我将分享我新获得的知识。您可能知道,当存在“未解决的外部符号”错误时,这意味着编译器找不到符号在哪里。以下是解决此问题的步骤:
示例:
[...] \ tuto_librealsense \ 2_capture \ out \ build \ build \ x64-debug \ rs-capture.cpp.obj:错误lnk2019:未解决的外部符号gluperspective在功能中引用了“ void” struct glfw_state&,class rs2 :: points&)“(?draw_pointcloud @@ yaxmmaeauglfw_state @@ @@ eaevpoints@rs2 @@ z z
)下一步:研究。
就我而言, GoT是Microsoft网站,因为它是本机Windows库。在此页面上,我发现此功能属于OpenGL32库,相应的文件是OpenGL32.Lib,它导致我们进入下一步:
在您的PC上找到.lib文件或下载它。在这种情况下,它是一个本机库,因此您可以在
c:\ program Files \
或c:\ program Files(x86)\
中搜索它。请注意,最终的32个文件名表示您在(x86)结尾的目录上搜索它,因为这意味着它是一个32位库。将.lib文件的位置提供给您的cmakelists.txt(或在C ++项目的属性页面中)。
示例:我在cmakelists.txt中修改的两行:
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 :
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.
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 :
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\
orC:\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.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 :