linux 编译makefile脚本

下面是C编译脚本

 NAME=   yuv_connect
 DIR_INC=./include
 DIR_SRC=./src
 DIR_OBJ=./output/obj
 DIR_BIN=./output/bin

CC      = gcc
#CC      = g++

## debug flag
DBG_ENABLE   = 0


INCLUDE=-I$(DIR_INC)


## debug for debug info, when use gdb to debug
ifeq (1, ${DBG_ENABLE})
CFLAGS += -D_DEBUG -O0 -g -DDEBUG=1
endif

## get all include path
CFLAGS  += $(foreach dir, $(DIR_INC), -I$(dir))
CFLAGS += -std=c++11

CFLAGS += -lm

TARGET=$(DIR_BIN)/$(NAME)

#SRC=$(wildcard ${DIR_SRC}/*.c)
#SRC         += $(wildcard $(DIR_SRC)/*.cpp)
SRC         += $(wildcard $(DIR_SRC)/*.c)


#OBJS=$(SRC:$(DIR_SRC)/%.c=$(DIR_OBJ)/%.o)
OBJS        +=$(SRC:$(DIR_SRC)/%.cpp=$(DIR_OBJ)/%.o)

$(TARGET):$(OBJS)
        @echo 'depend file "$^" ...'
        $(CC) $(CFLAGS) -o $(TARGET) $(OBJS)
#$(DIR_OBJ)/%.o:${DIR_SRC}/%.cpp
$(DIR_OBJ)/%.o:${DIR_SRC}/%.c
        @echo 'compiling object file "$@" ...'
        $(CC) $(CFLAGS) -c -o $@ $<
clean:
        rm -fr $(OBJS) $(TARGET);
        rm -fr $(DIR_OBJ)/* $(DIR_BIN)/*;

test:
        @echo $(SRC)
        @echo $(OBJS)

Linux下用C编程 sqrt函数找不到
使用gcc编译时,需要在后面加上参数-lm,m即math的简写,否则会报sqrt函数找不到错误。就像写posix thread的程序时,编译时需要加上-lpthread 一样。

c++编译脚本:

NAME=   yuv_connect
DIR_INC=./include
DIR_SRC=./src
DIR_OBJ=./output/obj
DIR_BIN=./output/bin

#CC      = gcc
CC      = g++

## debug flag
DBG_ENABLE   = 0


INCLUDE=-I$(DIR_INC) 


## debug for debug info, when use gdb to debug
ifeq (1, ${DBG_ENABLE})
CFLAGS += -D_DEBUG -O0 -g -DDEBUG=1
endif

## get all include path
CFLAGS  += $(foreach dir, $(DIR_INC), -I$(dir))
CFLAGS += -std=c++11


TARGET=$(DIR_BIN)/$(NAME)

#SRC=$(wildcard ${DIR_SRC}/*.c)
SRC         += $(wildcard $(DIR_SRC)/*.cpp)


#OBJS=$(SRC:$(DIR_SRC)/%.c=$(DIR_OBJ)/%.o)
OBJS        +=$(SRC:$(DIR_SRC)/%.cpp=$(DIR_OBJ)/%.o)

$(TARGET):$(OBJS)
	@echo 'depend file "$^" ...'
	$(CC) $(CFLAGS) -o $(TARGET) $(OBJS)
$(DIR_OBJ)/%.o:${DIR_SRC}/%.cpp
	@echo 'compiling object file "$@" ...'
	$(CC) $(CFLAGS) -c -o $@ $<
clean:
	rm -fr $(OBJS) $(TARGET);
	rm -fr $(DIR_OBJ)/* $(DIR_BIN)/*;

test:
	@echo $(SRC)
	@echo $(OBJS)

你可能感兴趣的:(视频编解码)