0

I am trying to compile a CUDA 5.5 application on nsight with ubuntu 12.04

At first I was getting an issue about missing header files such as #include <helper_cuda_drvapi.h>

To fix this I added the path /usr/include/samples/common/inc to my includes list.

This solved the missing header file issue but caused a new issue.

when trying to compile the program on nsight I get the following errors

/usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:278: undefined reference to cuInit' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:279: undefined reference tocuDeviceGetCount' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:290: undefined reference to cuDeviceGetName' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:291: undefined reference tocuDeviceComputeCapability' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:294: undefined reference to cuDeviceGetAttribute' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:327: undefined reference tocuDeviceGetAttribute' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:330: undefined reference to cuDeviceGetAttribute' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:333: undefined reference tocuDeviceComputeCapability' /usr/local/cuda-5.5/samples/common/inc/helper_cuda_drvapi.h:336: undefined reference to `cuDeviceGetAttribute'

any suggestions?

Thanks in advance

*****************UPDATE************

What it basically comes down to is I am trying to compile the "CUDA Video Decoder GL API" sample program on linux and it is not working because of some error with the header files. Does anyone know why this is?

UPDATE

enter image description here

enter image description here

enter image description here

enter image description here

  • 1
    Try including `cuda.h` and `cuda_runtime.h` before `helper_cuda_drvapi.h`. – Roger Dahl Nov 02 '13 at 02:07
  • I saw that was how they fixed it with nvcc but I didn't think there was a way to set what gets compiled first with nsight –  Nov 03 '13 at 19:04
  • @RogerDahl I believe your comment is correct. The OP obviously doesn't understand it, nor the difference between nsight EE and nvcc. Could you expand your comment into an answer? I would upvote it. – Robert Crovella Nov 04 '13 at 04:26
  • @RobertCrovella, in [this answer](http://stackoverflow.com/questions/6302695/difference-between-cuda-h-cuda-runtime-h-cuda-runtime-api-h), @talonmies mentions that nvcc automatically includes the required headers. I guess `helper_cuda_drvapi.h`, being part of the sample framework, is intended for use only from `.cu` files and so doesn't include cuda.h itself? – Roger Dahl Nov 04 '13 at 05:31

2 Answers2

1

The undefined references are to CUDA driver API methods. helper_cuda_drvapi.h has the following comment near the top:

Helper functions for CUDA Driver API error handling (make sure that CUDA_H is included in your projects)

So, in your .cu and .cpp files, before the #include <helper_cuda_drvapi.h>, include cuda.h:

#include "cuda.h"
#include <helper_cuda_drvapi.h>

See this question for more information about the CUDA headers.

Community
  • 1
  • 1
Roger Dahl
  • 15,132
  • 8
  • 62
  • 82
  • I have done this and yet I am still getting the same error when I compile the program in nsight –  Nov 04 '13 at 17:48
1

You need to manually link with libcuda (Nsight projects use Runtime API)

To link with this library:

  1. Go to Properties for your project, open General / Path and Symbols
  2. On the Libraries tab add cuda (without prefix or suffix - in theory should make your project more clossplatform. You may also want to check "Add to all configurations" when adding the library - otherwise it will be for your current build configuration (e.g. "Debug" or "Release" only).

Update: Project settings screenshot: enter image description here

Eugene
  • 9,242
  • 2
  • 30
  • 29
  • I have done this as well, I am starting to think in the end it is that it ran on windows because of DirectX but it does not work on Linux because it does not support DirectX –  Nov 04 '13 at 22:50
  • I tested it on Linux. Just to be sure - I both added `#include ` as Roger suggested and added `-lcuda` linker flag. – Eugene Nov 04 '13 at 23:10
  • Wait you got "CUDA Video Decoder GL API" to run on linux if so please let me know the exact commands you used to make it work –  Nov 04 '13 at 23:22
  • No, I only included that header, reproduced error messages - and then fixed the compilation issues. – Eugene Nov 04 '13 at 23:57
  • Can you paste the whole nvcc invocation from the console view? – Eugene Nov 05 '13 at 00:51
  • You do not link against libcuda. Please see the project settings screenshot I added to my answer for details. – Eugene Nov 05 '13 at 21:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/40600/discussion-between-user2719805-and-eugene) –  Nov 06 '13 at 00:15