Skip to content
Advertisement

Multiple instances of main method in C

I’ve got an issue with an assignment, but I’m not asking for help to do the assignment, just single problem.

My code is like this:

#include "linux/kernel.h"
#include "linux/unistd.h"
#include <linux/slab.h>

typedef _msg_t msg_t;

struct msg_t { /* members here */ };

static msg_t *bottom = NULL;
static msg_t *top = NULL;

int function_one (argA, argB) {
/* function is working, no need to show code*/
}

int function_two (argA, argB) {
/* function is working, so no need I guess to show the code*/
}

int main(int argc, char ** argv) {
char *in = "This is a testing message";
char msg[50];
int mlen;
function_one(in, strlen(in)+1);
mlen = function_two(msg, 50);
}

Here’s the problem: When I do the make command from the directory, I get the error

/home/<username hidden by me>/dm510/linux-3.18.2/arch/um/os-linux/main.c:118: 
   multipli definition of 'main'
arch/um/kernel/built-in.o:
   /home/<username hidden again>/dm510/linux-3.18.2/arch/um/kernel/file_i_created.c:60 
   first defined here"

What does this error mean? I only defined the main method one time in my own file

Advertisement

Answer

The message says you have (at least) two C files, main.c and file_i_created.c that are included in the build. Both have main() functions. (In C, the term is “function”, not “method”.) Remove one of those source files, or remove/rename the main() function in one of them.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement