Ubuntu16.04下使用NPP库编译程序时出现nppiMalloc_8u_C1未定义引用错误
Hey there, let's sort out that frustrating undefined reference error you're hitting with functions like nppiMalloc_8u_C1 when compiling with nvcc.
The Root Cause
Your current command uses -L to tell nvcc where to look for libraries, but you haven't actually specified which NPP libraries to link against. The compiler knows the path to the libraries, but it doesn't know which ones contain the functions your code uses—hence the "undefined reference" messages.
The Solution
You need to add -l flags for the specific NPP libraries that include the functions you're calling. For nppiMalloc_8u_C1, this function lives in the nppig library (NPP Image Geometry module). Here's the corrected compile command:
nvcc -L/home/usr/local/cuda-9.0/targets/x86_64-linux/lib -lnppig -lnppc main.cu
A quick breakdown of the flags:
-L: Specifies the directory where nvcc should search for library files (you already had this right)-lnppig: Links against thelibnppig.solibrary (nvcc automatically adds thelibprefix and.sosuffix)-lnppc: Links against the core NPP library, which is often a dependency for other NPP modules
Extra Tips
- If your code uses other NPP functions (like image filtering, arithmetic operations, etc.), you'll need to add the corresponding library flags. For example:
- Image arithmetic:
-lnppial - Image filtering:
-lnppif - Color conversion:
-lnppicc
- Image arithmetic:
- To confirm which library contains a specific function, use this command (replace the library path and function name as needed):
This will show you if the function exists in that library.nm -D /home/usr/local/cuda-9.0/targets/x86_64-linux/lib/libnppig.so | grep nppiMalloc
内容的提问来源于stack exchange,提问作者Tuğrul Görgülü

