1、add.c代码实现加法运算:
int add(int a,int b)
{
return a+b;
}
2、头文件add.h
#ifndef ADD_H
#define ADD_H
int add(int a,int b);
#endif
3、CMakeLists.txt编写
cmake_minimum_required(VERSION 2.6)
set(CMAKE_C_FLAGS -m32)
project(test_add)
include_directories(
${PROJECT_SOURCE_DIR}/)
link_directories(
P
R
O
J
E
C
T
S
O
U
R
C
E
D
I
R
/
)
a
d
d
l
i
b
r
a
r
y
(
{PROJECT_SOURCE_DIR}/) add_library(
PROJECTSOURCEDIR/)addlibrary({PROJECT_NAME} ${PROJECT_SOURCE_DIR}/add.c)
4、运行cmake.及make命令
5、readelf -h查询库信息,为32位