我正在尝试创建一个函数来使用 openimageio 轻松写出 exr 图像文件。每当我编译我的测试程序时,我都会收到以下错误。
架构 x86_64 的未定义符号:“OpenImageIO_v2_1::ImageOutput::create(std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&)”,引用自: libvol.a(OIIOFiles.o) 中的 writeOIIOImage(std::__cxx11::basic_string, std::allocator >, Image&, float, float) writeDeepImage(std::map, std::allocator >, Image*, std::更少,std::allocator > >,std::allocator,std::allocator > const,Image*> > >&,char const*) in libvol.a(OIIOFiles.o) ld:找不到符号架构 x86_64
我真的不确定我做错了什么。任何提示将不胜感激。
编译器命令行是:
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
供参考的是我的 OIIOFiles 的 cpp 文件
#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;
}