15 Replies - 564 Views - Last Post: 27 November 2019 - 11:31 AM
#1
makefiel problem starting
Posted 13 November 2019 - 02:10 PM
hi,
so i started to learn c programing with ubunto ...
and what i need to build a program that solves some functions
i have 4 files
1-The realization of 2 functions
2-Statement of the functions and constants
3-main
4-The realization of another 2 functions
so i did all this 4 files.c and the statement i did xxx.h
now i need to build a Makefile with the following commands:
• mymaths make on the compiler to create the static directory a.libmyMath that contains all of your functions.
• mymathd make on the compiler to create the so.libmyMath dynamic directory that contains all of your functions.
• mains make On the compiler create your main program called mains when it is linked to the static directory. If the library already exists, it should not be compiled again.
• maind make The compiler has to create your master maind program when it is linked to a dynamic directory. If the library already exists, it should not be compiled again.
• all make will compile all your libraries and programs.
• clean make will clear the folder from all folded files and leave only txt .c .h files.
i did this:(add picture)
and that not work for me . please help i stuck with that!
thanks
so i started to learn c programing with ubunto ...
and what i need to build a program that solves some functions
i have 4 files
1-The realization of 2 functions
2-Statement of the functions and constants
3-main
4-The realization of another 2 functions
so i did all this 4 files.c and the statement i did xxx.h
now i need to build a Makefile with the following commands:
• mymaths make on the compiler to create the static directory a.libmyMath that contains all of your functions.
• mymathd make on the compiler to create the so.libmyMath dynamic directory that contains all of your functions.
• mains make On the compiler create your main program called mains when it is linked to the static directory. If the library already exists, it should not be compiled again.
• maind make The compiler has to create your master maind program when it is linked to a dynamic directory. If the library already exists, it should not be compiled again.
• all make will compile all your libraries and programs.
• clean make will clear the folder from all folded files and leave only txt .c .h files.
i did this:(add picture)
and that not work for me . please help i stuck with that!
thanks
Replies To: makefiel problem starting
#2
Re: makefiel problem starting
Posted 13 November 2019 - 02:16 PM
#3
Re: makefiel problem starting
Posted 13 November 2019 - 02:29 PM
New folk don't have that access level yet.
Please copy/paste your code the post (and make sure to use the 'code' tag button in the editor).
Please copy/paste your code the post (and make sure to use the 'code' tag button in the editor).
#4
Re: makefiel problem starting
Posted 13 November 2019 - 03:17 PM
CC=gcc FLAGS= -g -Wall OBJECTS_MAIN=main.o OBJECTS_LIB1=basicMath.o OBJECTS_LIB2=power.o AR=ar all: mains maind mymathd mymaths mains: $(OBJECTS_MAIN) libmymath.a $(CC) $(FLAGS) $(OBJECTS_MAIN) libmymath.a maind: $(OBJECTS_MAIN) $(CC) $(FLAGS) $(OBJECTS_MAIN) libmymath.so mymathd: $(OBJECTS_LIB1) $(OBJECTS_LIB2) $(CC) -shared -o libmymath.so $(OBJECTS_LIB1) $(OBJECTS_LIB2) mymaths: $(OBJECTS_LIB1) $(OBJECTS_LIB2) $(AR) -rcs libmymath.a $(OBJECTS_LIB) $(OBJECTS_LIB2) main.o: main.c myMath.h $(CC) -c -Wall main.c basicMath.o: basicMath.c myMath.h $(CC) -c -Wall basicMath.c power.o: power.c myMath.h $(CC) -c -fPIC -Wall power.c .PHONY: clean all clean: rm -f *.o *.a *.so mymaths mymathd
#5
Re: makefiel problem starting
Posted 13 November 2019 - 06:08 PM
#6
Re: makefiel problem starting
Posted 13 November 2019 - 10:54 PM
make: *** No rule to make target 'libmymath.a', needed by 'mains'. Stop.
i just need that all the final files will be there after i did all the makefile
i post up what i need to do and i didnt know If I did properly
i just need that all the final files will be there after i did all the makefile
i post up what i need to do and i didnt know If I did properly
This post has been edited by Skydiver: 14 November 2019 - 06:51 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.
#7
Re: makefiel problem starting
Posted 14 November 2019 - 06:55 AM
That error makes perfect sense. In your make file for your mains you listed $(OBJECTS_MAIN) libmymath.a as your dependents (line 11.), but you don't have a rule for libmath.a. You do have a rule for mymaths which will create libmath.a. You should us mymaths as the dependent instead.
#8
Re: makefiel problem starting
Posted 14 November 2019 - 11:08 AM
I would instead rename the "mymaths" target to "libmymath.a". I would also rename "mymathd" to "libmymath.so".
#9
Re: makefiel problem starting
Posted 14 November 2019 - 11:19 AM
You could, but you then not be able to fulfill these parts of requirements from your original post:
doberman1, on 13 November 2019 - 04:10 PM, said:
• mymaths make on the compiler to create the static directory a.libmyMath that contains all of your functions.
• mymathd make on the compiler to create the so.libmyMath dynamic directory that contains all of your functions.
• mymathd make on the compiler to create the so.libmyMath dynamic directory that contains all of your functions.
#10
Re: makefiel problem starting
Posted 26 November 2019 - 10:07 AM
Sure, then add two targets called "mymaths" and "mymathd", which depend on "libmymath.a" and "libmymath.so", respectively. Also add a target called "PHONY" which depends on "mymaths" and "mymathd" to force make to build those targets, even if files named "mymaths" or "mymathd" happen to exist.
I find it easier to let make do its job by using the actual names of the files that will be used (as targets and dependencies), and then add other targets with more convenient names.
I find it easier to let make do its job by using the actual names of the files that will be used (as targets and dependencies), and then add other targets with more convenient names.
#11
Re: makefiel problem starting
Posted 26 November 2019 - 01:49 PM
The OP doesn't need a "PHONY" target since he already has a "all" target that has "maths" and "maths" as some of its dependencies.
#12
Re: makefiel problem starting
Posted 26 November 2019 - 05:12 PM
Yes, OP needs a .PHONY target that depends on any target that is not a file name.
See https://www.gnu.org/...ny-Targets.html.
Here's the full Makefile that I would use:
(I would also note that both the mains target and the maind target create an executable named "a.out", so they will conflict with each other if built with make all--a.out will be from whichever target is run last.)
See https://www.gnu.org/...ny-Targets.html.
Here's the full Makefile that I would use:
CC=gcc FLAGS= -g -Wall OBJECTS_MAIN=main.o OBJECTS_LIB1=basicMath.o OBJECTS_LIB2=power.o AR=ar all: mains maind mymathd mymaths mains: $(OBJECTS_MAIN) libmymath.a $(CC) $(FLAGS) $(OBJECTS_MAIN) libmymath.a maind: $(OBJECTS_MAIN) $(CC) $(FLAGS) $(OBJECTS_MAIN) libmymath.so mymathd: libmymath.so mymaths: libmymath.a libmymath.so: $(OBJECTS_LIB1) $(OBJECTS_LIB2) $(CC) -shared -o libmymath.so $(OBJECTS_LIB1) $(OBJECTS_LIB2) libmymath.a: $(OBJECTS_LIB1) $(OBJECTS_LIB2) $(AR) -rcs libmymath.a $(OBJECTS_LIB) $(OBJECTS_LIB2) main.o: main.c myMath.h $(CC) -c -Wall main.c basicMath.o: basicMath.c myMath.h $(CC) -c -Wall basicMath.c power.o: power.c myMath.h $(CC) -c -fPIC -Wall power.c .PHONY: clean all mains maind mymathd mymaths clean: rm -f *.o *.a *.so mymaths mymathd
(I would also note that both the mains target and the maind target create an executable named "a.out", so they will conflict with each other if built with make all--a.out will be from whichever target is run last.)
#13
Re: makefiel problem starting
Posted 26 November 2019 - 06:27 PM
His "all" is already his phony target. There is no need for another one.
Good point about the a.out being overwritten, though. The mains and maind should specify output files so that they don't overwrite each other.
Good point about the a.out being overwritten, though. The mains and maind should specify output files so that they don't overwrite each other.
#14
Re: makefiel problem starting
Posted 27 November 2019 - 10:34 AM
Quote
A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request. There are two reasons to use a phony target: to avoid a conflict with a file of the same name, and to improve performance.
(Emphasis mine.)
Say a file named "mymathd" somehow got created. If it's newer than libmymath.so, then running make mymathd will not run the recipe to build libmymath.so. With .PHONY: mymathd, that tells make mymathd to run the mymathd recipe anyway.
I also left out the dependency on libmymath.so for the maind recipe in my previous post:
maind: $(OBJECTS_MAIN) libmymath.so $(CC) $(FLAGS) $(OBJECTS_MAIN) libmymath.so
#15
Re: makefiel problem starting
Posted 27 November 2019 - 11:13 AM
Yes, you would need the .PHONY directive to say the just in case there is a "mymathd" file or directory that is ever created, but with the makefile as defined by the OP, there is no such possibility of that file or directory being created.
Yes, it makes the makefile more robust, but it is not required to make things work.
Also consider for the other versions of make which don't have the .PHONY directive. Are you saying that our OP will be hopelessly unable to do his homework if he was using an old SCO Unix system because that version of make didn't have .PHONY?
Yes, it makes the makefile more robust, but it is not required to make things work.
Also consider for the other versions of make which don't have the .PHONY directive. Are you saying that our OP will be hopelessly unable to do his homework if he was using an old SCO Unix system because that version of make didn't have .PHONY?