building helloworld example..

1,414 views
Skip to first unread message

bhavesh pandey

unread,
Aug 17, 2012, 5:08:35 PM8/17/12
to openvd...@googlegroups.com
Hi, I'm trying to build and run a very simple program which has few lines from the cookbook examples.
When I try to build it, I get a bunch of errors and I'm not sure why thats happening. 

Following is the code:

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


int main(){

openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create();

std::cout<<"Testing Random Access: "<<std::endl;

openvdb::FloatGrid::Accessor accessor = grid->getAccessor();

openvdb::Coord xyz(1000, -20000, 300000);

accessor.setValue(xyz, 1.0);

std::cout<<"Grid"<< xyz << "=" << accessor.getValue(xyz) << std::endl;


return 0;
}


Following are the errors I'm getting:

22:00:45 **** Incremental Build of configuration Debug for project helloWorld ****
make all 
Building target: helloWorld
Invoking: GCC C++ Linker
g++ -L/usr/lib -o "helloWorld"  ./helloWorld.o   -l/usr/local/lib/libopenvdb.so
/usr/include/OpenEXR/half.h:481: error: undefined reference to 'half::_eLut'
/usr/include/OpenEXR/half.h:499: error: undefined reference to 'half::convert(int)'
/usr/include/OpenEXR/half.h:512: error: undefined reference to 'half::_toFloat'
/usr/include/tbb/spin_rw_mutex.h:112: error: undefined reference to 'tbb::spin_rw_mutex_v3::internal_acquire_writer()'
/usr/include/tbb/spin_rw_mutex.h:113: error: undefined reference to 'tbb::spin_rw_mutex_v3::internal_acquire_reader()'
/usr/include/tbb/spin_rw_mutex.h:122: error: undefined reference to 'tbb::spin_rw_mutex_v3::internal_upgrade()'
/usr/include/tbb/spin_rw_mutex.h:159: error: undefined reference to 'tbb::spin_rw_mutex_v3::internal_try_acquire_writer()'
/usr/include/tbb/spin_rw_mutex.h:159: error: undefined reference to 'tbb::spin_rw_mutex_v3::internal_try_acquire_reader()'
/usr/include/tbb/tbb_exception.h:110: error: undefined reference to 'tbb::internal::throw_exception_v4(tbb::internal::exception_id)'
/usr/include/tbb/cache_aligned_allocator.h:88: error: undefined reference to 'tbb::internal::NFS_Allocate(unsigned long, unsigned long, void*)'
/usr/include/tbb/cache_aligned_allocator.h:93: error: undefined reference to 'tbb::internal::NFS_Free(void*)'
/usr/include/tbb/tbb_allocator.h:111: error: undefined reference to 'tbb::internal::deallocate_via_handler_v3(void*)'
/usr/include/tbb/tbb_allocator.h:111: error: undefined reference to 'tbb::internal::deallocate_via_handler_v3(void*)'
/usr/include/tbb/tbb_allocator.h:106: error: undefined reference to 'tbb::internal::allocate_via_handler_v3(unsigned long)'
collect2: ld returned 1 exit status
make: *** [helloWorld] Error 1

22:00:46 Build Finished (took 211ms)

Any guidance would be much appreciated (I suspect it would be something trivial as I'm
not an amazing programmer).

Thanks,
Bhavesh. 

OpenVDB

unread,
Aug 17, 2012, 6:10:05 PM8/17/12
to openvd...@googlegroups.com
You're missing several libraries needing during linking. The easiest fix is to add a new target in the openvdb/Makefile. Simple copy/past everything under "vdb_print" and rename it to "helloWorld" and replace cmd/openvdb_print/main.cc with helloWorld.cpp. That is:

helloWorld: helloWorld.cc $(LIBOPENVDB)
    @echo "Building $@ because of $(call list_deps)"
    $(CXX) $(CXXFLAGS) -o $@ helloWorld.cc -I . \
        $(LIBS_RPATH) $(LIBOPENVDB_RPATH) -L $(PWD) $(LIBOPENVDB)

-Ken

bhavesh pandey

