makefile
#################################################################
# PRIVATE PART #
#################################################################
APP_STACK_DIR = .
# 内部头文件
INC_CFLAGS += -I $(APP_STACK_DIR)/Inc
# 对外接口目录
INC_CFLAGS += -I $(APP_STACK_DIR)/Intf
# 动态链接库
#LDFLAGS += -lName -lName
# 源文件
CSRC += $(APP_STACK_DIR)/Src/*.c
C_OBJS += $(patsubst %.c,%.o,$(wildcard $(CSRC)))
# 动态库编译标志
DEBUG = y
ifeq ($(DEBUG),y)
DEBUG_CFLAGS += -DDEBUG
DEBUG_CFLAGS += -g
endif
CFLAGS += -c
CFLAGS += -Os
CFLAGS += -Wall
CFLAGS += -fPIC
#CFLAGS += -fvisibility=hidden #隐藏属性
CFLAGS += $(DEBUG_CFLAGS)
# 目标文件
Target_Lib=$(APP_STACK_DIR)./Lib/libOne.a
Target_Dll=$(APP_STACK_DIR)./Lib/libone.so
TARGET = $(Target_Lib) $(Target_Dll)
# 编译规则
all:$(TARGET)
$(Target_Lib):$(C_OBJS)
$(AR) rcs $@ $^
@echo -e "\n>>>>> Compiling *$(Target_Lib)* sucessfully ended\n"
$(Target_Dll):$(C_OBJS)
$(CC) -shared $^ -o $@
@echo -e "\n>>>>> Compiling *$(Target_Dll)* sucessfully ended\n"
$(C_OBJS):%.o:%.c
$(CC) $(CFLAGS) $(INC_CFLAGS) $< -o $@
.PHONY:all clean
clean:
-rm -f $(C_OBJS)
-rm -f $(TARGET)
libOne.h
#ifndef __LIBONE_API_H__
#define __LIBONE_API_H__
// #define OPEN_API_LIBTWOTEST __attribute__((visibility("default")))
#define OPEN_API_LIBTWOTEST
#ifdef __cplusplus
extern "C"
{
#endif
/*
*名称: 测试用例
*描述:
*参数: 无
*返回值:0————成功;其他————错误号。
*说明:
*/
OPEN_API_LIBTWOTEST int myPrintf();
#ifdef __cplusplus
}
#endif
#endif
#include "libOne.h"
#include <stdio.h>
// #define OPEN_API_LIBONETEST_SRC __attribute__((visibility("default")))
#define OPEN_API_LIBONETEST_SRC
OPEN_API_LIBONETEST_SRC int myPrintf()
{
printf("Hi , I am is lib One ! \n");
return 0;
}
TARGET=appTest
########CC=g++
#CC=arm-linux-gnueabi-gcc
CFLAG=-g -Wall
INCLUDE=-I../include
SRC += main.c
LIB=-L../lib -ltwo -lone
all:
$(CC) $(CFLAG) $(INCLUDE) $(SRC) $(LIB) -o $(TARGET)