Gcc Error Undefined Reference 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 undefined reference to main' g++ Stack Overflow the company Business Learn more about hiring developers or posting ads with undefined reference to main in c us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is undefined reference to `main' error in c a community 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 in function `_start': (.text+0x20): undefined reference to `main' have read the 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
Undefined Reference To Main C++
runexp. The form is 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 254k38332460 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| up vote 3 down vote You're not including the C file that contains main() when compiling, so th
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 Business Learn more
Undefined Reference To Main' Makefile
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges (.text+0x20) undefined reference to main' gcc Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each in function start undefined reference to main other. Join them; it only takes a minute: Sign up undefined reference to main error in gcc on centos. up vote 0 down vote favorite I was trying to run a hello world program with gcc using the following http://stackoverflow.com/questions/15905119/c-linking-error-undefined-reference-to-main command gcc hello.c But I am getting the following error. /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: ld returned 1 exit status gcc reference undefined main share|improve this question edited Jul 30 '11 at 9:07 Kiril Kirov 23.6k875137 asked Jul 30 '11 at 8:54 Sreeraj S 11 2 Please, add text of hello.c to your post –osgx Jul 30 '11 at 9:00 add a comment| 1 Answer 1 active oldest votes up vote http://stackoverflow.com/questions/6882115/undefined-reference-to-main-error-in-gcc-on-centos 1 down vote Seems, that you have no defined a main() function in your hello.c. Right code is like this: #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have http://stackoverflow.com/questions/27963150/undefined-reference-to-main-error-in-gcc-4-7 Meta Discuss the workings and policies of this site About Us Learn more about Stack 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 undefined reference like you, helping each other. Join them; it only takes a minute: Sign up undefined reference to `main' error in gcc 4.7 up vote -1 down vote favorite I created a program in C and I tried to compile it. When I use my gcc 4.8.1 compiler in Widows everything worked and my program too. I undefined reference to compiled with the following arguments: gcc -std=c99 -O2 -DCONTEST -s -static -lm children.c But in linux I getting the following error: /usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: error: ld returned 1 exit status Why is that? My programm is working and I can't understand why I getting compiling errors in linux. My code is: /*---------------------*/ /* included files */ /*---------------------*/ #include