Compiling C code using makefile
Hi
I written four C programs each does different function when received message from client Common thing for all C programs are socket which act as server and execute function in thread. Now what I feel there are repitition of code.I want to avoid this. For example Include directory will be there were wrapper is written for socket etc. Also I want to use makefile Please show me some example code so that I can use as reference. |
I'm not sure what the question is, but here's the manual for GNU make:
http://www.gnu.org/software/make/manual/make.html |
Firstly it sort of matters if these four files link to create one image or if you intend to create multiple targets. As HMW notes, read up on Makefiles and begin with rudimentary ones. There are plenty of examples for how to make the most simple of Makefiles.
And a VERY IMPORTANT make file thing you need to know is PUNCTUATION. Note that when you indent you NEED TO USE TABS AND NOT WHITESPACES. I recommend you use a Linux or Unix editor to create your Makefiles and also ensure that the editor is not configured to replace TAB with spaces. I have a simple legacy Makefile which I refer to all the time for the basics as well as my list of GCC compiler flags that I like to retain and use. They improve my code because they check for lots of warning conditions and thus help me to not create suspect code. I'll be happy to post that example, but I feel you first ought to make a reasonable attempt to show what you've tried. |
The best way to create a makefile is to look at some makefiles. Maybe start with the makefiles used to build make. Hopefully they are up to date and correct. Put all your code in one file and remove duplicate code?
|
Thanks all
@rtmistler I have one makefile I made directories as Source, Include, Lib Source :-cpp files where functions are written Include:-header files for source cpp Lib:- After compilation .o files should go in this directory Source,Include,Lib will be common for all 4 programs I mentioned in first post Apart from that my first main application appdownload.cpp file will be in project directory along with its include.h file. Code:
CC = g++ |
I managed to write working makefile
Code:
CC = g++ |
I think it's an excellent effort and in fact there's little you need assistance with.
Here are some added suggestions:
What I do is add incrementally new ideas as I see them in other examples or develop them when I need too. |
Also do not overlook handy tools like Automake.
If you use these tools to discover dependencies and to construct your makefiles, it is much easier to be certain that your makefiles remain accurate as the program evolves. |
Quote:
5.3.2 Choosing the Shell |
All times are GMT -5. The time now is 07:53 PM. |