Compile 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 Us Learn more about Stack Overflow the company Business Learn more about undefined reference error in c compilation hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Arduino Error Compiling Undefined Reference
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 c++ error Join them; it only takes a minute: Sign up C Program Compile Error: Undefined reference to function 'compare'? up vote -2 down vote favorite Here is my code: #include because people are importing functions from different files. These two functions are in the same file, and the compare() function is declared before the main(). I would appreciate any help as to why I am getting this error. Thank you for your time. c function compiler-errors share|improve this question edited Sep 17 '14 at 21:37 Niall 19.5k85083 asked Sep 16 '14 at 6:11 LurkDog 1116 2 Nested functions in C is a compiler-specific extension. Using it will only lead to trouble (as you can see), don't use it. –Joachim Pileborg Sep 16 '14 at 6:13 2 Move the function to outside main's scope. –Maroun Maroun Sep 16 '14 at 6:14 Move function definition to outside of main. –Anbu.Sankar Sep 16 '14 at 6:16 Regarding nested functions in C: stackoverflow.com/questions/666586/…. –R Sahu Sep 16 '14 at 6:16 Where did you see an example that indicated you could nest functions in C? Whatever it is, stop using that reference. –Jonathon Reinhart Sep 16 '14 at 6:20 add a comment| 6 Answers 6 active oldest votes up vote 2 down vote You must define function outside the main function. your code should be: #include here for a quick overview of the site Help Center Detailed answers to any questions you c++ undefined reference to constructor might have Meta Discuss the workings and policies of this site undefined reference to c++ static variable 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 http://stackoverflow.com/questions/25861747/c-program-compile-error-undefined-reference-to-function-compare 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: 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 http://stackoverflow.com/questions/14557657/linker-error-c-undefined-reference 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 tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might http://electronics.stackexchange.com/questions/148616/undefined-reference-to-errors-trying-to-compile-with-make have Meta Discuss the workings and policies of this site About http://www.keil.com/support/docs/3136 Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Electrical Engineering Questions Tags Users Badges Unanswered Ask Question _ Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering undefined reference professionals, students, and enthusiasts. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top 'undefined reference to' errors trying to compile with Make up vote 1 down vote favorite I had a working undefined reference to Makefile that successfully compiled and built a basic program to toggle and LED on my stm32-h103 board. I have since attempted to add and use FreeRTOS in my program. I have added in the FreeRTOS paths into my Makefile however I am getting the following errors when I run make. src/app.a(startup.o):(.isr_vectors+0x2c): undefined reference to `vPortSVCHandler' src/app.a(startup.o):(.isr_vectors+0x38): undefined reference to `xPortPendSVHandler' src/app.a(startup.o):(.isr_vectors+0x3c): undefined reference to `xPortSysTickHandler' src/app.a(main.o): In function `main': /home/matthew/Work/22_ARM-Firmware/HomeAutomationControllerPrototype/src/main.c:36: undefined reference to `xTaskGenericCreate' /home/matthew/Work/22_ARM-Firmware/HomeAutomationControllerPrototype/src/main.c:37: undefined reference to `vTaskStartScheduler' collect2: error: ld returned 1 exit status I am very new to Makefiles so am unsure what else I must add to get the code to compile. My two make files are: Makefile.common TOP=$(shell readlink -f "$(dir $(lastword $(MAKEFILE_LIST)))") PROGRAM=main LIBDIR=$(TOP)/libs FREERTOSDIR=$(TOP)/src/FreeRTOS/Source #Adust the following line to the library in use STMLIB=$(LIBDIR)/STM32F10x_StdPeriph_Lib_V3.6.1/Libraries #Adjust TypeOfMCU in use, see CMSIS file "stm32f10x.h" #STM32F103RBT (128KB FLASH, 20KB RAM) --> STM32F10X_MD TypeOfMCU=STM32F10X_MD #STM32F103RET (512KB FLASH, 64KB RAM) --> STM32F10X_HD #TypeOfMCU=STM32F10X_HD TC=arm-none-eabi CC=$(TC)-gcc LD=$(TC)-ld -v OBJCOPY=$(TC)-objcopy AR=$(TC)-ar GDB=$(TC)-gdb INCLUDE=-I$(TOP)/inc INCLUDE+=-I$(STMLIB)/CMSIS/Incl 30 Days In the Last 90 Days In the Last 6 Months 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 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 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 IDE and Debugger Hardware & Collateral ULINK Debug Adaptors Evaluation Boards PC++ Undefined Reference To Class
C++ Undefined Reference To Winmain 16