Makefile Error Undefined Reference To Main
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 make undefined reference to function About Us Learn more about Stack Overflow the company Business Learn more about
Makefile Undefined Reference To Function
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join in function _start undefined reference to main 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 makefile give error undefined reference
Undefined Reference To Main' C++
to 'main' up vote 0 down vote favorite Makefile: all: a.out a.out: b.o a.o gcc -o b.o a.o a.o: a.c gcc -c a.c b.o: b.c gcc -c b.c .PHONY:clean clean: rm *.o a.out with make, give information: error: undefined reference to 'main' collect2: ld return 1 make: * [a.out] error 1 But when put source file a.c and b.c into Eclipse CDT, it compiles well. linker input file unused because linking not done Please explain what is wrong with my makefile? PS: a.c: int global_1 = 100; b.c: extern int global_1; int main() { int global_2 = global_1 * 2; return 0; } c makefile share|improve this question asked Sep 6 '13 at 14:27 lulyon 3,00531638 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted This rule doesn't specify the correct result file: a.out: b.o a.o gcc -o b.o a.o It should be a.out: b.o a.o gcc -o "$@" b.o a.o That's what you get for violating one of Paul's Rules of Makefiles. BTW, it's not the makefile that "gives the error", it's the compilation, specifically the linker. share|improve this answer answered Sep 6 '13 at 14:29 Jens 36.4k863105 add a comment| up vote 0 down vote This: a.out: b.o a.o gcc -o b.o a.o \----/ | | this says "name the output b.o" is overwriting the b.o object file with the output file. I'm pretty sure make is clever enough to figure the required command out without any input, so try deleting the second line. share|improve this answer answered Sep 6 '13 at 14:29 unwind 255k38332460 Sorry, when d
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 developers or posting ads
Makefile In C
with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the
C++ Undefined Reference To
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: makefile syntax Sign up Undefined reference maybe makefile is wrong? up vote 2 down vote favorite 1 I had some issues earlier with declaring my array set of records. Now I think there is something wrong with my Makefile or something. Here is http://stackoverflow.com/questions/18660141/makefile-give-error-undefined-reference-to-main my Makefile: EEXEC = proj1 CC = gcc CFLAGS = -c -Wall $(EXEC) : main.o set.o $(CC) -o $(EXEC) main.o set.o main.o : main.h main.c $(CC) $(CFLAGS) main.c set.o : set.h set.c $(CC) $(CFLAGS) set.c There are more functions I have in my set.c file but these are the functions I am testing at the moment: DisjointSet *CreateSet(int numElements); DisjointSet *MakeSet(DisjointSet *S,int ele, int r); void Print(DisjointSet *S); And the errors I am receiving in the terminal is: main.o: In function `main': main.c:(.text+0x19): http://stackoverflow.com/questions/4130681/undefined-reference-maybe-makefile-is-wrong undefined reference to `CreateSet' main.c:(.text+0x43): undefined reference to `MakeSet' main.c:(.text+0x5f): undefined reference to `Print' c makefile share|improve this question edited Nov 9 '10 at 5:18 asked Nov 9 '10 at 5:04 Jeremy 64228 1 Highlight and press the 0101 button for code formatting :) –Scott Wales Nov 9 '10 at 5:17 Fixed that, most of it. Still getting use to the formatting. –Jeremy Nov 9 '10 at 5:19 add a comment| 3 Answers 3 active oldest votes up vote 5 down vote accepted The errors that you're getting are linker errors, telling you that while linking your program the linker can't find a function named 'CreateSet' (etc.). It's not immediately obvious why that should be the case, because it appears that you're including "set.o" in the build command. To troubleshoot build problems, it's often useful to figure out what make is trying to do, and then run the commands individually one at a time so you can see where things go wrong. "make -n" will show you what commands "make" would run, without actually doing them. I would expect to see a command like: gcc -o proj1 main.o set.o try running that by hand and see where it gets you. share|improve this answer answered Nov 9 '10 at 5:44 David Gelhar 24.5k35270 That worked! How do I reflect this in the Makefile? –Jeremy Nov 9 '10 at 5:48 For starters, fix the inconsistency between EXEC and EEXEC. Otherwise,
tour help Tour Start here for a quick overview of the site Help Center Detailed answers to http://electronics.stackexchange.com/questions/148616/undefined-reference-to-errors-trying-to-compile-with-make 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 developers or posting ads with us Electrical Engineering Questions Tags Users Badges Unanswered Ask Question _ Electrical Engineering Stack Exchange is a undefined reference question and answer site for electronics and electrical engineering 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 undefined reference to compile with Make up vote 1 down vote favorite I had a working 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 CMS