autoconf 添加三方库(libcurl)简单试用
1. 参考项目
https://github.com/rongfengliang/autoconf-project
2. 项目说明
a. 项目结构
├── Jenkinsfile # jenkins 构建,实际使用可选
├── Makefile.am
├── README.md
├── autogen.sh # 生成配置的shell
├── configure.ac # configure 配置说明
├── src
│ ├── Makefile.am # makefile 构建说明
│ ├── main.c
│ ├── userservice.c
│ ├── userservice.h
b. configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([dalongdemoapp], [0.0.1], [dalong@qq.com])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_AWK
AC_PROG_MKDIR_P
# Checks for libraries.
AC_CHECK_LIB([curl]) # libcurl check
# Checks for header files.
AC_CHECK_HEADERS([string.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile
src/Makefile])
AC_OUTPUT
c. Makefile.am
AUTOMAKE_OPTIONS=foreign
SUBDIRS=src
d. src/Makefile.am
bin_PROGRAMS=dalongdemoapp
dalongdemoapp_SOURCES=main.c userservice.c
include_HEADERS=userservice.h
dalongdemoapp_LDADD=-lcurl
备注:dalongdemoapp_LDADD=-lcurl 获取方式
可以使用pkg-confg
命令如下:
pkg-config --libs --cflags libcurl
e. main.c userservice.c userservice.h
主要是一个简单的demo 以及一个使用libcurl 获取博客园博客信息的
主要方法userservice.h/printcontent
3. 生成使用
./autogen.sh
./configure
make
src/dalongdemoapp
备注: 实际系统需要安装libcurl 对于centos如下:
yum install -y libcurl-devel
4. 效果
5. 参考资料
https://github.com/rongfengliang/autoconf-project
https://www.jianshu.com/p/2f5e586c3402
https://blog.csdn.net/luotuo44/article/details/24836901