Splitting source into multiple files(Linux & make)
I consider myself to be a pretty able programmer, for a hobbyist, but I've run into some problems that I cannot seem to solve.
I'm taking my first shot at any real linux programming, and I am writing an ircbot for a channel I frequent. The linuxy part of it will be its eventual ability to use modules to call user-defined functions on certain events(E.g. receives PRIVMSG and it checks the PRIVMSG event chain. If someone has registered, it'll call the function in that module.. ).. I digress.
The problem I'm having is that, after the initial stages where it was all bunched up in one source file(Should have started out the other way), I decided to divide it all up into multiple source files. This has never really been a problem for me - I've done this plenty of times on Visual Studio, but the difference is that I'm not using an IDE that does the work for me, and I'm using make.
I'll describe the files:
ircbot.c: Contains the main function, which call various functions from botfunctions.c
botfunctions.c: Contains definitions for functions.
prototypes.h: Prototypes for functions in botfunctions.c
botstructs.h: Contains definitions for various structures used to structure input and so on.
What I started by doing is what I've done in most of my other projects. I use a main "includes.h" file which contains all the standard header files(stdio.h, network header files and all that), and includes the other header files, like prototypes, botstructs and so on. I then include this file in the other source files.
Thing is, if I use make, I can get everything to compile, since it splits everything into object files. ircbot.c compiles to ircbot.o fine, and botfunctions.c to botfunctions.o too, and they are compiled into the main executable fine. If I run this executable, however, I get the output I'm supposed to see a billion times over. In fact, it is too much for my terminal to handle and I have to manually kill it. The bot functions properly past that - it connects and does what it's supposed to do, only once, not a billion times like when it displays output.
Looking at the disassembly of the executable, it looks like main is a series of conditional jumps into itself.
I know there's something wrong here, since if I just try to compile with gcc, it doesn't like it and gives me undefined references to all the functions, in spite of the prototypes.h file being included.
Can someone give me some tips on this? I have read several makefile tutorials and "split your project into many files"-tutorials, but none of the mention strange cyclic calling errors(Cyclic dependencies, but not strange loops).
I would really appreciate it if someone could give me some hints on what I'm doing wrong, and tips for the future. Is the "one main include file with include guard"-approach no good? If so, why not?