我手动编译了OpenCV库,以使用以下命令获取静态库文件(在OSX上为*.a
)
cmake -D CMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -D CMAKE_INSTALL_PREFIX=./instDir/ ../openCV/
make -j8
make install
然后我想从我的C ++源代码中获得一个独立的可执行文件,因此我创建了以下Makefile
:
CXX = g++
CXXFLAGS = -std=c++11
INC_PATH = `pkg-config --cflags ../cmake_bin_dir_static/instDir/lib/pkgconfig/opencv.pc`
LIBS = `pkg-config --libs --static ../cmake_bin_dir_static/instDir/lib/pkgconfig/opencv.pc`
SOURCEDIR := ../project/
SOURCES := $(wildcard $(SOURCEDIR)/*.cpp)
OBJDIR=$(SOURCEDIR)/obj
OBJECTS := $(patsubst $(SOURCEDIR)/%.cpp,$(OBJDIR)/%.o,$(SOURCES))
DEPENDS := $(patsubst $(SOURCEDIR)/%.cpp,$(OBJDIR)/%.d,$(SOURCES))
# ADD MORE WARNINGS!
WARNING := -Wall -Wextra
# .PHONY means these rules get executed even if
# files of those names exist.
.PHONY: all clean
# The first rule is the default, ie. "make",
# "make all" and "make parking" mean the same
all: parking_static
clean:
$(RM) $(OBJECTS) $(DEPENDS) parking_static
# Linking the executable from the object files
parking_static: $(OBJECTS)
$(CXX) $(WARNING) $(CXXFLAGS) $(INC_PATH) $^ -o $@ $(LIBS)
-include $(DEPENDS)
$(OBJDIR):
mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: $(SOURCEDIR)/%.cpp Makefile $(OBJDIR)
$(CXX) $(WARNING) $(CXXFLAGS) $(INC_PATH) -MMD -MP -c $< -o $@
Makefile
应该正确,因为它在编译时没有标志--static
。但是,当它出现时,我会收到错误消息:
ld: library not found for -lAccelerate.framework
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [parking_static] Error 1
如何将静态OpenCV库链接到我的项目?