从OpenVDB编译Hello World示例

时间:2015-04-28 00:32:37

标签: c++ visual-c++ vs2010-express

我遇到了一些问题如下:

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 comment来包含openvdb.lib。

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

因此,我可以知道可能出现的问题,或者我使用它的方式是错误的吗?

3 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

确保库中的运行时库选项(/ MT或/ MD)一致。

答案 2 :(得分:-1)

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

这是人们对代码的一个问题,似乎在某些系统上工作,但在其他系统上却没有。