Link Error when using "half"

Delio Vicini <[email protected]> Wed, 25 Feb 2015 11:10:37 +0100
Newsgroups gmane.comp.video.openexr.devel
Message-ID <[email protected]>
Hi,

I am new to using OpenEXR and tried to get it to build for Windows x64 
with Visual Studio 2013. I managed to compile it using the source from 
the homepage (or the sidefx branch from github: 
https://github.com/sideeffects/openexr, both give the same error in the 
end). I tried using the generated lib/dll/include files in my project, 
but end up with a linker error when using the "half" data type.

Some part of the OpenEXR library seems to work, I can successfully read 
out filesize etc. and I guess the content of the file is loaded into 
memory. But I can't parse the data, because when casting "half" to float 
I get a linker error. My code is as follows (more or less copied from 
PBRT framework for now). If I comment out the three lines where the data 
is actually read, the code compiles and can successfully print out the 
image size (see the printf statement). The exact linker error message is:

1>main.obj : error LNK2001: unresolved external symbol "private: static 
union half::uif const * const half::_toFloat" (?_toFloat@half@@0QBTuif@1@B)
1>..\..\bin\Release\x64\OpenEXRExample.exe : fatal error LNK1120: 1 
unresolved externals

I assume that maybe my OpenEXR build has some issues, because I included 
all the libs/headers (including Half.lib etc.) as usual into my project. 
Does maybe someone have working Open EXR 64bit lib and dll files for 
Visual Studio 2013? Or any other ideas what I am doing wrong?

Thanks for your help!

Cheers,
Delio


Code:
Snippet

// EXR Function Definitions
Halide::Image<float> ReadImageEXR(const  string  &name,int  *width,int  *height)
{
	try  {
		InputFile  file(name.c_str());
		Box2i  dw = file.header().dataWindow();
		*width  = dw.max.x - dw.min.x + 1;
		*height  = dw.max.y - dw.min.y + 1;


		half  *rgb =new  half[3 * *width  * *height];

		FrameBuffer  frameBuffer;
		frameBuffer.insert("R",Slice(HALF, (char  *)rgb, 3 *sizeof(half), *width  * 3 *sizeof(half), 1, 1, 0.0));
		frameBuffer.insert("G",Slice(HALF, (char  *)rgb +sizeof(half), 3 *sizeof(half), *width  * 3 *sizeof(half), 1, 1, 0.0));
		frameBuffer.insert("B",Slice(HALF, (char  *)rgb + 2 *sizeof(half),	3 *sizeof(half), *width  * 3 *sizeof(half), 1, 1, 0.0));

		file.setFrameBuffer(frameBuffer);
		file.readPixels(dw.min.y, dw.max.y);

		
		Halide::Image<float> im = Halide::Image<float>(*width, *height, 3);
		float  *ptr = (float*) im.data();

		for  (int  i = 0; i < *width  * *height; ++i) {
			ptr[3 * i] = rgb[3 * i]; // <- these lines are the ones causing the build error.
			ptr[3 * i + 1] = rgb[3 * i + 1];
			ptr[3 * i + 2] = rgb[3 * i + 2];
		}
		delete[] rgb;
		printf("Read EXR image %s (%d x %d)\n",name.c_str(), *width, *height);
		im.set_host_dirty();
		return  im;
		//return Halide::Image<float>();

	}catch  (const  std::exception  &e) {
		printf("Unable to read image file \"%s\": %s",name.c_str(),
			e.what());
		return  Halide::Image<float>();
	}
}

_______________________________________________
Openexr-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/openexr-devel