|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Interesting Problems with the Compiler and Linker
Alright, I was programming and found the need to use a function pointer, I programmed it alright, my syntax was right, but the linker said it was being declared multipally. Well, I found a different way to program it, and just went on. I had this same problem trying to declare variables in header files too(I declared the function pointer in the header too).
Can anyone shed any light as to why it's complaining about this? I am really bad at figuring out linker problems, I have a mental block or something with them. |
|
#2
|
|||||
|
|||||
|
Re: Interesting Problems with the Compiler and Linker
Never declare variables in header files (.h), otherwise, everytime you include that header file you'll be ordering the compiler to declare the variable all over again. That's why you see those "multiply defined" errors.
In the header file use: Code:
extern char myvariable; There is an alternative way to declare variables in a header file that involves a conditional compile: Code:
#ifdef DECLARE_MY_VARIABLES
char myvariable;
#else
extern char myvariable;
#endif
Code:
#define DECLARE_MY_VARIABLES
#include that_header_file.h
#undef DECLARE_MY_VARIABLES
Last edited by Mark McLeod : 14-02-2008 at 14:01. |
|
#3
|
|||
|
|||
|
Re: Interesting Problems with the Compiler and Linker
I was going to put those variables into structs, because they all had something to do with each other, but the compiler/linker said the same thing about my defined struct.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Build problems: MPLink 4.15 Linker... help? | Trav-O | Programming | 2 | 12-01-2008 14:26 |
| compiler problems | sephiroth_42 | Programming | 4 | 04-02-2007 10:56 |
| Compiler problems | katkana | Programming | 2 | 03-02-2005 18:29 |
| Free Compiler/Linker for WinXP? | IMDWalrus | Programming | 14 | 05-11-2003 15:45 |
| Interesting thing with the times | Joe Ross | CD Forum Support | 6 | 14-05-2002 21:51 |