Gcc Error Undefined Reference To Main
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company undefined reference to main in function _start Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs undefined reference to main' g++ Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just undefined reference to main c++ like you, helping each other. Join them; it only takes a minute: Sign up Undefined reference to main - collect2: ld returned 1 exit status up vote 18 down vote favorite 1 I'm trying to compile a undefined reference to main makefile program (called es3), but, when I write from terminal: gcc es3.c -o es3 it appears this message: /usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: ld returned 1 exit status What could I do? c gcc reference share|improve this question edited Dec 12 '13 at 1:26 plaes 16.5k75263 asked Nov 1 '11 at 10:56 Bran Stark 1351211 Might be a good idea to post the code causing this error. –Lundin
Undefined Reference To Main Eclipse
Nov 1 '11 at 14:56 1 @BrandoSK: When I follow that link, I get a 45-second countdown. Either post the code as part of your question, or narrow it down to a small example that illustrates the problem and post that. –Keith Thompson Nov 2 '11 at 3:58 Ok, I just downloaded your source file. (1) It's called es3_f3.c, not es3.c. (2) It contains multiple errors, for example a missing semicolon on line 18. It could not possibly have compiled, which means you couldn't get far enough to see the linker error that you report. Show us your real code. (The downloaded source file is 73 lines, which is short enough to post here directly.) –Keith Thompson Nov 2 '11 at 4:03 The error message you show is very similar to the one I get when I use the command gcc es3.c -o es3 with a source file that doesn't define a main function. Whatever source file you're really compiling doesn't define a main function. –Keith Thompson Nov 2 '11 at 4:07 add a comment| 5 Answers 5 active oldest votes up vote 29 down vote accepted It means that es3.c does not define a main function, and you are attempting to create an executable out of it. An executable needs to have an entry point, the
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of
Undefined Reference To Main Fortran
this site About Us Learn more about Stack Overflow the company Business undefined reference to main assembly Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask undefined reference to main' shared library Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign http://stackoverflow.com/questions/7965437/undefined-reference-to-main-collect2-ld-returned-1-exit-status up undefined reference to `main' in C up vote 1 down vote favorite Hi I am getting below error while compiling a c code using gcc /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../lib64/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status I am trying to import the fftw() function into SystemVerilog. Here is my code #include here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack http://stackoverflow.com/questions/20514587/text0x20-undefined-reference-to-main-and-undefined-reference-to-function Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up (.text+0x20): undefined reference to `main' and undefined reference to function up vote 4 down vote undefined reference favorite 2 I am having issue getting my makefile to work without errors. The first issue i have is with an undefined reference to main. I have main in my producer.c file as a function. The second issue is an undefined reference to SearchCustomer(). error: bash-4.1$ make gcc -Wall -c producer.c shared.h gcc -Wall -c consumer.c shared.h gcc -Wall -c AddRemove.c shared.h gcc -pthread -Wall -o producer.o consumer.o AddRemove.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In undefined reference to function `_start': (.text+0x20): undefined reference to `main' AddRemove.o: In function `AddRemove': AddRemove.c:(.text+0xb1): undefined reference to `SearchCustomer' AddRemove.c:(.text+0x1e9): undefined reference to `SearchCustomer' AddRemove.c:(.text+0x351): undefined reference to `SearchCustomer' collect2: ld returned 1 exit status make: *** [producer] Error 1 makefile: COMPILER = gcc CCFLAGS = -Wall all: main debug: make DEBUG=TRUE main: producer.o consumer.o AddRemove.o $(COMPILER) -pthread $(CCFLAGS) -o producer.o consumer.o AddRemove.o producer.o: producer.c shared.h $(COMPILER) $(CCFLAGS) -c producer.c shared.h consumer.o: consumer.c shared.h $(COMPILER) $(CCFLAGS) -c consumer.c shared.h AddRemove.o: AddRemove.c shared.h $(COMPILER) $(CCFLAGS) -c AddRemove.c shared.h ifeq ($(DEBUG), TRUE) CCFLAGS += -g endif clean: rm -f *.o c gcc compilation compiler-errors makefile share|improve this question edited Dec 11 '13 at 9:17 asked Dec 11 '13 at 8:53 user2644819 46721124 The code is too long. Narrow your problem down and provide a Short, Self Contained, Correct (Compilable), Example. –Yu Hao Dec 11 '13 at 8:56 A couple of suggestions: in the main recipe, you can write: $(COMPILER) -o $@ $^ $(LDFLAGS) and put -pthread in LDFLAGS. In the other rules you can write once: %.o: %.c and as recipe: $(COMPILER) $(CCFLAGS) -c -o $@ $< (and not give the .h to the compiler!) and later add dependency for special targets, for example: producer.o: shared.h other_header.h and consumer.o: shared.h yet_a