1

I have a piece of a project in which I have some code files defining functions, some header files, and then a .c file for testing (which has the main()). Particularly, I have these files all in the same folder (both .c and .h):

“dice”, “game”, “map”, “players”. Then there's “test”, this last one only .c. In all the .h files there's the same type of declaration at the begining (this is from “game.h”):

#ifndef GAME_H 
#define GAME_H

#include "dice.h"
#include "map.h"
#include "players.h"

//then there goes the short declaration of the functions in game.c

#endif

The stdio.h is also added in the .c files.

My problem is that I get all the time an error like this: "[Linker Error]: undefined reference to 'whatever_the_function_is_called'" (for like 2 or three functions), and "[Linker Error]: undefined reference to 'WinMain@16'". "Id returned 1 exit status". The only thing I managed to solve is the “WinMain@16” error by adding “void” before the main(), but I've never needed this before. Actually, in an earlier version of the project none of this happened.

I've checked my spelling and looked over the case sensitivity, revised the parameters, checked over that the functions were written on the right place, and tested a lot of other things a bunch of times, but nothing worked.

Could someone help me with this? Any ideas, explanations or anything would be much appreciated.

Thank you in advance!

PD: The main function:

main(){

  int i;
  char opt = 'a';

  t_players pl;
  t_map map;

  initialize_seed();

  initialize_players(&pl);
  initialize_regions(&map, &pl);

  while(opt != 'n' && opt != 'N'){
        print_map(map, pl);
        scanf("%c", &opt);
        //still to complete
  }

}
Haekoth
  • 27
  • 5
  • what IDE do you use, do you use mingw compiler? did you add any libraries to link with your project? – nio Nov 28 '13 at 19:17
  • 3
    You should use `int` not `void` before `main()`. Also, your error says that you didn't link with all *.c/*.cpp files. – UltraInstinct Nov 28 '13 at 19:17
  • Hi, thank you both for the fast response! As to what IDE I'm using, it's wxDevC++. I do not have any other libraries than stdio. About the int, I have kept going without doing that all the time, this is the first time that happens. Anyway I'll try it out right now. – Haekoth Nov 28 '13 at 19:18
  • Ok, the error persists even with using int main(). About linking the files, what do you mean? Excuse me if this is basics, I'm a begginer to split files. Isn't just enough to make a .c and .h with the same name? Thanks again! – Haekoth Nov 28 '13 at 19:28
  • names of files doesn't matter there... you have to have all .c files added in your dev-cpp project and every C file has to know about functions in other .c files (using headers), but your problem is in linking... (not header related) – nio Nov 28 '13 at 19:30
  • Why can't we see your WinMain function? – David Heffernan Nov 28 '13 at 19:35
  • Oh, so then I should compile them and link the .o file? But the other files can't compile also (they have the same WinMain error, and I can't solve it, now for some reason it says "the file has been modified outside wxDevC++, do you want to reload it from the disk?"). I will now upload the main() if you want to see it. – Haekoth Nov 28 '13 at 19:41
  • There's sometimes problem with compiling C code using main function with mingw compiler, you should check what libraries are linked to your project in project settings. The trick is that some library does implement the WinMain for you and calls your main function, in your case it didn't work out. Here's some hint: http://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16 – nio Nov 28 '13 at 20:14
  • Ok, thanks for the help nio. As expected, switching main() by WinMain() solved the "WinMain@16" problem (though I would prefer to change it I can't manage to do it). But the other linking problems persist, though. Anyway, I've managed to make it work on my VM with Ubuntu 12.10 using the "gcc" method, so for now I can at least try and debug. I will keep trying to make it work on wxDevC++ and post the answer when I find it. Anyway, do you know a method to change the entry point without using cmd? That would be much more convenient. Thank you again! – Haekoth Nov 28 '13 at 20:28
  • Is your project GUI or console based? If it's console only, check your project settings if you have console application set. Maybe it will help. – nio Nov 28 '13 at 20:43

0 Answers0