Makefile Example 1

Source: Internet
Author: User

# set Compiler
CC = g++

#-fpic acts on the compile phase, telling the compiler to generate location-independent code
The #-D macro definition, equivalent to the global # define in C, can be used to control the compilation of the source program through macro definitions, for example:
# #ifdef _fileline
# printf ("Hello Yu Qiang, How is you?\n");
# #else
# printf ("Sorry to Lost. \ n ");
# #endif
# program Final call output is: Hello Yu Qiang, how is it?
Cflag =-g-fpic-d_fileline

# MySQL header file
Mysqlinc =/usr/include/mysql

INC =-i-iinclude-i$ (mysqlinc)

# MySQL Library directory
Mysqllib =-l/usr/lib64/mysql-l MYSQLCLIENT-LZ-LM

# Server Destination
SERVEROBJS = src/file1.o src/file2.o src/file3.o

# client Target
CLIENTOBJS = SRC/F1.O SRC/F2.O

# Bin Directory
BINDIR = Bin

# Checkbin Check if the bin directory exists
# Generate Server and Client in bin directory
All:checkbin $ (BINDIR)/server $ (BINDIR)/client

# Build Server
# $^ all. o Files
# [email protected] all. C Files
$ (BINDIR)/server: $ (SERVEROBJS)
$ (CC)-G $ (myslqlib) $^-o [email protected]

# Generate Client
$ (BINDIR)/CLIETN: $ (CLIENTOBJS)
$ (CC)-G $ (mysqllib) $^-o [email protected]

# . Suffixes the connection suffix, connect the. O. cpp. C. cpp.o these files together to compile. A list of types that support file suffixes within the current makefile.
. Suffixes:. C. o CPP
. CPP.O:
$ (CC) $ (cflag) $ (INC)-o [email protected]-C $<

# . Phony pseudo target
. Phony:checkbin
Checkbin:
Test-d "${bindir}" | | mkdir $ (BINDIR)


. Phony:clean
Clean
-rm-f *.O
-rm-f $ (BINDIR)/server

Makefile Example 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.