Possible NPP bug in 'npp::operator<<' overloading


I have a C++ script (called main_script.cpp) that calls two classes (called class1.cpp/h and class2.cpp/h) which both include <npp.h>.

While compiling my program, I encounter the following error:

class2.o: In function `npp::operator<<(std::ostream&, npp::Exception const&)':
tmpxft_000002fb_00000000-5_class2.compute_61.cudafe1.cpp:(.text+0x10): multiple definition of `npp::operator<<(std::ostream&, npp::Exception const&)'
class1.o:tmpxft_000002d2_00000000-5_class1.compute_61.cudafe1.cpp:(.text+0x10): first defined here
collect2: error: ld returned 1 exit status
Makefile:107: recipe for target 'main_script' failed

Googling this error lead me to the concept of #include guards. I am using include guards in all my header files, which leads me to the belief that in the NPP code, the overloading of the operator<< is not coded properly.

Here are some suggestions I found online to fix the problem:

  • declaring the operator in the header file and moving the implementation to the .cpp file
  • define the operator implementation inside the class definition
  • inline the operator implementation

Perhaps my assumptions are all wrong and the problem is in my code, but in either case, I’d like to get your opinion! :)

By the way, if I change my code to only include 1 class (not 2), then this error doesn’t appear and my code runs smoothly.

I would suggest providing a short, complete code demonstrating the issue, along with the compile command line, and the CUDA version you are using.

Hi Robert, thanks for the quick reply.

I created a small repo demonstrating the issue: https://github.com/zanbri/NppOperatorBug

In it, you’ll find a Makefile, so simply enter make and the error should appear during compilation.

Note: The code in class1 and class2 are identical – both are included as they are needed to reproduce the error.

I’m running Cuda release 10.0, V10.0.130 .

I just made a simplified version and pushed it to the same git (https://github.com/zanbri/NppOperatorBug). There is no actual code, just includes, and it causes the same problem.

The problem seems to arise when both #include <npp.h> AND #include <Exceptions.h> are called in both class1 and class 2 scripts.

So I think I found the exact problem. In the script ‘/usr/local/cuda-10.0/samples/7_CUDALibraries/common/UtilNPP/Exceptions.h’, on line 116, I changed the code from:

116     std::ostream &                                                                           
117     operator << (std::ostream &rOutputStream, const Exception &rException)                          
118     {                                                                                               
119         rOutputStream << rException.toString();                                                     
120         return rOutputStream;                                                                       
121     }

to this:

116     inline std::ostream &                                                                           
117     operator << (std::ostream &rOutputStream, const Exception &rException)                          
118     {                                                                                               
119         rOutputStream << rException.toString();                                                     
120         return rOutputStream;                                                                       
121     }

And that fixed my problem.

It would be helpful if you file a bug at developer.nvidia.com

The general bug filing description is here:


It should be sufficient to just provide a link to this forum thread.