Compile 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 undefined reference to main c c++ problem Overflow the company Business Learn more about hiring developers or posting ads with us Stack arduino error compiling undefined reference Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community function _start error undefined reference to main of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up C Linking Error: undefined reference to 'main' up vote 11 down vote favorite I have read the undefined reference to main eclipse other answers on this topic, and unfortunately they have not helped me. I am attempting to link several c programs together, and I am getting an error in response: $ gcc -o runexp.o scd.o data_proc.o -lm -fopenmp /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status make: * [runexp] Error 1 I have exactly one main function and it is in runexp. The form is
Undefined Reference To Main Makefile
int main(void) { ...; return 0; } Any thoughts on why I might get this error? Thanks! c linker share|improve this question edited Apr 9 '13 at 14:53 unwind 254k38330460 asked Apr 9 '13 at 14:47 Nicole 3402514 is this function at global scope? –Ivaylo Strandjev Apr 9 '13 at 14:48 4 your GCC command doesn't include runexp.c, it OUTPUTS to runexp.o - sure you're including the source file with the main method ? –Morten Jensen Apr 9 '13 at 14:49 add a comment| 3 Answers 3 active oldest votes up vote 10 down vote accepted You should provide output file name after -o option. In your case runexp.o is treated as output file name, not input object file and thus your main function is undefined. share|improve this answer answered Apr 9 '13 at 14:51 Romeo 3,0831022 Thank you so much! I completely did not notice. Woops. –Nicole Apr 9 '13 at 15:05 Or just remove the -o option and use the conventional ./a.out, which is a beautiful name ;) –Tomasz Gandor Aug 5 '14 at 22:42 add a comment| Did you find this question interesting? Try our newsletter Sign up for our newsletter and get our top new questions delivered to your inbox (see a
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
Undefined Reference To Main Fortran
Stack Overflow the company Business Learn more about hiring developers or posting ads with undefined reference to main code blocks us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a undefined reference to main assembly community of 4.7 million programmers, just 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 http://stackoverflow.com/questions/15905119/c-linking-error-undefined-reference-to-main vote favorite 1 I'm trying to compile a 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.4k75263 asked Nov 1 '11 at 10:56 Bran Stark 1351211 Might http://stackoverflow.com/questions/7965437/undefined-reference-to-main-collect2-ld-returned-1-exit-status be a good idea to post the code causing this error. –Lundin 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 28 down vote accepted It means that es3.c does
least in this lab). these are here as they are errors i have fallen into before and will probably fall into again. they might be useful for other people. i have looked on the web for beginner's explainations http://www.hannahdee.eu/cpp.html of g++ compiler messages, and the best i could find was this: http://www.csee.umbc.edu/courses/undergraduate/341/misc/CommonErrors.shtml; if you can't find what you are looking for here you might want to try their list. Error messageExplanation error: expected `;' before ':' token You've http://www.csee.umbc.edu/courses/undergraduate/202/spring07/Projects/CommonErrors.shtml finished a line with a : instead of a ; error: 'cerr' was not declared in this scope You've either forgotten to #include
suggestions for errors that should be included in this document or have questions or suggestions for improving the document please email Mr. Frey Definitions Commonly used words and phrases found in the compiler and linker error messages. identifier -- the name of a class, struct, function or variable collect2: ld returned 1 exit status -- usually found as the last line of the error. This phrase indicates that you have a linker (ld) error, not a compiler error. Linker errors occur when g++ tries to combine all of your .o files into an executable file. Linker errors CANNOT be fixed by guarding header files or by changing which header files are included in your .cpp file. non-aggregate type -- classes and structs are generically called "aggregate" types. If you get an error indicating that your class is a "non-aggregate type", then the compiler has not seen your class definition and doesn't recognize your class as such. read-only structure -- refers to a const object. This phrase is generally found in a compiler error when you are trying to change a data member in a const object. Compiler Errors undeclared identifier Example doy.cpp: In function `int main()': doy.cpp:25: `DayOfYear' undeclared (first use this function) doy.cpp:25: (Each undeclared identifier is reported only once for each function it appears in.) doy.cpp:25: parse error before `;' token Meaning You used "DayOfYear" in your code, but the compiler has not seen a definition for "DayOfYear". It doesn't know what "DayOfYear" is. Usual Causes You forgot to include the header file that defines the class/struct/function/etc You misspelled the name of the identifier cout undeclared Example xyz.cpp: In function `int main()': xyz.cpp:6: `cout' undeclared (first use this function) xyz.cpp:6: (Each undeclared identifier is reported only once for each function it appears in.) Meaning This is really a special case