Thread: MakeFile not working

  1. #1
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693

    MakeFile not working

    Code:
    hellomake: hellomake.c hellofunc.c hellomake.h
    	gcc -o hellomake hellomake.c hellofunc.c -I.
    thats the makefile and here are the files

    Code:
    #include "hellomake.h"
    #include<stdio.h>
    
    void myPrintHelloMake(void) {
    
      printf("Hello makefiles!\n");
    
      return;
    }
    hellomake.h
    Code:
    /*
    example include file
    */
    
    void myPrintHelloMake(void);

    Code:
    #include <stdio.h>
    
    int main() {
      // call a function in another file
      myPrintHelloMake();
    
      return(0);
    }
    last one is hellomake.c



    I am typing in make and it says no makefile found

  2. #2
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    try make -f <makefile name>

  3. #3
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    that compiled my code but now when I type make it still doesnt execute it

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    rmatze is right. You probably didn't name your make file with a standard name that make recognizes. The typical name is just "Makefile", if you don't use a standard name, you need to specify what make file you want with the -f command.

    Also note:
    1. Your organization is a bit backwards. You should rename hellomake.h to hellofunc.h, since it has the prototype for the function in hellofunc.c.
    2. You need to include hellofunc.h in hellomake.c, the file where you actually call the function, not hellofunc.c where you define it (see footnote).
    3. Since the prototype is included in hellomake.c, but refers to a function in an external .c file (hellofunc.c), you need to use the extern keyword: extern void myPrintHelloMake(void);
    4. You should use include guards for every header file you make: Include guard - Wikipedia, the free encyclopedia.


    Footnote: If you compile with the warnings set to high, you would have seen a message about this. Add the -Wall option to the gcc command in your make file.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by camel-man View Post
    that compiled my code but now when I type make it still doesnt execute it
    Running make wont execute hellomake unless you tell it to. This is normally not done, since make is generally used for building/compiling, not running arbitrary programs. If you really want to run the program via the make file, you need to add it to the make file:
    Code:
    $ cat Makefile
    hellomake: hellomake.c hellofunc.c hellomake.h
            gcc -Wall -o hellomake hellomake.c hellofunc.c -I.
            ./hellomake
    $ make
    gcc -Wall -o hellomake hellomake.c hellofunc.c -I.
    ./hellomake
    Hello makefiles!
    If you want to run your program like a normal person, just do:
    Code:
    $ ./hellomake
    Hello makefiles!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with Makefile
    By kiros88 in forum C Programming
    Replies: 1
    Last Post: 05-26-2010, 12:43 PM
  2. Makefile
    By vin_pll in forum C++ Programming
    Replies: 2
    Last Post: 01-12-2010, 12:14 AM
  3. Replies: 9
    Last Post: 03-30-2009, 04:09 AM
  4. difference makefile makefile.am makefile.in
    By Bargi in forum Linux Programming
    Replies: 7
    Last Post: 10-28-2007, 02:08 PM
  5. help with makefile
    By metsman20 in forum Linux Programming
    Replies: 0
    Last Post: 04-20-2003, 01:38 PM