繁体   English   中英

从OpenVDB编译Hello World示例

[英]Compiling Hello World example from OpenVDB

我遇到了一些问题,如下所示:

error LNK2001: unresolved external symbol "__declspec(dllimport) const openvdb::v3_0_0::tree::TreeBase::`vftable'" (__imp_??_7TreeBase@tree@v3_0_0@openvdb@@6B@)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __cdecl openvdb::v3_0_0::GridBase::saveFloatAsHalf(void)const " (__imp_?saveFloatAsHalf@GridBase@v3_0_0@openvdb@@QEBA_NXZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl openvdb::v3_0_0::util::printBytes(class std::basic_ostream<char,struct std::char_traits<char> > &,unsigned __int64,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool,int,int)" (__imp_?printBytes@util@v3_0_0@openvdb@@YAHAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@_KAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@5@2_NHH@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static bool __cdecl openvdb::v3_0_0::Metadata::isRegisteredType(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?isRegisteredType@Metadata@v3_0_0@openvdb@@SA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class boost::shared_ptr<class openvdb::v3_0_0::Metadata> __cdecl openvdb::v3_0_0::Metadata::createMetadata(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?createMetadata@Metadata@v3_0_0@openvdb@@SA?AV?$shared_ptr@VMetadata@v3_0_0@openvdb@@@boost@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl openvdb::v3_0_0::math::Transform::print(class std::basic_ostream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (__imp_?print@Transform@math@v3_0_0@openvdb@@QEBAXAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@6@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl openvdb::v3_0_0::initialize(void)" (__imp_?initialize@v3_0_0@openvdb@@YAXXZ)

代码:

#include <openvdb/openvdb.h>
#include <iostream>

#pragma comment(lib,"openvdb.lib")
int main()
{
    // Initialize the OpenVDB library.  This must be called at least
    // once per program and may safely be called multiple times.
    openvdb::initialize();
    // Create an empty floating-point grid with background value 0. 
    openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create();
    std::cout << "Testing random access:" << std::endl;
    // Get an accessor for coordinate-based access to voxels.
    openvdb::FloatGrid::Accessor accessor = grid->getAccessor();
    // Define a coordinate with large signed indices.
    openvdb::Coord xyz(1000, -200000000, 30000000);

    // Set the voxel value at (1000, -200000000, 30000000) to 1.
    accessor.setValue(xyz, 1.0);

    // Verify that the voxel value at (1000, -200000000, 30000000) is 1.
    std::cout << "Grid" << xyz << " = " << accessor.getValue(xyz) << std::endl;

    // Reset the coordinates to those of a different voxel.
    xyz.reset(1000, 200000000, -30000000);

    // Verify that the voxel value at (1000, 200000000, -30000000) is
    // the background value, 0.
    std::cout << "Grid" << xyz << " = " << accessor.getValue(xyz) << std::endl;

    // Set the voxel value at (1000, 200000000, -30000000) to 2.
    accessor.setValue(xyz, 2.0);
    // Set the voxels at the two extremes of the available coordinate space.
    // For 32-bit signed coordinates these are (-2147483648, -2147483648, -2147483648)
    // and (2147483647, 2147483647, 2147483647).
    accessor.setValue(openvdb::Coord::min(), 3.0f);
    accessor.setValue(openvdb::Coord::max(), 4.0f);
    std::cout << "Testing sequential access:" << std::endl;
    // Print all active ("on") voxels by means of an iterator.
    for (openvdb::FloatGrid::ValueOnCIter iter = grid->cbeginValueOn(); iter; ++iter) {
        std::cout << "Grid" << iter.getCoord() << " = " << *iter << std::endl;
    }
}

仅供参考,我已经使用OpenVDB论坛中Rama的指南构建了openvdb.lib文件。 但是,当我尝试构建如下的hello world示例时,它抱怨链接器错误。 我已经包含了include目录以及库目录,甚至指定了#pragma注释以包含openvdb.lib。

仅供参考,内置的OpenVDB库是从VS2010构建的静态库。

因此,我可以知道可能出了什么问题或者我使用它的方式有问题吗?

根据网站,您需要在项目中包括以下文件(将它们添加到项目选项/链接器/输入中)

glew32d.lib
glu32.lib
opengl32.lib
GLFW.lib
zlibstat.lib
Half.lib

看来您还需要更改另一个选项:

Add /FORCE:MULTIPLE to the command line linker options under Linker > Command Line

这应该是编译测试项目的正确设置。

为了确保运行库选项(/ MT或/ MD)在您的库中是一致的。

顶部的代码不需要glew32d.lib,glu32.lib,opengl32.lib和GLFW.lib。 仅当有人正在编译单独的查看器应用程序时,才需要使用它们。 该代码示例创建一个网格容器,将值写入其中,然后将其读回。

这是人与代码有问题,似乎工作在某些系统上而不是其他。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM