![]() |
|
#1
|
|||
|
|||
Help with creating a makefileHi there!
I've just been looking around on the forum and was hoping to learn/see the output of the two files in this tutorial: Code:
Was wondering how to do this and how I would 'compile'? Looking around, I've come up with this: Code:
Advanced thank you. |
|||
|
#2
|
|||
|
|||
Re: Help with creating a makefileQuote:
With a text editor, create a file named Makefile in the same directory as parent.c and child.c. Paste the contents of your post into that file. Quote:
1. from the command line enter: Code:
or... 2. Since the first target will be "made" if no arguments are given, simply enter: Code:
3. Execute the executable. If this is Linux or some other UNIX-like operating system, then enter the following from the command line: Code:
Regards, Dave |
|
#3
|
|||
|
|||
Re: Help with creating a makefileHi Dave
Thanks a bunch! =] I feel very noob-y at the moment. =p Ani |
|
#4
|
|||
|
|||
Re: Help with creating a makefileQuote:
Regards, Dave "I was born not knowing, and have only had a little time to change that here and there." ---Richard Feynman (1918-1988) |
|
#5
|
|||
|
|||
Re: Help with creating a makefile^^, That's true I guess.
Just wondering - A bit off topic but I'm trying to get the tutorial working however I keep getting this error when executing: Code:
the code is pretty much the same except I changed the int main() in the child code so that it looks like this: child.c CPP / C++ / C Code:
Could it be because I'm compiling on the desktop? (Both files are in the same place) |
|
#6
|
|||
|
|||
Re: Help with creating a makefileQuote:
However... The example that you are working with has two separate programs in two separate files. Each program has a main() function. Bottom line: If both files have main(), you can't compile them together (and there is absolutely no reason that I can think of for wanting to do such a thing anyhow.) Compile parent.c by itself. Compile child.c by itself. Then invoke the parent. Here's a very simple Makefile. Code:
Since each program has only one file, there is really no need to create the .o files. Just compile each one to its own executable. Note that I always include a "clean" target so that you can start "fresh" with "make clean" Here's my suggestion: In your home directory, create a new directory named example1. Do it from a command line: Code:
Copy your original parent.c and child.c into the example1 directory. Create the new Makefile that I just showed and put it in the example directory. Then, from a command line (in the example1 directory), execute Code:
Regards, Dave Quote:
Now you have a single program with source code in two separate files. Your original Makefile will compile the individual functions in the two files and link them together. However the example won't work, since it expects there to be a program named "child" that was compiled from the original child.c Regards, Dave |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error compiling Apache 2.2.10 | tiagofgarcia | Apache Web Server Forum | 2 | 10-Nov-2009 14:31 |
| Need help with makefile | New_Programmer | C++ Forum | 2 | 31-Mar-2009 23:49 |
| Problem executing nam-1.13 | RodolfoAlvizu | Computer Software Forum - Linux | 20 | 28-Feb-2009 16:23 |
| Mixing C and assembly in x86 - Makefile nuances | aijazbaig1 | Assembly Language | 3 | 23-Apr-2008 09:29 |
| I need some help with my makefile program | takachi | C Programming Language | 2 | 14-Jan-2008 06:43 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The