当前位置: 首页 > 知识库问答 >
问题:

CMake C Project librealsense:未定义对 OpenGL 的引用与 CLion

鲍俊杰
2023-03-14

我正试图在Ubuntu 20.04上集成librealsense C CLion项目。< br >在终端中单独编译Librealsense可以正常工作。

项目如下所示:

RS_Pipeline
.
├── build
├── main.cpp
├── CMakeLists.txt
└── librealsense        // the integrated lib 
    ├── CMakeLists.txt
    ├── third-party     // libs like GLFW and GLAD which are use in the examples
    ├── examples        // 
    |   ├── example.hpp   // with class to generate OpenGL Window
    └── ...

克马尔主义者。基本文件夹中的txt看起来相当简单:

cmake_minimum_required(VERSION 3.2)
project(RS_Pipeline LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 11)
set(OpenGL_GL_PREFERENCE LEGACY)

add_executable(RS_Pipeline main.cpp librealsense/examples/example.hpp)

add_subdirectory(librealsense)

target_link_libraries(${PROJECT_NAME} realsense2)

当我试图将子模块包含到我的CLion项目中时,我得到了大量的:< code>main.cpp:(。text 0x23c):对glViewport错误消息的未定义引用,在基目录中构建my main.cpp失败。

不知何故<代码> #包含