unread,
Aug 17, 2012, 7:04:08 PM8/17/12
to openvd...@googlegroups.com
Thanks Ken that helped a lot.

Out of curiosity, is there a better way to fix this? 
Though your solution worked perfectly and i was able to build it in a separate directory so the 
openvdb root dir doesn't get cluttered.

Thanks,
Bhavesh.

OpenVDB

unread,
Aug 17, 2012, 10:58:05 PM8/17/12
to openvd...@googlegroups.com
Hey Bhavesh,

That's a great idea - I'll make sure in the next release we include a template Makefile you can use for your own projects

Cheers,
Ken

BaiLong

unread,
Jan 28, 2013, 7:40:33 PM1/28/13
to openvd...@googlegroups.com
Hello there,

I hope it's ok to revive this thread, but I had the same issue and would like to ask if there is already a temp Makefile somewhere in the package? Because I didn't find it.

Ken's trick of using the original Makefile and adding the helloWorld part did work for me too, but that always builds all the other parts every time as well. I tried breaking it down, but I only got to the point that at least I have to build libopenvdb.so in the same process. If I try to use my already installed version I get about a few thousand lines of errors like this:
undefined reference to `openvdb::v0_103_1::util::printBytes(std::ostream&, unsigned long, std::string const&, std::string const&, bool, int, int)'

Since the code already compiled I assume there is a very simple fix that I just don't see.

Thanks a lot!
--Markus

Denis

unread,
Mar 8, 2013, 4:41:23 AM3/8/13
to openvd...@googlegroups.com
I am testing the OpenVDB so here the steps I done to compile the helloworld in the VisualStudio 2010

1)
Download openexr ilmbase 1.02
Download tbb41
Download zlib-1.2.7
Download boost 1_53

2)
Create a new console project in VisualStudio 2010
with this main cpp code

//Microsoft Bugs on VC2010
#ifdef _DLL
#undef _DLL
#endif



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


int _tmain(int argc, _TCHAR* argv[])

{


    openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create();

    std::cout<<"Testing Random Access: "<<std::endl;

    openvdb::FloatGrid::Accessor accessor = grid->getAccessor();

    openvdb::Coord xyz(1000, -20000, 300000);

    accessor.setValue(xyz, 1.0);

    std::cout<<"Grid"<< xyz << "=" << accessor.getValue(xyz) << std::endl;

    return 0;
}

these are the other source files

<openvdb/Grid.cc>
<openvdb/io/Archive.cc>
<openvdb/io/Compression.cc>
<openvdb/io/File.cc>
<openvdb/io/GridDescriptor.cc>
<openvdb/io/Stream.cc>
<openvdb/math/Hermite.cc>
<openvdb/math/Maps.cc >
<openvdb/math/Proximity.cc>
<openvdb/math/QuantizedUnitVec.cc >
<openvdb/math/Transform.cc >
<openvdb/metadata/Metadata.cc >
<openvdb/metadata/MetaMap.cc >
<openvdb/Platform.cc >
<openvdb/util/Formats.cc >
<openvdb/util/Util.cc >



3) into the OpenVDB  file types.h I changed the line

#include <OpenEXS/half.h>       

into

#include <Half/half.h>        //Denis 06/03/2012

4) add the define NOMINMAX into the project to avoid incompatibility of min max define

5) add the #undefine _DLL due to the bug of visual studio for console projects

6)
in crtdef.h of Visual Studio insert these lines to solve the problem of console projects

//Denis 07/03/2013
#ifdef _CONSOLE
#undef _DLL
#endif


7) compile the static zlib end add the link to that library

8) add the define ZLIB_WINAPI for the zlib

9) add to the sources the file half.cpp of the ilmbase

10) in platform.h I changed the define of OPENEXR_DLL to allow a static inclusion of half.cpp

// Windows build currently links to the shared Half.dll
#ifdef _WIN32
    //Denis 08/03/2013
    #ifndef _CONSOLE
        #define OPENEXR_DLL 1
    #endif
#endif

11) copy tbb_debug.dll in the debug folder of openvdbhelloworld

I hope this can help who want to make test in windows .
Suggestions
are welcome.

Denis.

Reply all
Reply to author
Forward
0 new messages