Makefile for more than 1 executable program


 
Thread Tools Search this Thread
Top Forums Programming Makefile for more than 1 executable program
# 1  
Old 01-14-2010
Makefile for more than 1 executable program

Can anyone give me a makefile that creates 3 exe?for example, let's suppose i have the following files:

blah1.c
blah1.h

blah2.c
blah2.h

blah3.c
blah3.h

i've searched and searched but so far i was not able to complete it.
# 2  
Old 01-14-2010
Assuming you're using GNU make:
Code:
SRC=blah1.c blah2.c blah3.c
HDR=$(SRC:.c=.h)
OBJ=$(SRC:.c=.o)

PROG=$(SRC:.c=)

all: $(PROG)

$(PROG): $(OBJ)
        gcc -Wall -ggdb -o $@ $@.o

.c.o: $(SRC) $(HDR)
        gcc -Wall -ggdb -c $<

clean:
        rm -f $(PROG) $(OBJ)

Adjust the compile options as needed.
# 3  
Old 01-14-2010
Quote:
Originally Posted by pludi
Assuming you're using GNU make:
Code:
SRC=blah1.c blah2.c blah3.c
HDR=$(SRC:.c=.h)
OBJ=$(SRC:.c=.o)

PROG=$(SRC:.c=)

all: $(PROG)

$(PROG): $(OBJ)
        gcc -Wall -ggdb -o $@ $@.o

.c.o: $(SRC) $(HDR)
        gcc -Wall -ggdb -c $<

clean:
        rm -f $(PROG) $(OBJ)

Adjust the compile options as needed.
can you explain that?what changes i need to do in your example above in order to make it work properly?sorry for asking again,but i just began using makefiles.
# 4  
Old 01-14-2010
I meant that you'll probably have to change the lines invoking gcc to reflect the compile options you're using.
# 5  
Old 01-14-2010
ok i think i got it.thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Error when run makefile to compile C program

I have a make file for C program, which always gives the error ld: 0711-738 ERROR: Input file ../src/file_name.o XCOFF32 object files are not allowed in 64 mode Does anybody know the problem? Thanks for contribution (2 Replies)
Discussion started by: digioleg54
2 Replies

2. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

3. Shell Programming and Scripting

To see if a program exist and is executable

Hi, I am making a program that needs to detect if the program name in parameter is a valid runable program. But the line if ; then never seem to work. Even if I run like: ./script cat "-u" cat "-u" inputfile Thank you everyone. #!/bin/bash # usage() { #print usage message and quit... (4 Replies)
Discussion started by: leonmerc
4 Replies

4. Programming

Call a C programming executable inside a C program

hi guys i have only basic knowledge of C so guys plz help me ..... is C language support call the C executable inside the C ?? example contect mainA.c have a many function define in the struct,when i compile mainA and make a executable the name is ( A ),can i use executable C inside the C... (5 Replies)
Discussion started by: isnoname
5 Replies

5. Programming

how to call c executable inside c program??

hi guys i have only basic knowledge of c so guys plz help me ..... i want 2 call c executable which requires file name as argument and i need to modify file contents before calling that executable now my question is how can i call this c executable inside another c program with arguments ?? i... (9 Replies)
Discussion started by: zedex
9 Replies

6. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

7. Programming

Makefile compilation Error -Unable to create executable

Hi , While trying to compile a PRO*C code on unix using makefile i get the following errors. i am now working on a 10g migration (from 8i) ... these makefile perfectly work in previous version. ld: fatal: file... (7 Replies)
Discussion started by: sivalives
7 Replies

8. Programming

Client and Server program gen by Makefile

I created a "ebanking.x" file and run it as " rpcgen -a ebaning.x" It gen a few of files to me which is - "ebanking.h", "ebanking_server.c", "ebanking_svc.c", "ebanking_client.c", "ebanking_clnt.c", "ebanking_xdr.c" and "Makefile" The content of "ebanking.x" : struct bankargs { ... (0 Replies)
Discussion started by: wongalan48
0 Replies

9. Programming

problem in creating executable for a client program

Hi, I am trying to run simple client server c program in unix.At the compling stage server is creating an executable but the client is not. below is the link to the source codes: http://www.cs.rpi.edu/courses/sysprog/sockets/server.c http://www.cs.rpi.edu/courses/sysprog/sockets/client.c ... (2 Replies)
Discussion started by: konas
2 Replies

10. Programming

launch an executable from a C++ program

Hi everybody! Could you please tell me how can I launch an executable from a C++ (on unix) program? thanks in advance! (2 Replies)
Discussion started by: nadiamihu
2 Replies
Login or Register to Ask a Question