C Linking Error Undefined Reference
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 linking error undefined reference to function Us Learn more about Stack Overflow the company Business Learn more about hiring linker error undefined reference to winmain@16' dev c++ developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the
Linker Error Undefined Reference To __chkstk_ms'
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 Undefined reference to '_*' linker error
Linker Error Undefined Reference To Wsastartup@8'
up vote 0 down vote favorite I am having trouble compiling/linking the following C code. The linker throws errors that look like the following: pso.o:pso.c:(.text+0x41): undefined reference to '_ps' ... pso.o:pso.c:(.text+0x93): more undefined references to '_ps' follow This is my first time writing C code for gcc, so I'm unsure how to fix this problem. I am assuming that because struct PS is defined my header linker error undefined reference to __cpu_features_init file, it is somehow not linked to pso.c. However, I did use a #include "ps.h" statement at the top of that source file. I have included the relevant source files and header file below, as well as the make file I am using. Is there a fundamental concept I am missing for writing linkable C code? Thank you! Oh, and it's a particle swarm optimizer, if you were wondering :) The main.c file: #define MAIN #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 Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges linker error undefined reference to 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. undefined reference to function error in c 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 topic, and unfortunately they have not helped me. http://stackoverflow.com/questions/15257120/undefined-reference-to-linker-error 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; } Any thoughts on why I might get this error? Thanks! c linker http://stackoverflow.com/questions/15905119/c-linking-error-undefined-reference-to-main share|improve this question edited Apr 9 '13 at 14:53 unwind 253k38330460 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 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 answered Apr 9 '13 at 14:52 unwind 253k38330460 add a comment| up vote 1 down vote You are overwriting your object file runexp.o by r here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies http://stackoverflow.com/questions/14557657/linker-error-c-undefined-reference 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 like you, helping each other. Join them; it only takes a minute: undefined reference Sign up Linker Error C++ “undefined reference ” [duplicate] up vote 8 down vote favorite 2 Possible Duplicate: What is an undefined reference/unresolved external symbol error and how do I fix it? Trying to compile my program via g++ -o prog1 main.cpp -std=c++0x I get the error: /tmp/cc1pZ8OM.o: In function `main': main.cpp:(.text+0x148): undefined reference to `Hash::insert(int, char)' collect2: error: ld returned 1 undefined reference to exit status main.cpp #include Undefined Reference To Static Library Function