Need help to define Environment variable [message #1730317] |
Sun, 24 April 2016 15:17 |
epy hobb Messages: 1 Registered: April 2016 |
Junior Member |
|
|
Hi,
I have recently started to use Eclipse and found very user friendly. But as i m new, i m facing some problem. Like setting some Variables.
I bunch of .c and .h files. And at the beginning of the file i have check like
#ifdef PROCESSOR,
so, to make this file accessible i have to define #define PROCESSOR in each file, which is very time consuming every time(because i m using latest version of workspaces, so, need to browse new workspace every time).
So i want to know, easiest way to define PROCESSOR in the somewhere in the eclipse setting, so no need to #define in each file.
|
|
|
Re: Need help to define Environment variable [message #1730498 is a reply to message #1730317] |
Tue, 26 April 2016 11:22 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
Are you talking about a header guard ? if so, then the variable should be immediately defined in the header.
#ifndef GUARD
#define GUARD
:
#endif
If you are taking about conditional compilation, there are a number of ways to go about it.
You could define an environment variable, add it to the environment variable list
Project --> Properties --> C/C++ Build --> Environment then use the Add.. button
Alternately, you could just make a build variable
Project --> Properties --> C/C++ Build --> Build Variables also with an Add.. button.
You then would go to Project --> Properties --> C/C++ Build -->Settings and
edit the compiler command (normally, ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}) by adding
-Dmyvar=${myvar}
But that's a bit awkward.
You could set the the variable in the compile command
Project --> Properties --> C/C++ Build --> Settings
select compiler Preprocessor option in the dialog menu and add the variable in the pane labeled Define symbols (-D). There's a tiny add icon just above the pane.
Or you could have a header file (say, config.h) that defines the variable. This is probably best for future maintenance -- particularly if maintained by someone other than yourself. It will maintain a history that is less likely to be lost when moving the files to another project.
[Updated on: Tue, 26 April 2016 11:23] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02490 seconds