Linker Error Undefined Reference To C Programming
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and linker error undefined reference to function in c policies of this site About Us Learn more about Stack Overflow the
Undefined Reference Error In C
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users
Undefined Reference To Function C++
Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes
Linker Error C++
a minute: Sign up Linker Error C++ “undefined reference ” [duplicate] up vote 9 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 c++ linker error unresolved external symbol returned 1 exit status main.cpp #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 how to solve undefined reference error in c developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask undefined reference to static library function Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join undefined reference to constructor them; it only takes a minute: Sign up Linking error: Undefined reference to functions that're defined in a separate file? up vote 1 down vote favorite I'm probably forgetting something obvious that'll solve this. While there's other questions on http://stackoverflow.com/questions/14557657/linker-error-c-undefined-reference SO with the same issue, none of the solutions have been applicable to my situation. I have a main file, sim.c, a header file net.h, a header file friends.h, and a file with the functions, net.c. I have a makefile, which I created with gmakemake > Makefile, and its contents are very basic. Header.mak (makefile template): CFLAGS = -Wall -Wextra -pedantic -std=c99 -ggdb LFLAGS = -ggdb LDFLAGS = Makefile relevant contents: CPP_FILES = C_FILES = net.c sim.c PS_FILES = http://stackoverflow.com/questions/26820736/linking-error-undefined-reference-to-functions-thatre-defined-in-a-separate-fi S_FILES = H_FILES = net.h friends.h SOURCEFILES = $(H_FILES) $(CPP_FILES) $(C_FILES) $(S_FILES) .PRECIOUS: $(SOURCEFILES) OBJFILES = # # Main targets # all: net sim net: net.o $(OBJFILES) $(CC) $(CFLAGS) -o net net.o $(OBJFILES) $(CLIBFLAGS) sim: sim.o $(OBJFILES) $(CC) $(CFLAGS) -o sim sim.o $(OBJFILES) $(CLIBFLAGS) # # Dependencies # net.o: net.h sim.o: net.h My sim.c file contains: #include "net.h" #include "friends.h" My header file contains the functions in net.c and defines them all as stubs. I copied and pasted them to create the function headers, so there shouldn't be any typos. My net.c file contains: #include "net.h" Yet any time a function in sim.c tries to call a function in net.c, it errors on that line with: "undefined reference to `function_name`". How can I make sim.c able to access the functions in net.c? c makefile share|improve this question edited Nov 8 '14 at 19:04 asked Nov 8 '14 at 18:44 Rohawk 11210 add a comment| 2 Answers 2 active oldest votes up vote 0 down vote accepted The message undefined reference to 'function_name' implies that of all the object files you're giving to the linker, none of them has a definition for function_name. That means that either You're not linking with net.o net.c (as compiled) does not contain a definition for function_name -- by 'as compiled' I mean with all of the various preprocessor options you use on it. Since you show neither your l
Programming Boards C++ Programming linker error undefined reference to Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get http://cboard.cprogramming.com/cplusplus-programming/90936-linker-error-undefined-reference.html a compiler | Fixes for common problems Thread: linker error undefined reference to Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 06-18-2007 #1 BJtoVisualcC++ View Profile View Forum Posts Registered User Join Date Jun 2007 Posts 61 linker error undefined reference to I am getting errors saying linker error undefined reference to (function name) undefined reference what does this mean? How can I correct it? 06-18-2007 #2 robwhit View Profile View Forum Posts Registered User Join Date Oct 2001 Posts 2,129 it means you didn't write out what that function did, or you didn't link in the correct library. 06-18-2007 #3 Salem View Profile View Forum Posts and the hat of int overfl Join Date Aug 2001 Location The edge of the known universe Posts undefined reference to 34,493 It means one of these (typically) - you need to write the function. - you need to check the spelling - C++ is case sensitive, so 'foo' is different from 'Foo'. - you need to check the parameters - declaring foo(int a) and defining foo(double a) are different functions. - you forgot to specify the name of a library. If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. If at first you don't succeed, try writing your phone number on the exam paper. 06-18-2007 #4 Daved View Profile View Forum Posts Registered User Join Date Jan 2005 Posts 7,363 It could also mean that you forgot to include in the project the file that has the function definition. Or if the function is a member function of a class, perhaps you forgot the ClassName:: in the definition. Quick Navigation C++ Programming Top Site Areas Settings Private Messages Subscriptions Who's Online Search Forums Forums Home Forums General Programming Boards C++ Programming C Programming C# Programming Game Programming Networking/Device Communication FAQ Board Programming Book and Product Reviews Platform Specific Boards Windows Programming Linux Programming Cprogramming.com and AIHorizon.com's Artificial Intelligence Boards General AI Programming Community Boards Article Discussio