Hello,
I'm new to code::blocks. I program in C and use Linux Mint as my environment.
I have to say that I'm loving code::blocks so far!
However, for some time I'm having issues with linking my main program to libraries, getting "undefined reference to <function>". In searches I've been making to look for solving my problem I realize that I'm not the only one. But I didn't find any answer that could be applied here.
This is my code with the three of my files:
maintest.c
#include <stdio.h>
#include "lib.h"
int main() {
menu(3, "one", "two", "three");
return 0;
}
lib.h
#ifndef _LIB_H_
#define _LIB_H_
typedef char* string;
void menu(int count, ...);
#endif
lib.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include "lib.h"
void menu(int count, ...) {
va_list listPointer;
va_start(listPointer, count);
for(int i = 1; i <= count; i++) {
char *string = va_arg(listPointer, char*);
printf("%d ..... %s", i < count ? i : 0 , string);
}
va_end(listPointer);
}
The compiler (gcc) does ok if I compile this by terminal with the following command:
gcc -Wall maintest.c lib.c -o result
But if I just compile maintest.c, it happens that the same error occurs of "undefined reference to menu()".
I would like to know why code::blocks isn't compiling both files as it should, since one is calling another.
I'm really loving this IDE. I used Dev-C++, Borland and kdevelop, and this is by far the best. Although I'm having this issue that I never had before, so for that reason I'm unexperienced with linker problems.
I hope I'm on right section and sorry if this kind of question are obsolete, it's just I couldn't find an answer.
Hope a solution soon as possible, since I'm starting school and really need this ready.
Thank you very much for your time.