-1

I'm trying to experiment with the OpenSubdiv C++ library. I'm not an experienced C++ programmer.

The OpenSubdiv library has some tutorials that I'd like to get working, but I can't figure out how.

So far, I have installed OpenSubD and dependencies (GLFW) to the best of my extremely limited abilities, by doing the following (I'm on Ubuntu, for reference).

sudo apt-get install doxygen # (GLFW Dependency?)
sudo apt-get install xorg-dev # (GLFW Dependency?)
sudo apt-get install libglfw3 # (GLFW Dependency?)
sudo apt-get install libglfw3-dev # (GLFW Dependency?)

git clone git@github.com:PixarAnimationStudios/OpenSubdiv.git
cd OpenSubdiv
mkdir build
cd build 
cmake -D NO_PTEX=1 -D NO_DOC=1 -D NO_OMP=1 -D NO_TBB=1 -D NO_CUDA=1 -D NO_OPENCL=1 -D NO_CLEW=1 -D GLFW_LOCATION="/usr/" ..
cmake --build . --config Release --target install

Note this roughly follows the instructions given in the OpenSubdiv repo README.

The code I am trying to compile is

#include <GLFW/glfw3.h>
#include <opensubdiv/far/topologyDescriptor.h>
#include <opensubdiv/far/primvarRefiner.h>

#include <cstdio>

using namespace OpenSubdiv;

int main(int, char **){
    typedef Far::TopologyDescriptor Descriptor; 
    
    Sdc::SchemeType type = OpenSubdiv::Sdc::SCHEME_CATMARK;

    Sdc::Options options; 

    options.SetVtxBoundaryInterpolation(Sdc::Options::VTX_BOUNDARY_EDGE_ONLY);
    // Compiles fine up to this point. 
    

    Descriptor desc; //Fails here, trying to instantiate a "Descriptor" object, which lives in OpenSubdiv
    desc.numVertices = g_nverts;
    desc.numFaces = g_nfaces;
    desc.numVertsPerFace = g_vertsperface;
    desc.vertIndicesPerFace = g_vertIndices; 
    
    return 0;
}

The error I get is

g++ opensubd_minimal_example.cpp -o opensubd_minimal_example
/usr/bin/ld: /tmp/cc4WQ9jc.o: in function `main':
opensubd_minimal_example.cpp:(.text+0x57): undefined reference to `OpenSubdiv::v3_4_4::Far::TopologyDescriptor::TopologyDescriptor()'
collect2: error: ld returned 1 exit status

I'm guessing that there is some linking that needs to happen that I'm missing, but I don't know what, and I can't figure it out from looking at the cmake files used by OpenSubd, because I don't know how to use cmake.

I could use some guidance. Thanks.

GeneralPancake
  • 535
  • 2
  • 6
  • 15

1 Answers1

1

Please refer to the last section of OpenSubDiv: building with cmake.

The linker needs to know where to find the library to link. Set the OPENSUBDIV variable to the directory of OpenSubDiv, then compile and link your app.

g++ -I$OPENSUBDIV/include -c myapp.cpp
g++ myapp.o -L$OPENSUBDIV/lib -losdGPU -losdCPU -o myapp
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
TonnyRed
  • 36
  • 3
  • That worked, where `$OPENSUBDIV = OpenSubDiv`, which is the OpenSubDiv repo I pulled from Github. What confuses me is that there is no `OpenSubDiv/include` folder? So how is it actually finding the include files? Is there a way of expanding the path that I'm actually passing into the compiler? – GeneralPancake Jun 18 '22 at 21:45
  • The answer to initial question was the linker cannot find the library. You point to the library by `-losdGPU -losdCPU`. Finding headers is a different story. You can try to dump all include paths for angle bracket #include with something like `gcc -v -x c++ -E /dev/null`, where -v is verbose, x c++ - cpp, -E /dev/null - preprocess /dev/null then stop. – TonnyRed Jun 19 '22 at 00:38