Linker 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 Gcc
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions undefined reference to main in function _start Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, undefined reference to main c++ 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 other answers on this
Undefined Reference To Main G++
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 int main(void) { ...; return 0; }
Undefined Reference To Main Makefile
Any thoughts on why I might get this error? Thanks! c linker share|improve this question edited Apr 9 '13 at 14:53 unwind 255k38332460 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,0931022 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| up vote 3 down vote You're not including the C file that contains main() when compiling, so the linker isn't seeing it. You need to add it: $ gcc -o runexp runexp.c scd.o data_proc.o -lm -fopenmp share|improve this answer
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 undefined reference to main error in c about Stack Overflow the company Business Learn more about hiring developers or posting ads
Undefined Reference To Main Assembly
with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow in function start undefined reference to main is a community of 6.2 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 http://stackoverflow.com/questions/15905119/c-linking-error-undefined-reference-to-main 18 down 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.5k75263 asked Nov 1 '11 at 10:56 Bran Stark 1351211 http://stackoverflow.com/questions/7965437/undefined-reference-to-main-collect2-ld-returned-1-exit-status Might 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 29 down vote ac
Practice Problems Quizzes Resources Source Code Source Code Snippets C and C++ Tips Finding a Job References Function Reference Syntax Reference Programming FAQ Getting Help Message Board http://www.cprogramming.com/tutorial/compiler_linker_errors.html Email About Us Dealing with Compiler Errors - Surviving the Compilation Process By Alex Allain It's your first C (or C++) program--it's not that long, and you're about to compile http://www.csee.umbc.edu/courses/undergraduate/202/spring07/Projects/CommonErrors.shtml it. You hit compile (or enter the build command) and wait. Your compiler spits out fifty lines of text. You pick out words like "warning and "error". Does that mean it undefined reference worked? you wonder. You look for the resulting executable. Nothing. Damn, you think, I guess I have to figure out what this all means... The Types of Compilation Errors First, let's distinguish between the types of errors: most compilers will give three types of compile-time alerts: compiler warnings, compiler errors, and linker errors. Although you don't want to ignore them, compiler undefined reference to warnings aren't something severe enough to actually keep your program from compiling. Usually, compiler warnings are an indication that something might go wrong at runtime. How can the compiler know this at all? You might be making a typical mistake that the compiler knows about. A common example is using the assignment operator ('=') instead of the equality operator ('==') inside an if statement. Your compiler may also warn you about using variables that haven't been initialized and other similar mistakes. Generally, you can set the warning level of your compiler--I like to keep it at its highest level so that my compiler warnings don't turn in to bugs in the running program ('runtime bugs'). Nevertheless, compiler warnings aren't going to stop you from getting your program working (unless you tell your compiler to treat warnings as errors), so they're probably a bit less frustrating than errors. Errors are conditions that prevent the compiler from completing the compilation of your files. Compiler errors are restricted to single source code files and are the result of 'syntax errors'. What this really me
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 of "undeclared identifier". Usual causes You forgot