Results 1 to 5 of 5

Thread: Makefile to separate files in C

  1. #1
    Join Date
    Mar 2010
    Posts
    184

    Makefile to separate files in C

    Hello,
    I would like to compile a makefile that separate files. I read some tutorials, do some tests but I can not do. I want to compile for three files. I can not find any solution for this. If you guys have done this before, then please let me know. Thanks in advance. Also, any example will be appreciated.
    www.techarena.in

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: Makefile to separate files in C

    Hello,
    See if this example can help you.
    Here is the code
    Code:
    all: program PROG2 prog3
    
    program: program.c
    gcc-o program program.c
    
    PROG2: program2.c
    gcc-o program2.c PROG2
    
    prog3: prog3.c
    gcc prog3.c prog3, o
    Also, if you want to compile everything, simply type make. If you want to compile only prog3, you can type make prog3

  3. #3
    Join Date
    Dec 2009
    Posts
    296

    Re: Makefile to separate files in C

    Hello,
    Even i do have a similar kind of a problem. Even i am looking to compile a group of file to create a makefile. By cons I know where I read it, but it was said on a site that was not nice to make the kind MakeFile. And I do not know in advance how much is the size of the file. I would like to compile the example foo *. c. But unfortunately this is not working. If you have a solution for this then it is appreciated. Thanks in advance.

  4. #4
    Join Date
    Nov 2009
    Posts
    583

    Re: Makefile to separate files in C

    Hello,
    I understood that you did not want to compile only 3 files. In this case, we must instead do something like this:
    Here is the code
    Code:
    CC=gcc
    EXECTE=prog PROG2 prog3
    
    all: ${EXECTE}
    
    %. O:%. C
    	${CC} $< -O $@
    
    clean:
    rm ${EXECTE}
    Though I am not sure that this is what you want.

  5. #5
    Join Date
    Nov 2009
    Posts
    330

    Re: Makefile to separate files in C

    Hello,
    See if this example interests you
    Please take a look at the code
    Code:
    CC=gcc 
    CFLAGS=-Wall
    main: main.o hello_fn.o
    
    clean:
    	rm -f main main.o hello_fn.o
    I hope that the above code will help you.

Similar Threads

  1. Replies: 7
    Last Post: 15-06-2011, 07:39 AM
  2. Replies: 4
    Last Post: 16-04-2011, 02:49 AM
  3. How can I zip 100 file as separate zipped files with WinRar?
    By aamirKhan in forum Windows Software
    Replies: 6
    Last Post: 30-08-2010, 11:22 AM
  4. Execution of a makefile in C
    By Brake Fail in forum Software Development
    Replies: 4
    Last Post: 17-04-2009, 06:46 PM
  5. Command line tool to convert VC project files to Makefile
    By Harman in forum Software Development
    Replies: 3
    Last Post: 25-10-2008, 05:19 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,664,981,248.75423 seconds with 17 queries