# Problem compiling simple example

**URL:** <https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654>\
**Category:** CUDA Programming and Performance\
**Created:** [November 9, 2010, 2:40pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654 "2010-11-09T14:40:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ferguzz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ferguzz](https://forums.developer.nvidia.com/u/Ferguzz)\
**Post date:** [November 9, 2010, 2:40pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/1 "2010-11-09T14:40:39Z")

</div>

iya,

Just trying to compile some very simple examples on my mac. e.g.

#include \<stdio.h\>

**global** void foo()  
{  
}

int main()  
{  
Â foo\<\<\<1,1\>\>\>();  
Â printf(“CUDA error: %s\n”, cudaGetErrorString(cudaGetLastError())); Â  
Â return 0;  
}

But the nvcc compiler throws up errors like:

test.cu(9): error: expected an expression

test.cu(9): error: unrecognized token

test.cu(10): error: unrecognized token

test.cu(10): error: expected an expression

when I run nvcc --version i get :

nvcc: NVIDIA Â® Cuda compiler driver  
Copyright Â© 2005-2009 NVIDIA Corporation  
Built on Thu\_Mar\_11\_12:08:00\_PST\_2010  
Cuda compilation tools, release 3.0, V0.2.1221

Seems like it’s working fine. I can also run all the example programs provided with the CUDA SDK.

What’s my problem?

Tom

---

<div class="post-metadata">

**Author:** ![Ferguzz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ferguzz](https://forums.developer.nvidia.com/u/Ferguzz)\
**Post date:** [November 9, 2010, 2:40pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/2 "2010-11-09T14:40:39Z")

</div>

iya,

Just trying to compile some very simple examples on my mac. e.g.

#include \<stdio.h\>

**global** void foo()  
{  
}

int main()  
{  
Â foo\<\<\<1,1\>\>\>();  
Â printf(“CUDA error: %s\n”, cudaGetErrorString(cudaGetLastError())); Â  
Â return 0;  
}

But the nvcc compiler throws up errors like:

test.cu(9): error: expected an expression

test.cu(9): error: unrecognized token

test.cu(10): error: unrecognized token

test.cu(10): error: expected an expression

when I run nvcc --version i get :

nvcc: NVIDIA Â® Cuda compiler driver  
Copyright Â© 2005-2009 NVIDIA Corporation  
Built on Thu\_Mar\_11\_12:08:00\_PST\_2010  
Cuda compilation tools, release 3.0, V0.2.1221

Seems like it’s working fine. I can also run all the example programs provided with the CUDA SDK.

What’s my problem?

Tom

---

<div class="post-metadata">

**Author:** ![tera](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tera](https://forums.developer.nvidia.com/u/tera)\
**Post date:** [November 10, 2010, 8:21pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/3 "2010-11-10T20:21:18Z")

</div>

Can you post the output of [font=“Courier New”]hexdump -C test.cu[/font] ?  
It’s just a shot in the dark, but you may have a problem with special symbols or the character encoding used in the file.

---

<div class="post-metadata">

**Author:** ![tera](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tera](https://forums.developer.nvidia.com/u/tera)\
**Post date:** [November 10, 2010, 8:21pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/4 "2010-11-10T20:21:18Z")

</div>

Can you post the output of [font=“Courier New”]hexdump -C test.cu[/font] ?  
It’s just a shot in the dark, but you may have a problem with special symbols or the character encoding used in the file.

---

<div class="post-metadata">

**Author:** ![Ferguzz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ferguzz](https://forums.developer.nvidia.com/u/Ferguzz)\
**Post date:** [November 11, 2010, 1:03pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/5 "2010-11-11T13:03:08Z")

</div>

00000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e |#include \<stdio.|  
00000010 68 3e 0a 0a 5f 5f 67 6c 6f 62 61 6c 5f 5f 20 76 |h\>… **global** v|  
00000020 6f 69 64 20 66 6f 6f 28 29 0a 7b 0a 7d 0a 0a 69 |oid foo().{.}…i|  
00000030 6e 74 20 6d 61 69 6e 28 29 0a 7b 0a c2 a0 20 66 |nt main().{… f|  
00000040 6f 6f 3c 3c 3c 31 2c 31 3e 3e 3e 28 29 3b 0a c2 |oo\<\<\<1,1\>\>\>();…|  
00000050 a0 20 70 72 69 6e 74 66 28 22 43 55 44 41 20 65 |. printf(“CUDA e|  
00000060 72 72 6f 72 3a 20 25 73 5c 6e 22 2c 20 63 75 64 |rror: %s\n”, cud|  
00000070 61 47 65 74 45 72 72 6f 72 53 74 72 69 6e 67 28 |aGetErrorString(|  
00000080 63 75 64 61 47 65 74 4c 61 73 74 45 72 72 6f 72 |cudaGetLastError|  
00000090 28 29 29 29 3b 20 c2 a0 0a c2 a0 20 72 65 74 75 |())); … retu|  
000000a0 72 6e 20 30 3b 0a 7d |rn 0;.}|  
000000a7

Cheers

---

<div class="post-metadata">

**Author:** ![Ferguzz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ferguzz](https://forums.developer.nvidia.com/u/Ferguzz)\
**Post date:** [November 11, 2010, 1:03pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/6 "2010-11-11T13:03:08Z")

</div>

00000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e |#include \<stdio.|  
00000010 68 3e 0a 0a 5f 5f 67 6c 6f 62 61 6c 5f 5f 20 76 |h\>… **global** v|  
00000020 6f 69 64 20 66 6f 6f 28 29 0a 7b 0a 7d 0a 0a 69 |oid foo().{.}…i|  
00000030 6e 74 20 6d 61 69 6e 28 29 0a 7b 0a c2 a0 20 66 |nt main().{… f|  
00000040 6f 6f 3c 3c 3c 31 2c 31 3e 3e 3e 28 29 3b 0a c2 |oo\<\<\<1,1\>\>\>();…|  
00000050 a0 20 70 72 69 6e 74 66 28 22 43 55 44 41 20 65 |. printf(“CUDA e|  
00000060 72 72 6f 72 3a 20 25 73 5c 6e 22 2c 20 63 75 64 |rror: %s\n”, cud|  
00000070 61 47 65 74 45 72 72 6f 72 53 74 72 69 6e 67 28 |aGetErrorString(|  
00000080 63 75 64 61 47 65 74 4c 61 73 74 45 72 72 6f 72 |cudaGetLastError|  
00000090 28 29 29 29 3b 20 c2 a0 0a c2 a0 20 72 65 74 75 |())); … retu|  
000000a0 72 6e 20 30 3b 0a 7d |rn 0;.}|  
000000a7

Cheers

---

<div class="post-metadata">

**Author:** ![tera](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tera](https://forums.developer.nvidia.com/u/tera)\
**Post date:** [November 11, 2010, 3:57pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/7 "2010-11-11T15:57:46Z")

</div>

> [@](#):
>
> [font=“Courier New”]00000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e |#include \<stdio.|
> 
> 00000010 68 3e 0a 0a 5f 5f 67 6c 6f 62 61 6c 5f 5f 20 76 |h\>… **global** v|
> 
> 00000020 6f 69 64 20 66 6f 6f 28 29 0a 7b 0a 7d 0a 0a 69 |oid foo().{.}…i|
> 
> 00000030 6e 74 20 6d 61 69 6e 28 29 0a 7b 0a **c2 a0** 20 66 |nt main().{… f|
> 
> 00000040 6f 6f 3c 3c 3c 31 2c 31 3e 3e 3e 28 29 3b 0a **c2** |oo\<\<\<1,1\>\>\>();…|
> 
> 00000050 **a0** 20 70 72 69 6e 74 66 28 22 43 55 44 41 20 65 |. printf("CUDA e|
> 
> 00000060 72 72 6f 72 3a 20 25 73 5c 6e 22 2c 20 63 75 64 |rror: %s\n", cud|
> 
> 00000070 61 47 65 74 45 72 72 6f 72 53 74 72 69 6e 67 28 |aGetErrorString(|
> 
> 00000080 63 75 64 61 47 65 74 4c 61 73 74 45 72 72 6f 72 |cudaGetLastError|
> 
> 00000090 28 29 29 29 3b 20 **c2 a0** 0a **c2 a0** 20 72 65 74 75 |())); … retu|
> 
> 000000a0 72 6e 20 30 3b 0a 7d |rn 0;.}|
> 
> 000000a7
> 
> [/font]

You’ve got non-breaking spaces as indentation and as trailing whitespace after the printf() line. I guess the compiler chokes on those. Try deleting and re-inserting the indentation and deleting the trailing space after the printf().

Which editor did you use to create the file?

---

<div class="post-metadata">

**Author:** ![tera](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tera](https://forums.developer.nvidia.com/u/tera)\
**Post date:** [November 11, 2010, 3:57pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/8 "2010-11-11T15:57:46Z")

</div>

> [@](#):
>
> [font=“Courier New”]00000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e |#include \<stdio.|
> 
> 00000010 68 3e 0a 0a 5f 5f 67 6c 6f 62 61 6c 5f 5f 20 76 |h\>… **global** v|
> 
> 00000020 6f 69 64 20 66 6f 6f 28 29 0a 7b 0a 7d 0a 0a 69 |oid foo().{.}…i|
> 
> 00000030 6e 74 20 6d 61 69 6e 28 29 0a 7b 0a **c2 a0** 20 66 |nt main().{… f|
> 
> 00000040 6f 6f 3c 3c 3c 31 2c 31 3e 3e 3e 28 29 3b 0a **c2** |oo\<\<\<1,1\>\>\>();…|
> 
> 00000050 **a0** 20 70 72 69 6e 74 66 28 22 43 55 44 41 20 65 |. printf("CUDA e|
> 
> 00000060 72 72 6f 72 3a 20 25 73 5c 6e 22 2c 20 63 75 64 |rror: %s\n", cud|
> 
> 00000070 61 47 65 74 45 72 72 6f 72 53 74 72 69 6e 67 28 |aGetErrorString(|
> 
> 00000080 63 75 64 61 47 65 74 4c 61 73 74 45 72 72 6f 72 |cudaGetLastError|
> 
> 00000090 28 29 29 29 3b 20 **c2 a0** 0a **c2 a0** 20 72 65 74 75 |())); … retu|
> 
> 000000a0 72 6e 20 30 3b 0a 7d |rn 0;.}|
> 
> 000000a7
> 
> [/font]

You’ve got non-breaking spaces as indentation and as trailing whitespace after the printf() line. I guess the compiler chokes on those. Try deleting and re-inserting the indentation and deleting the trailing space after the printf().

Which editor did you use to create the file?

---

<div class="post-metadata">

**Author:** ![Ferguzz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ferguzz](https://forums.developer.nvidia.com/u/Ferguzz)\
**Post date:** [November 12, 2010, 11:30am UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/9 "2010-11-12T11:30:59Z")

</div>

Fantastic. Worked a treat. I used TextEdit to create the file. Can you suggest a better simple editor for writing C ?

Thanks,

Tom

---

<div class="post-metadata">

**Author:** ![Ferguzz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ferguzz](https://forums.developer.nvidia.com/u/Ferguzz)\
**Post date:** [November 12, 2010, 11:30am UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/10 "2010-11-12T11:30:59Z")

</div>

Fantastic. Worked a treat. I used TextEdit to create the file. Can you suggest a better simple editor for writing C ?

Thanks,

Tom

---

<div class="post-metadata">

**Author:** ![tera](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tera](https://forums.developer.nvidia.com/u/tera)\
**Post date:** [November 12, 2010, 1:28pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/11 "2010-11-12T13:28:30Z")

</div>

Not a simple one. I use Xcode and sometimes vim.

---

<div class="post-metadata">

**Author:** ![tera](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tera](https://forums.developer.nvidia.com/u/tera)\
**Post date:** [November 12, 2010, 1:28pm UTC](https://forums.developer.nvidia.com/t/problem-compiling-simple-example/19654/12 "2010-11-12T13:28:30Z")

</div>

Not a simple one. I use Xcode and sometimes vim.
