{"id":2541,"date":"2019-06-27T00:59:37","date_gmt":"2019-06-26T16:59:37","guid":{"rendered":"http:\/\/www.51cos.com\/?p=2541"},"modified":"2024-11-27T18:29:16","modified_gmt":"2024-11-27T10:29:16","slug":"%e5%87%a0%e4%b8%aa%e5%b8%b8%e7%94%a8makefile%e6%a8%a1%e6%9d%bf%ef%bc%88%e5%8a%a8%e6%80%81%e5%ba%93%e3%80%81%e9%9d%99%e6%80%81%e5%ba%93%e3%80%81%e5%8f%af%e6%89%a7%e8%a1%8c%e7%a8%8b%e5%ba%8f%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.51cos.com\/?p=2541","title":{"rendered":"\u51e0\u4e2a\u5e38\u7528makefile\u6a21\u677f\uff08\u52a8\u6001\u5e93\u3001\u9759\u6001\u5e93\u3001\u53ef\u6267\u884c\u7a0b\u5e8f\uff09"},"content":{"rendered":"<pre><code class=\"language-bash line-numbers\"> APPNAME=link\nLIB_SRCS=linker.c\nLIB_NAME=linker\nLIB_PATH=.libs\n\nCFLAGS+=-I<span class=\"katex math inline\">{LIB_PATH}\nLDFLAGS+=-L<\/span>{LIB_PATH} -l<span class=\"katex math inline\">{LIB_NAME}\n\nall: clean static_lib shared_lib install\n    gcc<\/span>{CFLAGS} main.c -o <span class=\"katex math inline\">{APPNAME}_static<\/span>{LDFLAGS} -static\n    gcc <span class=\"katex math inline\">{CFLAGS} main.c -o<\/span>{APPNAME}_shared <span class=\"katex math inline\">{LDFLAGS}    rm -f *.o\n\nstatic_lib: linker.c\n    gcc -c<\/span>{LIB_SRCS}\n    ar -rcs lib<span class=\"katex math inline\">{LIB_NAME}.a *.o\n    rm -f *.o\n\nshared_lib:     gcc -fPIC -shared<\/span>{LIB_SRCS}  -o lib<span class=\"katex math inline\">{LIB_NAME}.so\n\nclean:\n     rm -rf *.o\n\ndistclean:\n    rm -rf .libs\n    rm -rf<\/span>{APPNAME}_*\n\ninstall:\n    mkdir -p <span class=\"katex math inline\">{LIB_PATH}\n    mv lib<\/span>{LIB_NAME}.* <span class=\"katex math inline\">{LIB_PATH}\n    cp linker.h<\/span>{LIB_PATH}\n\n\n\n\n #\u7f16\u8bd1\u9759\u6001\u5e93\nAR=ar\nTARGET=xx.a\nobj= a.o b.o ....\n\n\nall:<span class=\"katex math inline\">(obj)<\/span>(AR) ruc <span class=\"katex math inline\">(TARGET)<\/span>^\n\n\n%.o:%.c\n<span class=\"katex math inline\">(CC) -c<\/span>&lt; <span class=\"katex math inline\">@\n\n\n#\u8c03\u7528\u9759\u6001\u5e93\nTARGET=targetName\nCC=gcc\nMKLIB=\/xx\/yy\/xx.a\nobj= a.o b.o ...\n\nall:<\/span>(obj) <span class=\"katex math inline\">(MKLIB)<\/span>(CC) <span class=\"katex math inline\">^ -o<\/span>(TARGET)\n\n\n%.o:%.c\n<span class=\"katex math inline\">(CC) -c<\/span>&lt; <span class=\"katex math inline\">@\n\n\n\u52a8\u6001\u5e93\u7f16\u8bd1\nTARGET=lib_xx.so\nCC=gcc\nobj= a.o b.o ...\nall:<\/span>(obj)\n<span class=\"katex math inline\">(CC) -share -fPIC -o<\/span>(TARGET) <span class=\"katex math inline\">^\n\n%.o:%.c<\/span>(CC) -fpic -c <span class=\"katex math inline\">&lt;<\/span>@\n\n\u52a8\u6001\u5e93\u8c03\u7528\nTARGET=targetName\nCC=gcc\nMKLIB=-L\/xx\/yy -l_xx\nobj= a.o b.o ...\n\nall:<span class=\"katex math inline\">(obj)\u00a0<\/span>(CC) <span class=\"katex math inline\">(MKLIB)<\/span>^ -o <span class=\"katex math inline\">(TARGET)\n\n%.o:%.c<\/span>(CC) <span class=\"katex math inline\">(MKLIB) -c<\/span>&lt; <span class=\"katex math inline\">@\n\n\n#############################################################      # Makefile for shared library.     # \u7f16\u8bd1\u52a8\u6001\u94fe\u63a5\u5e93  \n#############################################################     #set your own environment option     CC = g++     CC_FLAG = -D_NOMNG -D_FILELINE  \n\n    #set your inc and lib     INC =      LIB = -lpthread -L.\/ -lsvrtool  \n\n    #make target lib and relevant obj      PRG = libsvrtool.so     OBJ = Log.o  \n\n    #all target     all:<\/span>(PRG)  \n\n    <span class=\"katex math inline\">(PRG):<\/span>(OBJ)  \n        <span class=\"katex math inline\">(CC) -shared -o<\/span>@ <span class=\"katex math inline\">(OBJ)<\/span>(LIB)  \n\n    .SUFFIXES: .c .o .cpp  \n    .cpp.o:  \n        <span class=\"katex math inline\">(CC)<\/span>(CC_FLAG) <span class=\"katex math inline\">(INC) -c<\/span>*.cpp -o <span class=\"katex math inline\">*.o  \n\n    .PRONY:clean     clean:         @echo \"Removing linked and compiled files......;         rm -f<\/span>(OBJ) <span class=\"katex math inline\">(PRG)  \n\n\n#############################################################     # Makefile for static library.     # \u7f16\u8bd1\u9759\u6001\u94fe\u63a5\u5e93  \n#############################################################     #set your own environment option     CC = g++     CC_FLAG = -D_NOMNG -D_FILELINE  \n\n    #static library use 'ar' command      AR = ar  \n\n    #set your inc and lib     INC =      LIB = -lpthread -L.\/ -lsvrtool  \n\n    #make target lib and relevant obj      PRG = libsvrtool.a     OBJ = Log.o  \n\n    #all target     all:<\/span>(PRG)  \n    <span class=\"katex math inline\">(PRG):<\/span>(OBJ)  \n        <span class=\"katex math inline\">{AR} rv<\/span>{PRG} <span class=\"katex math inline\">?  \n\n    .SUFFIXES: .c .o .cpp     .cpp.o:<\/span>(CC) <span class=\"katex math inline\">(CC_FLAG)<\/span>(INC) -c <span class=\"katex math inline\">*.cpp -o<\/span>*.o  \n\n    .PRONY:clean  \n    clean:  \n        @echo \"Removing linked and compiled files......\"  \n        rm -f <span class=\"katex math inline\">(OBJ)<\/span>(PRG)  \n\n\n###########################################  \n    #Makefile for simple programs  \n###########################################  \n    INC=  \n    LIB= -lpthread  \n\n    CC=CC  \n    CC_FLAG=-Wall  \n\n    PRG=threadpooltest  \n    OBJ=CThreadManage.o CThreadPool.o CThread.o CWorkerThread.o threadpooltest.o  \n\n    <span class=\"katex math inline\">(PRG):<\/span>(OBJ)  \n        <span class=\"katex math inline\">(CC)<\/span>(INC) <span class=\"katex math inline\">(LIB) -o<\/span>@ <span class=\"katex math inline\">(OBJ)  \n\n    .SUFFIXES: .c .o .cpp     .cpp.o:<\/span>(CC) <span class=\"katex math inline\">(CC_FLAG)<\/span>(INC) -c <span class=\"katex math inline\">*.cpp -o<\/span>*.o  \n\n    .PRONY:clean  \n    clean:  \n        @echo \"Removing linked and compiled files......\"  \n        rm -f <span class=\"katex math inline\">(OBJ)<\/span>(PRG)  \n\n\n\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>APPNAME=link LIB_SRCS=linker.c LIB_NAME=linker LIB_PATH [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-2541","post","type-post","status-publish","format-standard","hentry","category-embedded"],"_links":{"self":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/2541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2541"}],"version-history":[{"count":6,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/2541\/revisions"}],"predecessor-version":[{"id":3031,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/2541\/revisions\/3031"}],"wp:attachment":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2541"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}