The Linux Page

undefined reference to `NvEGLImageFromFd(void*, int)' & `NvDestroyEGLImage(void*, void*)'

Including old code in modern programs

As I'm working on a project that runs on a Jetson Tegra, I ran in this issue:

CMakeFiles/panel_ve.dir/panel_ve.cpp.o: In function `panel_ve::run()':
/home/alexis/ve/virtual-entertainment/panel-ve/src/panel_ve.cpp:383: undefined reference to `NvEGLImageFromFd(void*, int)'
/home/alexis/ve/virtual-entertainment/panel-ve/src/panel_ve.cpp:414: undefined reference to `NvDestroyEGLImage(void*, void*)'

Yet, I linked against the nvbuf_utils library, but apparently it was not happening.

The fact is NVidia offers an nvbuf_utils.h file in their development environment and that's where the functions are defined. On my end, I did not really want to include that file (it's loose if you ask me, they don't install headers in /usr/include so each install could be different...) so I just copied those two function definitions:

EGLImageKHR NvEGLImageFromFd(EGLDisplay display, int dmabuf_fd);
int NvDestroyEGLImage(EGLDisplay display, EGLImageKHR eglImage);

in my own file, the one which uses those them.

Unfortunately, my file is C++ and those functions are defined in good old C... Yep! That was it. I was missing the extern "C" { ... } wrapper.

extern "C" {
EGLImageKHR NvEGLImageFromFd(EGLDisplay display, int dmabuf_fd);
int NvDestroyEGLImage(EGLDisplay display, EGLImageKHR eglImage);
}

For now, though, I decided to include the header among my files so that way other definitions will be readily available. And yes, the linker works too once I had both: the extern "C" and the correct library. Note that the nvbuf_utils.h header has the extern "C" already included.