柯南中不包含 OpenSceneGraph 插件?

OpenSceneGraph plugin not included in Conan?

我正在尝试使用 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