1

I'm trying to create a function to easily write out exr image files using openimageio. Whenever I compile my test program though I get the following error.

Undefined symbols for architecture x86_64: "OpenImageIO_v2_1::ImageOutput::create(std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&)", referenced from: writeOIIOImage(std::__cxx11::basic_string, std::allocator >, Image&, float, float) in libvol.a(OIIOFiles.o) writeDeepImage(std::map, std::allocator >, Image*, std::less, std::allocator > >, std::allocator, std::allocator > const, Image*> > >&, char const*) in libvol.a(OIIOFiles.o) ld: symbol(s) not found for architecture x86_64

I'm really not sure what I could be doing wrong. Any tips would be appreciated.

Compiler command line is:

g++ -Wall -std=c++11 -g -fPIC -fopenmp -O2 -msse3 -mfpmath=sse
  -D__REVISION__= exec/BasicSphereTest.C
  -I./include/ -I/usr/local/opt/openimageio/include -I/usr/include/python2.6
  -I/usr/local/lib/python2.6/config -I/opt/local/include -I/usr/local/opt/ilmbase/include
  -L./lib -lvol
  /usr/local/opt/openimageio/lib/libOpenImageIO.dylib -ldl -o bin/BasicSphereTest

For reference here is my cpp file for OIIOFiles

#include "OIIOFiles.h"

#include <iostream>
#include <cmath>
#include <OpenImageIO/imageio.h> 
#include <list>
#include <ctime>

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

using namespace std;
OIIO_NAMESPACE_USING


float imagePlaneValue( float v, float dG, float dB )
{
   if( v == 0.0 ){ return 0.0; }
   return pow(v, dG) * dB;
}


void writeOIIOImage( const string fname, Image& img, float displayBrightness, float displayGamma  )
{
   float* imagedata = new float[ img.Width()* img.Height() * 3 ];
   // fill image with the contents of img

   long index = 0;
   for( int j=0;j<img.Height();j++ )
   {
      for( int i=0;i<img.Width();i++ )
      {
         vector<float> pix = img.pixel(i,img.Height() - j - 1);
     for( size_t c=0;c<3;c++ )
         {
            pix[c] = imagePlaneValue( pix[c], displayGamma, displayBrightness );
        imagedata[index++] = pix[c];
         }
      }
   }
   auto out = ImageOutput::create (fname); 
   if( !out )
   {
      cout << "Not able to write an image to file " << fname << endl;
   }
   else
   {
      ImageSpec spec (img.Width(), img.Height(), 3, TypeDesc::HALF);
      spec.attribute("user", "ash");
      spec.attribute("writer", "OIIOFiles" );
      out->open (fname, spec);
      out->write_image (TypeDesc::FLOAT, imagedata);
      out->close ();
   }
   delete[] imagedata;

   cout <<"Image "<<fname<<" written."<<endl;
}



void writeDeepImage(map<string, Image *> &images, const char *filename)
{
    auto out = ImageOutput::create(filename);
    if (!out)
    {
        cout << "Not able to write images to file ";
        cout << filename << endl;
        return;
    }

    if (strcmp(out->format_name(), "openexr") != 0)
    {
        cout << "DeepImage format should be OpenEXR" << endl;
        cout << "Format provided: ";
        cout << out->format_name() << endl;
        return;
    }

    int num_channels = images.size();
    map<string, Image *>::iterator it;
    int width = images.begin()->second->Width();
    int height = images.begin()->second->Height();
    ImageSpec spec(width, height, num_channels, TypeDesc::HALF);
    float *imagedata = new float[width * height * num_channels];
    long long index = 0;
    spec.channelnames.clear();
    int cur_channel = 0;
    for (it = images.begin(); it != images.end(); it++)
    {
        index = 0;
        string fname = it->first;
        Image *img = it->second;
        spec.channelnames.push_back(fname);
        for (int j = 0; j < height; ++j)
        {
            for (int i = 0; i < width; ++i)
            {
                vector<float> pix = img->pixel(i, height - j - 1);
                /* Last two arguments should be displayGamma
                   and displayBrightness.  Ask about adding
                   in optional map of filename to gamma and
                   filename to brightness for unique values.
                */
                pix[0] = imagePlaneValue(pix[0], 1.0, 1.0);
                long long ind = num_channels * index;
                ind += cur_channel;
                imagedata[ind] = pix[0];
                index++;
            }
        }
        cur_channel += 1;
    } // loop over images
    spec.attribute("user", "ash");
    spec.attribute("writer", "OIIOFiles");
    out->open(filename, spec, ImageOutput::Create);
    out->write_image(TypeDesc::FLOAT, imagedata);
    out->close();

    delete imagedata;
}
Useless
  • 64,155
  • 6
  • 88
  • 132
  • Odds are really, really good you're just missing a `-l` or two on the command line. Could you add the command line to the question? – user4581301 Jan 04 '20 at 23:53
  • here it is. `g++ -Wall -std=c++11 -g -fPIC -fopenmp -O2 -msse3 -mfpmath=sse -D__REVISION__= exec/BasicSphereTest.C -I./include/ -I/usr/local/opt/openimageio/include -I/usr/include/python2.6 -I/usr/local/lib/python2.6/config -I/opt/local/include -I/usr/local/opt/ilmbase/include -L./lib -lvol /usr/local/opt/openimageio/lib/libOpenImageIO.dylib -ldl -o bin/BasicSphereTest` – Robert Kern Jan 05 '20 at 00:03
  • You have in include path for OIIO headers (`-I/usr/local/opt/openimageio/include`), but no matching library path (`-L`) and no library at all (`-l`). Are you supposed to link a library that would provide those undefined symbols? – Useless Jan 05 '20 at 00:14
  • Is that not what /usr/local/opt/openimageio/lib/libOpenImageIO.dylib is? – Robert Kern Jan 05 '20 at 00:22
  • @RobertKern Too many unknown things here: What is your Operating System? Is the OIIO library you got a X86_64 version? And I've found "cpython" word in the OIIO library. I recommend you to ask your question to the Github repository of OIIO: [link](https://github.com/OpenImageIO/oiio), and then you can let us know how things go. – wangkaibule Jan 05 '20 at 01:19
  • I'm using macOS 10.15.2. I installed OIIO via homebrew and had it built from the sourcecode on my machine so it should be built for my architecture I think. I can try asking there as well. – Robert Kern Jan 05 '20 at 01:23
  • I'm not getting any sort of response from the developers. Anyone else here have any suggestions? Is there any more info I can provide that would be useful? – Robert Kern Jan 12 '20 at 00:37
  • Is it possible that you have two OIIO installations? That you are including headers from one, and linking another, so the reason it's not finding the symbol when you link is basically that the versioned namespaces don't match? Just a guess, there's not enough information here to tell. – Larry Gritz Aug 07 '20 at 06:46

0 Answers0