另外:librealsense库中包含的示例也可以毫无问题地编译。(他们使用完全相同#include“librealsense/examples/example.hpp”。

看起来,CLion只是没有在我自己的main中找到正确的openGL。分别为cpp。如果我从example.hpp中包含它。

====================[ Build | RS_Pipeline | Release ]===========================
/snap/clion/175/bin/cmake/linux/bin/cmake --build /home/lukas/Development/Cpp/RS_Pipeline/cmake-build-release --target RS_Pipeline
[0/1] Re-running CMake...
-- Checking internet connection...
-- Internet connection identified
-- Info: REALSENSE_VERSION_STRING=2.50.0
-- Setting Unix configurations
-- Building libcurl enabled
-- using RS2_USE_V4L2_BACKEND
-- Could NOT find apriltag (missing: APRILTAG_INC APRILTAG_LIB) 
-- Unable to find apriltag library, skipping pose-apriltag example
-- Check for updates capability added to realsense-viewer
-- Check for updates capability added to realsense-depth-quality
-- Building with TM2
-- Fetching recommended firmwares:
-- D4XX_FW_VERSION: 5.13.0.50
-- SR3XX_FW_VERSION: 3.26.1.0
-- T26X_FW_VERSION: 0.2.0.951
-- L51X_FW_VERSION: 1.5.8.1
-- L53X_FW_VERSION: 3.5.5.1
-- https://librealsense.intel.com/Releases/RS4xx/FW/D4XX_FW_Image-5.13.0.50.bin
-- Download firmware 0;"returning early; file already exists with expected SHA1 hash" for D4XX_FW_Image-5.13.0.50.bin
-- https://librealsense.intel.com/Releases/SR300/FW/SR3XX_FW_Image-3.26.1.0.bin
-- Download firmware 0;"returning early; file already exists with expected SHA1 hash" for SR3XX_FW_Image-3.26.1.0.bin
-- https://librealsense.intel.com/Releases/TM2/FW/target/0.2.0.951/target-0.2.0.951.mvcmd
-- Download firmware 0;"returning early; file already exists with expected SHA1 hash" for target-0.2.0.951.mvcmd
-- https://librealsense.intel.com/Releases/L5xx/FW/L51X_FW_Image-1.5.8.1.bin
-- Download firmware 0;"returning early; file already exists with expected SHA1 hash" for L51X_FW_Image-1.5.8.1.bin
-- https://librealsense.intel.com/Releases/L5xx/FW/L53X_FW_Image-3.5.5.1.bin
-- Download firmware 0;"returning early; file already exists with expected SHA1 hash" for L53X_FW_Image-3.5.5.1.bin
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lukas/Development/Cpp/RS_Pipeline/cmake-build-release
[1/1] Linking CXX executable RS_Pipeline
FAILED: RS_Pipeline 
: && /usr/bin/c++ -O3 -DNDEBUG -rdynamic CMakeFiles/RS_Pipeline.dir/main.cpp.o -o RS_Pipeline  -Wl,-rpath,/home/lukas/Development/Cpp/RS_Pipeline/cmake-build-release/librealsense  librealsense/librealsense2.so.2.50.0  -lglfw && :
/usr/bin/ld: CMakeFiles/RS_Pipeline.dir/main.cpp.o: in function `set_viewport(rect const&)':
main.cpp:(.text+0x23c): undefined reference to `glViewport'
/usr/bin/ld: main.cpp:(.text+0x241): undefined reference to `glLoadIdentity'
/usr/bin/ld: main.cpp:(.text+0x24b): undefined reference to `glMatrixMode'
/usr/bin/ld: CMakeFiles/RS_Pipeline.dir/main.cpp.o: in function `draw_pointcloud(float, float, glfw_state&, rs2::points&)':
main.cpp:(.text+0x2bb): undefined reference to `glLoadIdentity'
/usr/bin/ld: main.cpp:(.text+0x2c5): undefined reference to `glPushAttrib'
/usr/bin/ld: main.cpp:(.text+0x2e0): undefined reference to `glClearColor'
/usr/bin/ld: main.cpp:(.text+0x2ea): undefined reference to `glClear'
/usr/bin/ld: main.cpp:(.text+0x2f4): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0x2f9): undefined reference to `glPushMatrix'
/usr/bin/ld: main.cpp:(.text+0x32a): undefined reference to `gluPerspective'
/usr/bin/ld: main.cpp:(.text+0x334): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0x339): undefined reference to `glPushMatrix'
/usr/bin/ld: main.cpp:(.text+0x36c): undefined reference to `gluLookAt'
/usr/bin/ld: main.cpp:(.text+0x394): undefined reference to `glTranslatef'
/usr/bin/ld: main.cpp:(.text+0x3b2): undefined reference to `glRotated'
/usr/bin/ld: main.cpp:(.text+0x3cf): undefined reference to `glRotated'
/usr/bin/ld: main.cpp:(.text+0x3e3): undefined reference to `glTranslatef'
/usr/bin/ld: main.cpp:(.text+0x3f6): undefined reference to `glPointSize'
/usr/bin/ld: main.cpp:(.text+0x400): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0x40a): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0x417): undefined reference to `glBindTexture'
/usr/bin/ld: main.cpp:(.text+0x437): undefined reference to `glTexParameterfv'
/usr/bin/ld: main.cpp:(.text+0x44b): undefined reference to `glTexParameteri'
/usr/bin/ld: main.cpp:(.text+0x45f): undefined reference to `glTexParameteri'
/usr/bin/ld: main.cpp:(.text+0x466): undefined reference to `glBegin'
/usr/bin/ld: main.cpp:(.text+0x516): undefined reference to `glEnd'
/usr/bin/ld: main.cpp:(.text+0x51b): undefined reference to `glPopMatrix'
/usr/bin/ld: main.cpp:(.text+0x525): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0x52a): undefined reference to `glPopMatrix'
/usr/bin/ld: main.cpp:(.text+0x52f): undefined reference to `glPopAttrib'
/usr/bin/ld: main.cpp:(.text+0x558): undefined reference to `glVertex3fv'
/usr/bin/ld: main.cpp:(.text+0x566): undefined reference to `glTexCoord2fv'
/usr/bin/ld: CMakeFiles/RS_Pipeline.dir/main.cpp.o: in function `draw_pointcloud_wrt_world(float, float, glfw_state&, rs2::points&, rs2_pose&, float*, std::vector >&)':
main.cpp:(.text+0x98b): undefined reference to `glLoadIdentity'
/usr/bin/ld: main.cpp:(.text+0x995): undefined reference to `glPushAttrib'
/usr/bin/ld: main.cpp:(.text+0x9b0): undefined reference to `glClearColor'
/usr/bin/ld: main.cpp:(.text+0x9ba): undefined reference to `glClear'
/usr/bin/ld: main.cpp:(.text+0x9c4): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0x9c9): undefined reference to `glPushMatrix'
/usr/bin/ld: main.cpp:(.text+0x9fa): undefined reference to `gluPerspective'
/usr/bin/ld: main.cpp:(.text+0xa04): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0xa09): undefined reference to `glPushMatrix'
/usr/bin/ld: main.cpp:(.text+0xa2f): undefined reference to `glTranslatef'
/usr/bin/ld: main.cpp:(.text+0xa4a): undefined reference to `glRotated'
/usr/bin/ld: main.cpp:(.text+0xa65): undefined reference to `glRotated'
/usr/bin/ld: main.cpp:(.text+0xa79): undefined reference to `glTranslatef'
/usr/bin/ld: main.cpp:(.text+0xa83): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xa90): undefined reference to `glLineWidth'
/usr/bin/ld: main.cpp:(.text+0xa9a): undefined reference to `glBegin'
/usr/bin/ld: main.cpp:(.text+0xac4): undefined reference to `glColor3f'
/usr/bin/ld: main.cpp:(.text+0xad8): undefined reference to `glVertex3f'
/usr/bin/ld: main.cpp:(.text+0xae2): undefined reference to `glEnd'
/usr/bin/ld: main.cpp:(.text+0xaef): undefined reference to `glLineWidth'
/usr/bin/ld: main.cpp:(.text+0xb02): undefined reference to `glColor3f'
/usr/bin/ld: main.cpp:(.text+0xb2f): undefined reference to `glMultMatrixf'
/usr/bin/ld: main.cpp:(.text+0xb37): undefined reference to `glMultMatrixf'
/usr/bin/ld: main.cpp:(.text+0xb4a): undefined reference to `glPointSize'
/usr/bin/ld: main.cpp:(.text+0xb54): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xb5e): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xb71): undefined reference to `glBindTexture'
/usr/bin/ld: main.cpp:(.text+0xb91): undefined reference to `glTexParameterfv'
/usr/bin/ld: main.cpp:(.text+0xba5): undefined reference to `glTexParameteri'
/usr/bin/ld: main.cpp:(.text+0xbb9): undefined reference to `glTexParameteri'
/usr/bin/ld: main.cpp:(.text+0xbc0): undefined reference to `glBegin'
/usr/bin/ld: main.cpp:(.text+0xc76): undefined reference to `glEnd'
/usr/bin/ld: main.cpp:(.text+0xc7b): undefined reference to `glPopMatrix'
/usr/bin/ld: main.cpp:(.text+0xc85): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0xc8a): undefined reference to `glPopMatrix'
/usr/bin/ld: main.cpp:(.text+0xc8f): undefined reference to `glPopAttrib'
/usr/bin/ld: main.cpp:(.text+0xcc0): undefined reference to `glVertex3fv'
/usr/bin/ld: main.cpp:(.text+0xcce): undefined reference to `glTexCoord2fv'
/usr/bin/ld: CMakeFiles/RS_Pipeline.dir/main.cpp.o: in function `set_viewport(rect const&)':
main.cpp:(.text+0x27b): undefined reference to `glOrtho'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

