# Problem compiling Cuda source code

**URL:** <https://forums.developer.nvidia.com/t/problem-compiling-cuda-source-code/26712>\
**Category:** CUDA Programming and Performance\
**Created:** [May 22, 2012, 9:01am UTC](https://forums.developer.nvidia.com/t/problem-compiling-cuda-source-code/26712 "2012-05-22T09:01:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elrachal](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Elrachal](https://forums.developer.nvidia.com/u/Elrachal)\
**Post date:** [May 22, 2012, 9:01am UTC](https://forums.developer.nvidia.com/t/problem-compiling-cuda-source-code/26712/1 "2012-05-22T09:01:21Z")

</div>

Hi everyone,

I’m a beginner and didn’t get how to compile Cuda:  
I’m using the following code in a file named main.c:

#include \<stdio.h\>  
#include \<stdlib.h\>

/\*  
\*  
\*/

**global** void kernel(void)  
{

}

int main(int argc, char\*\* argv)  
{  
kernel\<\<\<1,1\>\>\>();  
printf(“Hello World\n”);

```
return (EXIT_SUCCESS);

```

}

With nvcc main.c I’ve got the following error :

main.c:15: error: expected â€˜=â€™, â€˜,â€™, â€˜;â€™, â€˜asmâ€™ or â€˜\_\_attribute\_\_â€™ before â€˜voidâ€™  
main.c: In function â€˜mainâ€™:  
main.c:24: error: â€˜kernelâ€™ undeclared (first use in this function)  
main.c:24: error: (Each undeclared identifier is reported only once  
main.c:24: error: for each function it appears in.)  
main.c:24: error: expected expression before â€˜\<â€™ token

I know that it seems to be simple, but I really have trouble to understand how to build and run it.

I thank you beforehand for your advice.

Elrachal

---

<div class="post-metadata">

**Author:** ![Gilles\_C](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Gilles\_C](https://forums.developer.nvidia.com/u/Gilles_C)\
**Post date:** [May 22, 2012, 9:15am UTC](https://forums.developer.nvidia.com/t/problem-compiling-cuda-source-code/26712/2 "2012-05-22T09:15:33Z")

</div>

Hi,  
Cuda sources are expected to have a “.cu” extension.

---

<div class="post-metadata">

**Author:** ![Elrachal](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Elrachal](https://forums.developer.nvidia.com/u/Elrachal)\
**Post date:** [May 22, 2012, 9:27am UTC](https://forums.developer.nvidia.com/t/problem-compiling-cuda-source-code/26712/3 "2012-05-22T09:27:24Z")

</div>

Hi

Thank you for your help, the a.out file has been created.

Unfortunately, by doing ./a.out, the following message appears : ./a.out: error while loading shared libraries: libcudart.so.4: cannot open shared object file: No such file or directory

Do you have any Idea about solving this?

Cheers,

Elrachal

PS : libcudart.so exists and is located on /opt/cuda/lib/

---

<div class="post-metadata">

**Author:** ![Gilles\_C](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Gilles\_C](https://forums.developer.nvidia.com/u/Gilles_C)\
**Post date:** [May 22, 2012, 9:53am UTC](https://forums.developer.nvidia.com/t/problem-compiling-cuda-source-code/26712/4 "2012-05-22T09:53:47Z")

</div>

```auto
export LD_LIBRARY_PATH=/opt/cuda/lib:$LD_LIBRARY_PATH

```

---

<div class="post-metadata">

**Author:** ![Elrachal](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Elrachal](https://forums.developer.nvidia.com/u/Elrachal)\
**Post date:** [May 22, 2012, 10:41am UTC](https://forums.developer.nvidia.com/t/problem-compiling-cuda-source-code/26712/5 "2012-05-22T10:41:11Z")

</div>

it works.

Thank you !!
