0

I faced a problem trying to create static wrapper for some of NPP icc functions, to call them from cGo (Golang) environment.

I'm able to create and compile (C language) executable, with provided static NPP libraries, and it works well. Then I compile it as a library (with necessary flags). But when I try to link that library from another executable (plain C or cGo), I get error message "undefined reference to nppiYCbCr420ToRGB_8u_P3C3R". What I'm doing wrong?

wrapper.c

#include <nppi_color_conversion.h>
#include <cuda_runtime_api.h>

int YCbCr420ToRGB() {
  NppiSize oSizeROI;

  const Npp8u * const pSrc[3];
  int cSrcStep[3];
  Npp8u *cDst;

  NppStatus ret = nppiYCbCr420ToRGB_8u_P3C3R(pSrc, cSrcStep, cDst, 0, oSizeROI);

  return (int)ret; // ret = 14
}

build.sh

nvcc nppGo.c -lib -lnppicc_static -lnppc_static -lculibos -lcudart_static -lpthread -ldl -lrt -I /usr/local/cuda-10.0/include -L /usr/local/cuda-10.0/lib64 -o libnppGo

caller.c

#include <stdio.h>
#include "nppGo.h"

int main() {

  int ret = YCbCr420ToRGB();
  printf("Return code is: %d\n", ret);

return (int)ret;
}

buildtest.sh

nvcc caller.c -L. -lnppGo -o nppGo

Finally I get this error message

./libnppGo.a(tmpxft_0000204d_00000000-2_nppGo.o): In function `YCbCr420ToRGB':
nppGo.c:(.text+0xf9): undefined reference to `nppiYCbCr420ToRGB_8u_P3C3R'
collect2: error: ld returned 1 exit status

I also tried to use another linker/compiler, with same results:

g++ -c nppGo.c -I /usr/local/cuda-10.0/include
ar rcs nppGo.a nppGo.o libnppicc_static.a libnppc_static.a libculibos.a libcudart_static.a libdl.a

1 Answers1

0

following command to merge static libs may not work properly.

ar rcs nppGo.a nppGo.o libnppicc_static.a libnppc_static.a libculibos.a libcudart_static.a libdl.a

Instead use an MRI script to merge these static libs. Like to create nppGo.a use following script, let's name it LibnppGo.mri

Before that , we need to create a temp static lib for nppGo.o.

ar rcs nppGo_temp.a nppGo.o

And LibnppGo.mri will look like:

create nppGo.a
addlib nppGo_temp.a
addlib libnppicc_static.a
addlib libnppc_static.a
addlib libculibos.a 
addlib libcudart_static.a
addlib libdl.a
save
end

And execute ar as:

ar -M <LibnppGo.mri

And you should get a correct final static lib, which you can link properly.

g-217
  • 2,069
  • 18
  • 33
  • Thanks gjha. I finally decided to not use C wrapper, I now call NPP functions from Golang directly, using cGo methods. – Eugene FILIN Feb 15 '19 at 13:13