-
undefined reference
Hello,
I have a problem. When trying to compile my sourcecode I get following warning:
undefined reference to `add'
This is where I get it:
Code:
#include <stdio.h>
#include <string.h>
#include "mytype.h"
int main(int argc, char *argv[])
{
MyType ps = {0,0};
add(3, &ps);
...
This is the header:
Code:
typedef struct
{
int counter;
int lastindex;
unsigned int codes[100];
} MyType;
void add(unsigned int code, MyType *ps);
What did I get wrong? Both files are in the same directory.
-
You need to actually define the add function.
-
It appears that you have included a function prototype for the function 'add', but no actual function. Hence the error 'undefined reference', since you are calling a function which you haven't included in your source code.
-
Hello, I defined the function in a file called mytype.c which includes mytype.h.
How do I get it from there?
-
Depends on what you're using to compile your code. You need to compile it along with your other code.
-
Oh yeah, I have to compile all source files at once, that was my mistake.