微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Conan 中不包含 OpenSceneGraph 插件?

如何解决Conan 中不包含 OpenSceneGraph 插件?

我正在尝试使用 OpenSceneGraph 进行简单的网格查看器,并且我想使用 Conan 作为依赖项。 编译在调试和发布模式下都运行良好(我现在使用 msvc 工具链在 Windows 上进行编译)。

只要我尝试加载任何类型的网格,osgDB::readNodeFiles 就会失败。看起来插件没有链接到最终的二进制文件。 我检查了柯南的包,.lib 的插件列表存在,我猜应该是链接的。 我会错过什么?

有我的 conanfile.txt :

[requires]
    openscenegraph/3.6.5
[generators]
cmake

CMakeLists.txt 也很简单:

cmake_minimum_required(VERSION 3.17)

# Set a default build type if none was specified
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONfigURATION_TYPES)
    message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
    set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
            STRING "Choose the type of build." FORCE)
    # Set the possible values of build type for cmake-gui
    set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
            "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

set(PROJECT_NAME 3D_radio)

project(${PROJECT_NAME})

if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    conan_basic_setup()
    set(CMAKE_CONfigURATION_TYPES ${CONAN_CONfigURATION_TYPES})
else()
    message(WARNING "The file conanbuildinfo.cmake doesn't exist,you have to run conan install first")
endif()

# get all source files
file(GLOB all_SRCS
        "include/*.h"
        "source/*.cpp"
        )

# add executable and addShader libraries
add_executable(${PROJECT_NAME} ${all_SRCS} source/main.cpp include/main.h)

target_include_directories(${PROJECT_NAME} PRIVATE
        include
        ${CONAN_INCLUDE_Dirs}
        )

target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})

而且代码也很简单:

int main(int argc,char **argv) {
    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);

    // read the scene from the list of file specified commandline args.
    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);

    // if not loaded assume no arguments passed in,try use default mode instead.
    if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt");

    // if no model has been successfully loaded report failure.
    if (!loadedModel)
    {
        std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
        return 1;
    }
}

控制台输出

C:\...\cmake-build-release\bin\program.exe C:\...\first.obj
C:\...\cmake-build-release\bin\program.exe: No data loaded
Error reading file C:\...\first.obj: read error (Could not find plugin to read objects from file "C:\...\first.obj".)
Error reading file cow.osgt: read error (Could not find plugin to read objects from file "cow.osgt".)

例如,我可以在 Paint 3D 中打开这些文件。所以我知道他们是对的。问题似乎来自链接。有什么想法吗?

解决方法

我找到了解决方案。 我正在静态编译程序,插件链接到最终的二进制文件,但插件注册表查找动态库(例如 osgdb_obj.dll)。

如果你有同样的问题,你必须手动注册插件:

USE_OSGPLUGIN(obj)
USE_GRAPHICSWINDOW() // and you may want this to get a window

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。