Linker Error Undefined
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
Undefined Reference To C++ Error
Learn more about Stack Overflow the company Business Learn more about hiring developers undefined reference to function c++ or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack
C++ Undefined Reference To Class
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 C++ “undefined reference ” [duplicate] up undefined reference error in c 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
error message (or “unresolved external symbol, for Visual C++ users). This is not actually a message from the compiler, but is emitted
C++ Undefined Reference To Constructor
by the linker, so the first thing to do is to understand undefined reference to static variable c++ what the linker is, and what it does. Linker 101 To understand the linker, you have to understand
Undefined Reference To C++ Linux
how C++ programs are built. For all but the very simplest programs, the program is composed of multiple C++ source files (also known as “translation units”). These are compiled separately, http://stackoverflow.com/questions/14557657/linker-error-c-undefined-reference using the C++ compiler, to produce object code files (files with a .o or a .obj extension) which contain machine code. Each object code file knows nothing about the others, so if you call a function from one object file that exists in another, the compiler cannot provide the address of the called function. This is where the the linker https://latedev.wordpress.com/2014/04/22/common-c-error-messages-2-unresolved-reference/ comes in. Once all the object files have been produced, the linker looks at them and works out what the final addresses of functions in the executable will be. It then patches up the addresses the compiler could not provide. It does the same for any libraries (.a and .lib files) you may be using. And finally it writes the executable file out to disk. The linker is normally a separate program from the compiler (for example, the GCC linker is called ld) but will normally be called for you when you use your compiler suite’s driver program (so the GCC driver g++ will call ld for you). Traditionally, linker technology has lagged behind compilers, mostly because it’s generally more fun to build a compiler than to build a linker. And linkers do not necessarily have access to the source code for the object files they are linking. Put together, you get a situation where linker errors, and the reasons for them, can be cryptic in the extreme. Undefined reference Put simply, the “undefined reference” error means you hav
30 Days In the Last 90 Days In the Last 6 http://www.keil.com/support/docs/3136 Months Technical Support Overview Search Contact Assistance Request Feedback Support http://www.cplusplus.com/forum/beginner/25188/ 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: undefined reference LINKER 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 undefined reference to missing. class 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 C
files, but I didn't figure out how I can make the main program work. The errors that appear (when I try to compile the source files) are: 1. median.cpp 1
2
[Linker error] undefined reference to `WinMain@16' ld returned 1 exit status 2. grade.cpp 1
2
3
[Linker error] undefined reference to `median(std::vector<double, std::allocator<double> >)' [Linker error] undefined reference to `WinMain@16' ld returned 1 exit status 3. student_info.cpp 1
2
[Linker error] undefined reference to `WinMain@16' ld returned 1 exit status 4. 4_data_headers_partitioning.cpp (the main program) 1
2
3
4
[Linker error] undefined reference to `read(std::istream&, Student_info&)' [Linker error] undefined reference to `compare(Student_info const&, Student_info const&)' [Linker error] undefined reference to `grade(Student_info const&)' ld returned 1 exit status I attached the source files here: http://www.2shared.com/file/US8dNvZz/partitioning.html Can you help me a little? What I do wrong? Or what I omit? Thanks in advance for your help. (I'm using dev c++ 4.9.9.2 under windows) Jun 19, 2010 at 1:14pm UTC magnificence7 (188) I can't find where to download your files, maybe posting it helps? Anyway, are you sure you've compiled all your source files before linking? Jun 20, 2010 at 1:55am UTC Zhuge (4639) It seems like you are trying to compile all the cpp files as separate programs (hence, looking for WinMain in the other cpps). I don't know how dev c++ works, but there is probably a way to specify a "project" or something that indicates that your files are together a single program. Jun 20, 2010 at 1:56pm UTC Duoas (10453) Yes, start Dev-C++ and create a new Project. Add your main program's cpp file, then add the other cpp files you intend to use in your project. Make sure you create a "