Why am I getting “undefined reference to main”

Your compiler’s command line contains -I -c sequence.

This -I option “swallows” your -c option. -I requires an additional argument, which is an include directory name. You failed to supply that argument, which is why -I assumes that -c that follows it is the directory name. So that -I consumes that -c.

The compiler never sees that -c. Without -c it assumes that you want to compile and link your program. Since Gladius.cpp does not have main in it, you get the error at linking stage.

Here ‘s a simple demo of the same problem: http://coliru.stacked-crooked.com/a/8a37cd3e90a443e2

You need to figure out why you have an orphaned -I in your command line.

Leave a Comment