Linker Error Undefined Reference To Function
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 undefined reference error in c company Business Learn more about hiring developers or posting ads with us Stack Overflow undefined reference to c++ error Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2
Undefined Reference To Function C++
million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up What causes the error “undefined reference to (some function)”? [duplicate] up vote 7 down vote favorite This question already
C++ Undefined Reference To Class
has an answer here: What is an undefined reference/unresolved external symbol error and how do I fix it? 25 answers I get the error: main.o(.text+0x1ed): In function `main': : undefined reference to `avergecolumns' collect2: ld returned 1 exit status when I gcc *.o. I'm not quite sure what causes this error. Other posters have explained it as the function is not found or the function is empty. If someone could clarify or refine, c++ undefined reference to constructor it would be greaty appreciated! Here is my function's code(I'm trying to calculate the average of the column in 2D arrays): #include "my.h" void averagecolumns (int x, int y, int** a) { int i; int j; float sum; float colAvg; sum = 0; colAvg = 0; printf("i. The column averages are: \n"); for(i = 0; i < x; i++) { for(j = 0; j < y; j++) { sum += a[i][j]; colAvg = sum / (float)x; } printf("Column: %3d, Average: %6.2f", j, colAvg); sum = 0; colAvg = 0; } The relavent parts of main are: #include "my.h" int main (int argc, char* argv[]) { int** a; float** colAvg; int ROWS; int COLS; int i; int j; int** table; FILE* fpmyfile; int closeResult; .... printme (ROWS, COLS, a); // call functions a - j oddvalues (ROWS, COLS, a); oddlocations (ROWS, COLS, a); countoddrows (ROWS, COLS, a); addrows (ROWS, COLS, a); findfirstsmall (ROWS, COLS, a); findlastlarge (ROWS,COLS, a); addcolumns (ROWS, COLS, a); avergecolumns (ROWS, COLS, a); .... } Also, is this a linker or a compile error (I wasn't sure which tag to add). c linker-error share|improve this question edited Nov 6 '11 at 0:49 Kerrek SB 284k40517750 asked Nov 6 '11 at 0:42 Piseagan 114239 marked as duplicate by PlasmaHH, JasonMArcher, Michael Walz, Ivan Ferić, Oz123
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 Static Variable C++
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions undefined reference to c++ linux Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million c++ undefined reference to function in class 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 favorite I'm probably forgetting http://stackoverflow.com/questions/8024440/what-causes-the-error-undefined-reference-to-some-function 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 = -Wall -Wextra -pedantic -std=c99 -ggdb LFLAGS http://stackoverflow.com/questions/26820736/linking-error-undefined-reference-to-functions-thatre-defined-in-a-separate-fi = -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 function_name. That means that either You're not linking with net.o net.c (as compil
30 Days In the Last 90 Days In the Last 6 Months http://www.keil.com/support/docs/3136 Technical Support Overview Search Contact Assistance Request Feedback Support Resources Support Knowledgebase Article Index Top 10 Articles Product Manuals Application Notes Downloads Product Updates Discussion Forum Books Product Information Software & Hardware Products ARM Development ToolsC166 Development ToolsC51 Development ToolsC251 Development ToolsDebug AdaptersEvaluation Boards Product Brochures Newsletters Home/Technical Support GCC: LINKER undefined reference ERROR (UNDEFINED REFERENCE WITH C++) Information in this article applies to: GNU C Compiler for ARM All Versions SYMPTOM The GNU linker gives error messages while linking an application which contains class declarations and class instances. CAUSE The class declaration specifies a constructor and/or destructor, but the constructor/destructor function is missing. class undefined reference to clf { public: clf(); // Constructor (ctor) ~clf(); // Destructor (dtor) int n1, n2, n3; }; clf clf1; // class object int main (void) { return (0); } The linker gives the error messages which look like the following ones: .\obj\blinky.o(.text+0x40): In function '__static_initialization_and_destruction_0': /cygdrive/c/Keil/ARM/GNU/Examples/Blinky/blinky.cpp(92): error: undefined reference to 'clf::~clf [in-charge]() 'blinky.o' (.text+0x44):blinky.cpp:92: undefined reference to 'clf::clf[in-charge]()' RESOLUTION Add the constructor(s) and/or destructor(s) as shown below: class clf { public: clf(); // Constructor (ctor) ~clf(); // Destructor (dtor) int n1, n2, n3; }; clf::clf () { // define ctor n1 = n2 = n3 = 0; } clf::~clf() { // define dtor } clf clf1; // class object int main (void) { return (0); } SEE ALSO µVision DEBUGGER: SOURCE LEVEL DEBUGGING WITH GNU ARM Last Reviewed: Monday, December 10, 2012 Did this article provide the answer you needed? Yes No Not Sure Products Development Tools ARM C166 C51 C251 µVision