共有2个答案

严峰
2023-03-14

@Botje多谢了,真快!现在,它正在与以下CMakeLists合作:

cmake_minimum_required(VERSION 3.2)
project(RS_Pipeline LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 11)
set(OpenGL_GL_PREFERENCE LEGACY)

find_package(OpenGL REQUIRED)


add_executable(RS_Pipeline main.cpp librealsense/examples/example.hpp)

add_subdirectory(librealsense)

target_link_libraries(${PROJECT_NAME}
        realsense2
        glfw OpenGL::GL
        glfw OpenGL::GLU
)

看起来这个话题已经可以结束了。

端木宏才
2023-03-14

这些示例都包含此文件,而您没有:

find_package(OpenGL REQUIRED)
set(DEPENDENCIES realsense2 glfw ${OPENGL_LIBRARIES})

这使得< code>realsense2库依赖于GLFW和您的OpenGL堆栈。

将以下内容添加到CMakeLists.txt中:

find_package(OpenGL REQUIRED)
target_link_libraries(${PROJECT_NAME} glfw OpenGL::GL )
 类似资料:
  • 我只是想让OpenGL在我的机器(Windows 7 64位)上使用GLFW工作。 我得到了单一的链接器错误: 我试图编译的代码是最简单的(在Test.cpp文件中)。 我正在使用一个简单的Makefile来尝试编译: 其他信息: 使用g编译(MinGW32) lib文件夹包含glfw3.dll、libglfw3. a和libglfw3dll. a(从GLFW网站下载的Win32版本-Window

  • 问题内容: 我在Ubuntu 11.04上编写了一个使用freeglut的程序。工作正常。然后,我得到了另一台计算机,并尝试在全新安装的Ubuntu 11.04上运行该程序。不起作用 所以我安装了 1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev mesa-common-dev gcc` 并尝试运行该程序,该程序会导入 使用命令 但是,链接器或类似内容会弹出20

  • 我正在尝试使用AassetManager从android apk访问资产。然而,尽管我已经包含了asset_manager.h和asset_manager_jni.h,但我仍然得到了“对aassetmanager_fromjava的未定义引用”。其他来自asset_manager.h的函数,如AAssetManager_openDir(mgr,"“)等也不能被引用。 以下是完整的代码 这段代码在一

  • 错误:未定义对'pthread_cancel'的引用

  • 问题内容: 我正在使用Linux,并且具有以下文件: 该函数在中声明和定义。我需要在中使用该函数,因此我将该函数声明为 在。 但是,在编译过程中,我得到了错误 怎么了? 谢谢。 预计到达时间:多亏了我收到的答案,我现在有了以下内容: 在fileA.h中,我有 在fileA.c中,我有 在fileB.h中,我有 在fileB.cpp中,我有 但是,我现在有错误 问题答案: 如果您确实是使用C而不是C

  • 问题内容: 我正在尝试使用mingw的gcc与我的MSVC构建的python26_d一起运行Rabbyt库的调试版本。我有很多未定义的引用,这导致我创建了libpython26_d.a,但是仍然存在一个未定义的引用。谷歌搜索给我: http://www.techlists.org/archives/programming/pythonlist/2003-03/msg01035.shtml 但是-r