C++ 从OpenVDB编译Hello World示例

C++ 从OpenVDB编译Hello World示例,c++,visual-c++,visual-studio-2010,C++,Visual C++,Visual Studio 2010,我遇到了以下一些问题: 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(dllimpo

我遇到了以下一些问题:

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)
错误LNK2001:未解析的外部符号“\uu declspec(dllimport)const openvdb::v3\u 0\u 0::tree::TreeBase::`vftable'”(\uu imp_7TreeBase@tree@v3_0_0@openvdb@@6B@)
1> main.obj:错误LNK2001:未解析的外部符号“\uu declspec(dllimport)public:bool\uu cdecl openvdb::v3\u 0\u 0::GridBase::saveFloatAsHalf(void)const”(\uu imp??saveFloatAsHalf@GridBase@v3_0_0@openvdb@@QEBA_NXZ)
1> main.obj:错误LNK2001:未解析的外部符号“\uu declspec(dllimport)int\uu cdecl openvdb::v3\u 0\u 0::util::printBytes(类std::basic\u ostream&,无符号\uu int64,类std::basic\u string const&,类std::basic\u string const&,bool,int,int)”(uu_uimp_u)?printBytes@util@v3_0_0@openvdb@@YAHAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@@U KAEBV?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@5@2_NHH@Z)
1> main.obj:错误LNK2001:未解析的外部符号“\uu declspec(dllimport)public:static bool\uu cdecl openvdb::v3\u 0\u 0::Metadata::isRegisteredType(类std::basic\u string const&”)(\uu imp?isRegisteredType@Metadata@v3_0_0@openvdb@@SA_NAEBV?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@@std@@@Z)
1> main.obj:错误LNK2001:未解析的外部符号“\u declspec(dllimport)public:静态类boost::shared\u ptr\uu cdecl openvdb::v3\u 0\u 0::Metadata::createMetadata(类std::basic\u string const&)”(uu_uimp_u)?createMetadata@Metadata@v3_0_0@openvdb@@SA?AV?$共享_ptr@VMetadata@v3_0_0@openvdb@@@boost@@AEBV?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@@std@@@Z)
1> main.obj:错误LNK2001:未解析的外部符号“\u declspec(dllimport)public:void\u cdecl openvdb::v3\u 0\u 0::math::Transform::print(类std::basic\u ostream&,类std::basic\u string const&)const”(uu_uimp_u)?print@Transform@math@v3_0_0@openvdb@@QEBAXEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@6@@Z)
1> main.obj:错误LNK2001:未解析的外部符号“\uu declspec(dllimport)void\uu cdecl openvdb::v3\u 0\u 0::initialize(void)”(\uu 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;
    }
}
#包括
#包括
#pragma注释(lib,“openvdb.lib”)
int main()
{
//初始化OpenVDB库。必须至少调用该库
//每个程序一次,可以安全地调用多次。
openvdb::initialize();
//创建背景值为0的空浮点网格。
openvdb::FloatGrid::Ptr grid=openvdb::FloatGrid::create();
std::cout根据网站,您需要在项目中包括以下文件(将它们添加到项目选项/链接器/输入中)

那么您似乎还需要更改另一个选项:

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

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

以确保运行时库选项(/MT或/MD)在libs中保持一致。

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


这是人们在代码方面遇到的一个问题,似乎在某些系统上工作,但在其他系统上不工作。

链接器错误意味着您忘记链接库,因此链接器找不到运行库函数的代码。您可以转到项目选项,然后转到链接器/输入,并在库中添加库文件folder@meneldal嗨,我有很多ady在include和其他库目录中添加了这些lib和header文件夹。如果您确实将所需的lib添加到链接器中,可能是因为lib的编译不正确,跳过了一些函数。@meneldal,其他lib编译得很好,因为它们是openvdb编译之前的先决条件iled。因此,我很确定先决条件库没有任何问题。但是,错误似乎只是在openvdb.lib中出现。感谢系统找不到的符号显然来自openvdb.lib。您确定您将其放入了include路径并且链接良好吗?您好,我已将所需的库添加到当前项目中。但是,我可以知道你所说的
Add/FORCE:MULTIPLE to the command line linker options(多个到命令行链接器选项)是什么意思吗?
链接器选项中还有“command line”选项。您可以添加将转到链接器的选项。如果没有它,它可能会工作,这是我第一次听说这个选项,甚至在使用Visual Studio和许多库之后。我已经尝试将
\FORCE:MULTIPLE
添加到命令行,但结果仍然相同。我可以知道关于\uu dec的问题是什么吗lspec(dllimport)?基本上,这是您给dll中的项(您可以从外部访问的内容)提供的链接。您可能在构建库时使用了错误的选项,因为您希望生成静态库。您好,仅供参考,我已验证我已使用/MDWelcome to Stack Overflow构建了所有这些库。理想情况下,答案不仅会指出代码中的问题,而且会提供解决问题的解决方案或建议方法。如果您不能i don’我不能帮助用户或不确定,通常人们只是对原始问题留下评论。嗨,谢谢你的回答,但我已经设法解决了,是的,hello并不真的需要glew库,因为它没有使用任何查看器来查看openvdb网格。然而,进行此编译的方法实际上是更改预处理器,如s链接。谢谢
Add /FORCE:MULTIPLE to the command line linker options under Linker > Command Line