简单记录一下在windows环境下使用cmake构建工程
任务
- cmake一个工程
- 静态库和动态库的构建与安装
- 外部共享库和头文件的使用
前期准备
先找一个路径 [D:\DamonWS\STUDY\4-5-6-Linux\CMAKE] 建立如下code1
code2
code3
三个文件夹
D:\DamonWS\STUDY\4-5-6-Linux\CMAKE> tree
.
├── code1
├── code2
└── code3
CMake一个工程
代码工程在目录下的code1文件夹
1、步骤一,写好C代码
先在code1
下创建一个src
文件夹,随后创建fun.c
fun.h
main.c
文件
fun.c
中的内容
#include "stdio.h"
int add(int a,int b)
{
int c = a+b;
return (c);
}
fun.h
中的内容
#ifndef _FUN_H_
#define _FUN_H_
int add(int a,int b);
#endif
main.c
中的内容
#include "stdio.h"
#include <stdlib.h>
#include "fun.h"
int main(int argc, char* argv[])
{
printf("main >> hello world !\n");
if(argc < 3)
{
printf("Usage: %s input error\n", argv[0]);
return -1;
}
int a = atoi(argv[1]); //取传入参数1
int b = atoi(argv[