时间:2021-05-19
1、在windows下 g++环境中,调用一个python的静态链接库,在makefile文件有一段是全局的g++命令:
$(PROG): $(OBJS) $(CXX) $(LFLAGS) $^ -o $@现在我要链接上一个python的静态库,lib存储在makefile同目录下libs文件夹下:
$(PROG): $(OBJS) $(CXX) $(LFLAGS) $^ -o $@ ./libs/libpython37.a2、在Linux Ubuntu 18.04版本中添加静态库,视python版本而定:
$(PROG): $(OBJS) $(CXX) $(LFLAGS) $^ -o $@ -lpython3.6mmain.cpp
#include <stdio.h>#include "opencv2/opencv.hpp"int main(){ cv::Mat image = cv::imread("./testPic/jianhui.jpg"); //cv::imshow("xxx", image); //cv::waitKey(40); printf("image.col=%d image.row=%d \n", image.cols, image.rows); cv::imwrite("aa.jpg", image); return 0;}Makefile
EXE=main#SUBDIR=src object#CXXFLAGS:编译选项, LDFLAGS:链接选项thirdparty_root := /local_install/staticCC := g++#export PKG_CONFIG_PATH := ${thirdparty_root}/lib/pkgconfig:${PKG_CONFIG_PATH}#INCS += `pkg-config --cflags opencv`#LIBS += `pkg-config --libs opencv`INCS := -I${thirdparty_root}/includeLIBS += -L${thirdparty_root}/lib -lopencv_imgcodecs -lopencv_dnn -lopencv_imgproc -lopencv_core #LIBS += -L${thirdparty_root}/lib -lopencv_imgcodecs -lopencv_imgproc -lopencv_core # 亲们,顺序不能变,因为这个快把我整崩溃了LIBS += -L${thirdparty_root}/share/OpenCV/3rdparty/lib -lIlmImf -llibjasper -llibjpeg -llibpng -llibtiff -llibwebp -lzlib -lippicv -ldlCXXFLAGS := -Wall -c -O2 -std=c++11 $(INCS)LDFLAGS := $(LIBS)LDFLAGS += -lpthread#LDFLAGS += -Wl,-rpath,${thirdparty_root}/share/OpenCV/3rdparty/lib:${thirdparty_root}/lib: # 动态库的时候需要寻找的路径#CXX_SOURCES =$(foreach dir,$(SUBDIR), $(wildcard $(dir)/*.cpp))#CXX_OBJECTS=$(patsubst %.cpp, %.o, $(CXX_SOURCES))CXX_OBJECTS := $(patsubst %.cpp,%.o,$(shell find . -name "*.cpp"))DEP_FILES =$(patsubst %.o, %.d, $(CXX_OBJECTS))$(EXE): $(CXX_OBJECTS) $(CC) $(CXX_OBJECTS) -o $(EXE) $(LDFLAGS) %.o: %.cpp $(CC) -c $(CXXFLAGS) -MMD $< -o $@-include $(DEP_FILES)clean: rm -rf $(CXX_OBJECTS) $(DEP_FILES) $(EXE)test: echo $(CXX_OBJECTS)上面的Makefile 是用调用动态库的方式来调用静态库,如果同时存在静态库和动态库,会优先调用动态库
EXE=CppWebServer#SUBDIR=src object#CXXFLAGS:编译选项, LDFLAGS:链接选项CC := g++thirdparty_root := /local_install/static#INCS += `pkg-config --cflags opencv`INCS += -I/usr/lib/jdk1.8.0_191/includeINCS += -I/usr/lib/jdk1.8.0_191/include/linux/INCS += -I./includeINCS := -I${thirdparty_root}/include# 这种方式调用静态库,保证在在动态库也存在的时候也能调用到静态库LIBS += ${thirdparty_root}/lib/libopencv_imgcodecs.aLIBS += ${thirdparty_root}/lib/libopencv_dnn.aLIBS += ${thirdparty_root}/lib/libopencv_imgproc.aLIBS += ${thirdparty_root}/lib/libopencv_core.aLIBS += ${thirdparty_root}/share/OpenCV/3rdparty/lib/libIlmImf.aLIBS += ${thirdparty_root}/share/OpenCV/3rdparty/lib/liblibjasper.aLIBS += ${thirdparty_root}/share/OpenCV/3rdparty/lib/liblibjasper.aLIBS += ${thirdparty_root}/share/OpenCV/3rdparty/lib/liblibjpeg.aLIBS += ${thirdparty_root}/share/OpenCV/3rdparty/lib/liblibpng.aLIBS += ${thirdparty_root}/share/OpenCV/3rdparty/lib/liblibtiff.aLIBS += ${thirdparty_root}/share/OpenCV/3rdparty/lib/liblibwebp.aLIBS += ${thirdparty_root}/share/OpenCV/3rdparty/lib/libzlib.aLIBS += ${thirdparty_root}/share/OpenCV/3rdparty/lib/libippicv.aLIBS += -L./lib -lTHFaceImage -lTHFeatureLIBS += -ldl#LIBS += `pkg-config --libs opencv`CXXFLAGS := -Wall -c -O2 -std=c++11 $(INCS)LDFLAGS := $(LIBS) LDFLAGS += -lpthread#CXXFLAGS += -I/usr/local/include/#LDFLAGS += -L/usr/local/lib -lopencv_world#CXX_SOURCES =$(foreach dir,$(SUBDIR), $(wildcard $(dir)/*.cpp))#CXX_OBJECTS=$(patsubst %.cpp, %.o, $(CXX_SOURCES))CXX_OBJECTS := $(patsubst %.cpp,%.o,$(shell find . -name "*.cpp"))CXX_OBJECTS += $(patsubst %.c,%.o,$(shell find . -name "*.c"))DEP_FILES =$(patsubst %.o, %.d, $(CXX_OBJECTS))$(EXE): $(CXX_OBJECTS) $(CC) $(CXX_OBJECTS) -o $(EXE) $(LDFLAGS)%.o: %.cpp $(CC) -c $(CXXFLAGS) -MMD $< -o $@-include $(DEP_FILES)clean: rm -rf $(CXX_OBJECTS) $(DEP_FILES) $(EXE) OBJ_DIR = objmove: if [ ! -d $(OBJ_DIR) ]; then mkdir -p $(OBJ_DIR); fi;\ mv $(CXX_OBJECTS) $(OBJ_DIR); \ mv $(DEP_FILES) $(OBJ_DIR); \ mv $(EXE) $(OBJ_DIR) test: echo $(CXX_OBJECTS)到此这篇关于makefile如何调用静态库的方法实现的文章就介绍到这了,更多相关makefile调用静态库内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
这里介绍过Android.mk如何使用静态库,这里介绍的是通过动态库调用静态库的使用方法1、首先修改第一篇介绍的.c文件软件名称:AndroidStudiov2
本文给出的静态方法实现删除将指定文件下的所有内容。静态方法在调用时,不能使用类的实例来调用,只能通过类名来调用。//======================
在同一个类中:对于静态方法,其他的静态或非静态方法都可以直接调用它。而对于非静态方法,其他的非静态方法是可以直接调用它的。但是其他静态方法只有通过对象才能调用它
静态方法和非静态方法的区别: 1.静态方法不需要类实例化就可以调用,反之非静态方法需要实例化后才能调用; 2.静态方法只能访问静态成员和方法,非静态方法都可
shell文件内调用makefile文件:#!/bin/bashcdctemplate-2.1./configuresudomake-finstallcd../