Linking Error In C Undefined Reference
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta undefined reference error in c Discuss the workings and policies of this site About Us Learn
Linker Error Undefined Reference To Function In C
more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack error undefined reference to c++ Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, undefined reference error in c compilation helping each other. Join them; it only takes a minute: Sign up Undefined reference to '_*' linker error 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
Undefined Reference To Static Library Function
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 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 how to solve undefined reference error in c the company Business Learn more about hiring developers or posting ads with us Stack error undefined offending command Overflow Questions Jobs Documentation Tags Users 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 a minute: Sign up Linking error: Undefined reference to functions that're defined in a separate file? up vote 1 down vote http://stackoverflow.com/questions/15257120/undefined-reference-to-linker-error favorite I'm probably forgetting something obvious that'll solve this. While there's other questions on 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 = http://stackoverflow.com/questions/26820736/linking-error-undefined-reference-to-functions-thatre-defined-in-a-separate-fi -Wall -Wextra -pedantic -std=c99 -ggdb LFLAGS = -ggdb LDFLAGS = Makefile relevant contents: CPP_FILES = C_FILES = net.c sim.c PS_FILES = 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 funct 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 http://stackoverflow.com/questions/14557657/linker-error-c-undefined-reference 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 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Linker Error undefined reference 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 returned 1 exit status main.cpp #include Undefined Reference To Function C++