Go Down

Topic: [SOLVED] Referencing define in another file (Read 470 times) previous topic - next topic

GregM

Jul 30, 2013, 04:24 pm Last Edit: Jul 30, 2013, 07:25 pm by GregM Reason: 1
I've got a project that I would like to publish on google code. The problem is that the code contains a api key which obviously I dont want to publish. I could remove it from the local source code but then everytime I rest the code I would need to put the key back in.

Currently the key is defined at the top of my program as
Code: [Select]

#define apikey "my key here"


What I would like to do just include the key in a separate file and then not sync that to google code. I've tried adding in a new file called key.ino but I think at compile time the key then gets added to the bottom of the main program so that it fails to compile.

I can't use it in a #include as its only a define.

Any suggestions, or is there a simple solution I'm over looking?


KeithRB

"I can't use it in a #include as its only a define."

In traditional C, that is exactly where #defines are supposed to go!

If you are worried about name space collision you can make them "idimpotent":

# ifndefined(API_KEY_FILE)
#define API_KEY_FILE
#define my_api_key
#endif

AWOL

Better still, make them "idempotent"
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

GregM


"I can't use it in a #include as its only a define."

In traditional C, that is exactly where #defines are supposed to go!

If you are worried about name space collision you can make them "idimpotent":

# ifndefined(API_KEY_FILE)
#define API_KEY_FILE
#define my_api_key
#endif



I'm afraid you've completely lost me. :(

Should I create a file, say "api_key_file" and it in put the apikey. Then use the above code in my main program?

KeithRB

You create a .h file with the commands I used and then #include it.

mrburnette

#5
Jul 30, 2013, 05:12 pm Last Edit: Jul 30, 2013, 05:58 pm by mrburnette Reason: 1
Edit to Bold, Italicize, and Underline stuff!

Quote
What I would like to do just include the key in a separate file and then not sync that to google code. I've tried adding in a new file called key.ino


Use the Arduino GUI to create a new tab called key.h, put your defines there.  In your main module,
Code: [Select]
#include "Defines.h"

"Defines.h" for different LCD pinouts that looks like:

Code: [Select]
// defines associated specifically with Nokia 5110 LCD ScrnFuncts
#define PIN_SCE   7
#define PIN_RESET 6
#define PIN_DC    5
#define PIN_SDIN  4
#define PIN_SCLK  3

#define LCD_C     LOW
#define LCD_D     HIGH
#define LCD_X     84
#define LCD_Y     48

UKHeliBob

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

GregM

Thanks guys - working perfectly now.

Go Up