curl编译linux静态库及使用总结

一、安装OPENSSH

1、上传文件并解压 openssl-1.0.2k.tar.gz

2、执行
./config no-asm
make
make install

备注:如果要编译动态库,需要增加参数如下:
./config no-asm --shared

3、生成的文件目录在:/usr/local/ssl 下

二、安装curl

1、上传文件并解压 curl-7.53.1.tar.gz

2、执行
CPPFLAGS="-I/usr/local/ssl -I/usr/local/ssl/include" LDFLAGS="-L/usr/local/ssl/lib" LIBS="-ldl" ./configure --with-ssl --disable-shared --enable-static --disable-dict --disable-ftp --disable-imap --disable-ldap --disable-ldaps --disable-pop3 --disable-proxy --disable-rtsp --disable-smtp --disable-telnet --disable-tftp --disable-zlib --without-ca-bundle --without-gnutls --without-libidn --without-librtmp --without-libssh2 --without-nss --without-zlib

make curl_LDFLAGS=-all-static

make install curl_LDFLAGS=-all-static

备注:

3、生成的文件目录
头文件在:/usr/local/include 下
库文件在:/usr/local/lib 下

4、使用curl的程序,Makefile如下:
#--------------------------------------------------------------------------
#source file
#源文件,自动找所有.c和.cpp文件,并将目标定义为同名.o文件
SOURCE := $(wildcard *.c) $(wildcard *.cpp) $(wildcard *.cc)
OBJS := ( p a t s u b s t (patsubst %.c,%.o, (patsubst(patsubst %.cpp,%.o,$(SOURCE)))

当前时间

CURTIME=$(shell date +%Y%m%d)

#可执行文件名
EXENAME = payment

#目标文名
TARGET := ( E X E N A M E ) . (EXENAME). (EXENAME).(CURTIME)

#可执行文件拷贝目录
BINDIRECT = /home/chnsgy/server/bin/$(EXENAME)/

#compile and lib parameter
#编译参数

#CC := gcc
CC := g++
#CC := g++ -O3

头文件路径

INCLUDES := -I./
INCLUDES += -I/usr/include/
INCLUDES += -I/usr/local/include/
INCLUDES += -I/usr/local/boost/include/
INCLUDES += -I/usr/local/protobuf/include/
INCLUDES += -I/usr/local/websocketpp/
INCLUDES += -I/usr/local/g3log/
INCLUDES += -I/usr/local/ssl/include/
INCLUDES += -I…/comm/

依赖库路径

LIBS := -L/usr/lib/
LIBS += -L/usr/local/lib/
LIBS += -L/usr/local/boost/lib/
LIBS += -L/usr/local/ssl/lib/
LIBS += -L…/comm/
LIBS += -lcomm
LIBS += /usr/local/protobuf/lib/libprotobuf.a
LIBS += /usr/local/lib64/libmysqlcppconn-static.a
LIBS += /usr/local/g3log/lib/libg3logger.a
LIBS += -ldl
LIBS += -lrt
LIBS += -lboost_thread-mt-sd
LIBS += -lpthread
LIBS += -lboost_system-mt-sd
LIBS += -lboost_filesystem-mt-sd
LIBS += -lboost_serialization-mt-sd
LIBS += -lboost_log-mt-sd
LIBS += /usr/local/lib/libcurl.a
LIBS += /usr/local/ssl/lib/libssl.a
LIBS += /usr/local/ssl/lib/libcrypto.a

LDFLAGS :=
DEFINES :=
CFLAGS := -std=c++11 -g -Wall -O3 $(DEFINES) $(INCLUDES)
CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H -D_DEBUG -DCURL_STATICLIB

#i think you should do anything here
#下面的基本上不需要做任何改动了

.PHONY : everything objs clean veryclean rebuild

everything : $(TARGET)

all : $(TARGET)

objs : $(OBJS)

rebuild: veryclean everything

clean :
rm -fr *.so
rm -fr *.o

veryclean : clean
rm -fr $(TARGET)

$(TARGET) : $(OBJS)
$(CC) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
rm -f ( B I N D I R E C T ) (BINDIRECT) (BINDIRECT)(TARGET)
cp $@ -f ( B I N D I R E C T ) (BINDIRECT) (BINDIRECT)(EXENAME)

你可能感兴趣的:(curl编译linux静态库及使用总结)