Thread: error: 'printf' was not declared in this scope

ankakusu is offlineFirst Cup of Ubuntu

Join Date Oct 2006 Beans 10 --> Beans 10

error: 'printf' was not declared in this scope

I want to try the code below and It is a code with preprocessors. I get an error.

Can anyone can tell me the reason?

#define HATALI(A) A*A*A /* Kup icin hatali makro */ #define KUP(A) (A)*(A)*(A) /* Dogusu . */ #define KARE(A) (A)*(A) /* Karesi icin dogru makro */ #define START 1 #define STOP 9 main() < int i,offset; offset = 5; for (i = START;i >
'printf' was not declared in this scope
June 2nd, 2007 #2

WW is offlineIced Blended Vanilla Cr�me Ubuntu

Join Date Oct 2004 Beans 1,532 --> Beans 1,532

Re: error: 'printf' was not declared in this scope

You forgot
#include June 2nd, 2007 #3

ankakusu is offlineFirst Cup of Ubuntu

Join Date Oct 2006 Beans 10 --> Beans 10

Re: error: 'printf' was not declared in this scope

when included the header file

it returned an error:

studio.h: No such file or directory

I am using gcc compiler. Can this be the reason? June 2nd, 2007 #4

WW is offlineIced Blended Vanilla Cr�me Ubuntu

Join Date Oct 2004 Beans 1,532 --> Beans 1,532

Re: error: 'printf' was not declared in this scope

stdio.h (not studio.h)
June 2nd, 2007 #5

ankakusu is offlineFirst Cup of Ubuntu

Join Date Oct 2006 Beans 10 --> Beans 10

Re: error: 'printf' was not declared in this scope

anyway, the program give a more garbled error.

what does this error mean?

how can I fix the problem?

/tmp/ccGQNcoh.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld output returned 1
June 2nd, 2007 #6

WW is offlineIced Blended Vanilla Cr�me Ubuntu

Join Date Oct 2004 Beans 1,532 --> Beans 1,532

Re: error: 'printf' was not declared in this scope

What command did you use that results in that error?
June 2nd, 2007 #7

ankakusu is offlineFirst Cup of Ubuntu

Join Date Oct 2006 Beans 10 --> Beans 10

Re: error: 'printf' was not declared in this scope

I'm using vi editor and first of all I created a file like this:

user@user-desktop:~$ vi example_macro.cpp

then I compiled the file by the command:

sh-3.1$ gcc example_macro.cpp -o objmacro

by the way I have a off topic question,
I have created a file:

user@user-desktop:~$ mkdir make_file_work

then I go and look both the 'user' file and to the 'desktop' I cannot find such a directory? But if I write the command:

user@user-desktop:~$ cd make_file_work

I can go inside that file, but I cannot see it in the file browser.

thanks again for your help WW.

June 2nd, 2007 #8

WW is offlineIced Blended Vanilla Cr�me Ubuntu

Join Date Oct 2004 Beans 1,532 --> Beans 1,532

Re: error: 'printf' was not declared in this scope

You appear to be writing C, not C++. Rename the file to example_macro.c, and try again. (I just tried it both ways; I got the same error that you did when the file was called example_macro.cpp, and it compiled fine when I called it example_macro.c.)

June 2nd, 2007 #9

Mime is offlineSpilled the Beans

Join Date Apr 2006 Beans 13 --> Beans 13

Re: error: 'printf' was not declared in this scope

It'll compile as a .cpp if you put the line.

using namespace std;

under the include for stdio.h, or preface printf with "std::" in order to tell the compiler that you're using a function from the standard namespace.

June 3rd, 2007 #10

ankakusu is offlineFirst Cup of Ubuntu

Join Date Oct 2006 Beans 10 --> Beans 10

Re: error: 'printf' was not declared in this scope

Yes, it compiled when I changed the extesion from .cpp to .c. But I dont know the diferrences between the c and cpp.

Does the reason depends to 'printf' function? Because, as far as I remember I use cout function instead of printf in cpp. I guess printf is a c function.

But when I tried with
#include
using namespace std;

it gave an error again. the error the same:

/tmp/ccubDW3d.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld output return 1

what does this error mean anyway?

"/tmp/ccubDW3d.o" . what is the object ccubDW3d.o in the 'tmp' directory?

"(.eh_frame+0x11)" . can this be an address?

"undefined reference to `__gxx_personality_v0'" : it says '__gxx_personality_v0' and says there is an undefined reference to this 'thing'. But I've not use that thing in my . . . code. What does it refer to in my code?
"collect2: ld output return 1" : what is collect 2? What is ld output? What does returning 1 means?

WW and Mime thanks for help