I just installed Visual C++ 2008 Express Edition. I dont know where i configure it to properly compile multiple source files project. It do well just when the project is a single file.
eg. Source_B.c has a reference to a global variable declared in Source_A.c
When Source_B.c is compiled i have this: error C2065: 'varname' : undeclared identifier
The same sources compiled in Visual Studio 2005 years ago, so its a IDE misconfiguration right?
Robert wrote:I just installed Visual C++ 2008 Express Edition. I dont know where i configure it to properly compile multiple source files project. It do well just when the project is a single file.
eg. Source_B.c has a reference to a global variable declared in Source_A.c
When Source_B.c is compiled i have this: error C2065: 'varname' : undeclared identifier
The same sources compiled in Visual Studio 2005 years ago, so its a IDE misconfiguration right?
The sources remains intact.
Any thoughts?
PS: Im not a programmer yet!
I am not a programmer. I have searched 'error c2065 microsoft vs 2008' in Google. I copy some URLs:
The first link explains a little the error C2065, which is in fact:
'identifier' : undeclared identifier
The second link explains some things about the changes in Visual C++ 2005 Compiler. Quoting a little:
Enforce parameter checking for Visual C++ attributes
Code that passes named attributes to the attribute constructor in quotes when the type is not a string and without quotes when the type is a string will now give Compiler Error C2065 or Compiler Warning (level 1) C4581. Previously all compiler attributes were parsed as strings, and if needed, the compiler inserted the missing quotes. Attribute support was enhanced by adding parameter checking validation. This will prevent unexpected behavior due to incorrect arguments to an attribute constructor.
For this release you cannot have a multi-byte character string (MBCS) in any argument to an attribute which takes an implicit string as an argument, even if the string is quoted (doing so can result in a corrupt .idl file). The workaround is as follows:
In post #3, there is someone with the same problem as you, and got answered:
Bojan Resnik wrote:
umesh wrote:3.umesh said
December 29, 2009 at 12:07
I have created one application in VS2005. It is working perfectly. But when i am building same application in VS 2008 it is showing these errors please help.
Bojan Resnik said
December 29, 2009 at 13:25
Do you mean that the application is compiled with Visual Studio 6.0 under VS 2005 or that it is a regular VS 2005 application?
If the former, then most probably you did not run the vcvars32.bat file that came with Visual Studio 6.0 or you did not supply the /useenv switch when starting VS 2008.
Reply
I hope it will be useful. I wish you good luck because it is all the help I can give you. And please do not underestimate Google!
Two first meanings of the dutch word "leren":
1. leren [vc] (learn, larn, acquire) acquire or gain knowledge or skills.
2. leren [v] (teach, learn, instruct) impart skills or knowledge to.
Robert wrote:I just installed Visual C++ 2008 Express Edition. I dont know where i configure it to properly compile multiple source files project. It do well just when the project is a single file.
eg. Source_B.c has a reference to a global variable declared in Source_A.c
When Source_B.c is compiled i have this: error C2065: 'varname' : undeclared identifier
The same sources compiled in Visual Studio 2005 years ago, so its a IDE misconfiguration right?
The sources remains intact.
Any thoughts?
PS: Im not a programmer yet!
as much as i love criticizing microsoft, your problem has more to do with your misunderstanding of the C language than the microsoft IDE. in particular compiling units arecompiled independantly and linked at the end. so a variabled defined in source_b.c cannot be used in source_a.c unless you use extern to declare it in source_a.c
This 'declares' the variable varname, i.e. tells the compiler that it is an int, so that you won't run into error C2065 anymore in any of these files.
In one of the files you would still have to actually reserve memory space for it (make it 'internal', as it were, rather than leaving the compiler under the impression it is external), by writing
-Correct declaration of the var as extern in SourceA
-Correct inicialization and use of the var in SourceA
-put #include of SourceB in SourceA file?
-omitting #include of SouceA in sourceB??
duh
Now the use of the .h suggested seems to be good.
I have learned Basic 20 years ago, Pascal 10 years ago and start something with C in a spare time in 2008 (the code comes from a backup from that time).
I have no idea how to some C things work at all till now.
My error was trust in the backup code (because i have a vague memory with it worked in past) and dont trust in the compiler.
The road till a perft function in C of yesterday became a kind of interstellar travel now!
Kinda surprised it compiled in an earlier version to begin with.
at any rate, most .c files tends to have a .h file, the .h file tends to include:
type definitions
prototypes of functions i.e. void somefunc(int a);
extern declarations of global variables that are used in other .c files
constants/enums
this is the stuff other compilation units need to know to get things ready for the linker.
each .c file will then include the .h's of any other compilation unit that it needs to access parts of.
you place these in a .h file so that they only have to exist in one place and because other .c files need to know about them. If you only have two .c files you might just put the extern into that .c file but by the time you have a whole mess of .c files it's far more convenient to be able to just include the collection of .h files you need in each .c than to try to remember all the different externs and function prototypes you call from each individual file.