Crt1.O: in Function '_Start': - Undefined Reference to 'Main' in Linux

crt1.o: In function `_start': - undefined reference to `main' in Linux

Try adding -nostartfiles to your linker options, i.e.

$(LINK) -nostartfiles -g ...

From the gcc documentation:

-nostartfiles
Do not use the standard system startup files when linking. The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used.

This causes crt1.o not to be linked (it's normally linked by default) - normally only used when you implement your own _start code.

Undefined reference to 'main' error in crt1.o function _start

Here are a couple of hints:

  1. -o $@ $< is not needed for .o files, so remove that from those targets.
  2. -Wall makes more sense when used while compiling not linking. So I would add it to the CC and CXX line instead (or better, to the CFLAGS and CXXFLAGS).
  3. the clean target should be a dependency of the .PHONY target, so that you can execute it always (without previous check for changed dependencies).

If you still get an error about missing references to your functions from modules.c, you are probably missing some extern "C" ... statements in main.cpp. That's because the internal name of C++ functions is calculated differently than that from C functions (i think C++ prefixes all names with the namespace, class names, etc). To tell C++ that a specific function can be found using the old internal name for linkage, use the extern "C" statement.

c - In function `_start': (.text+0x20): undefined reference to `main'

I believe you're trying to build an object file.

gcc, when invoked by default, will try to build an executable. It cannot do that if it doesn't find a main function in one of the files you've specified to be compiled and linked.

To build just an object file, pass the -c flag to gcc when compiling your code.

gcc -o "progressWarmUp" -c ./main.o

This will tell gcc to stop after the compilation process and before the linking process.
Note that if you actually want to execute this code yourself, you'll have to link it into an executable by linking it with an object file that has a defined main function.

FORTRAN: undefined reference to main in crt1.o in function '_start'

This error I know from cases when I forgot to add the object file for the main program (the one that starts with program foo ;-) ). Could it be that you miss that one as well?

gfortran compile object file error crt1.o: In function `_start':

You certainly do not execute an object .o file. You link it to create an executable file.

But Notice you do not create the reader.o file, you create a reader.x file in:

gfortran -O3 reader.f iotools.c -o reader.x

With this command an executable file reader.x should be created and you should be able to execute it. There is no second gfortran command.

OR

You can do it in two steps. First compile and then link

gfortran -c -O3 reader.f iotools.c -o reader.o

gfortran reader.o

In this case the second command creates an executable file called a.out.

Both ways are possible.

These are absolute basics, please do some study first before attempting more. Read a tutorial, search among the questions there. There are many very similar questions here. I answered here just to clear your specific confusions which might not be that directly clear from some duplicates.



Related Topics



Leave a reply



Submit