用于链接OpenCV和现有库的Makefile(不使用cmake)

问题描述 投票:0回答:2

目前,我一直在研究如何使用Makefile将现有库与OpenCV链接。我还是Makefile的新手。我在互联网上搜索过,但主要是答案是在CMake上。即使有答案,结果的输出也包含错误。请看看我的Makefile,我做错了什么?

Makefile文件

###############################################################
#
# Purpose: Makefile for "head_tracking"
# Author.: robotis
# Version: 0.1
# License: GPL
#
###############################################################

TARGET = head_tracking

INCLUDE_DIRS = -I../../../include -I../../../../Framework/include

CXX = g++
CXXFLAGS += -O2 -DLINUX -Wall $(INCLUDE_DIRS)
#CXXFLAGS += -O2 -DDEBUG -DLINUX -Wall $(INCLUDE_DIRS)
LFLAGS += -lpthread -ljpeg -lrt
CPPFLAGS = $(shell pkg-config --cflags opencv2) #The one i added
LDLIBS = $(shell pkg-config --libs opencv2)     #The one i addded

OBJECTS =   main.o

all: $(TARGET)

clean:
    rm -f *.a *.o $(TARGET) core *~ *.so *.lo

libclean:
    make -C ../../../build clean

distclean: clean libclean

darwin.a:
    make -C ../../../build

$(TARGET): darwin.a $(OBJECTS)
    $(CXX) $(CFLAGS) $(OBJECTS) ../../../lib/darwin.a -o $(TARGET) $(LFLAGS)
    chmod 755 $(TARGET)

# useful to make a backup "make tgz"
tgz: clean
    mkdir -p backups
    tar czvf ./backups/head_tracking_`date +"%Y_%m_%d_%H.%M.%S"`.tgz --exclude backups *

Error Image: Undefined Refrenced

c++ opencv makefile g++ ubuntu-12.04
2个回答
0
投票

您有链接错误,您需要链接以下标志:

-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab

OpenCV Undefined symbols for architecture x86_64: error


0
投票

好吧,我终于解决了我的链接错误。我现在可以用我的Robotis-Op库编译openCV。这是新的Makefile。

###############################################################
#
# Purpose: Makefile for "head_tracking"
# Author.: robotis
# Version: 0.1
# License: GPL
#
###############################################################

TARGET = head_tracking

INCLUDE_DIRS = -I../../../include -I../../../../Framework/include -I/usr/local/include/opencv2

CXX = g++
CXXFLAGS += -O2 -DLINUX -Wall $(INCLUDE_DIRS) `pkg-config --cflags opencv`
#CXXFLAGS += -O2 -DDEBUG -DLINUX -Wall $(INCLUDE_DIRS)
LFLAGS += -lpthread -ljpeg -lrt 
LDFLAGS = `pkg-config --libs opencv` 
#CPPFLAGS = $(shell pkg-config --cflags opencv2)
#LDLIBS = $(shell pkg-config --libs opencv2)

OBJECTS =   main.o

all: $(TARGET)

clean:
    rm -f *.a *.o $(TARGET) core *~ *.so *.lo

libclean:
    make -C ../../../build clean

distclean: clean libclean

darwin.a:
    make -C ../../../build

$(TARGET): darwin.a $(OBJECTS)
    $(CXX) $(CFLAGS) $(OBJECTS) ../../../lib/darwin.a -o $(TARGET) $(LFLAGS) $(LDFLAGS)
    chmod 755 $(TARGET)

# useful to make a backup "make tgz"
tgz: clean
    mkdir -p backups
    tar czvf ./backups/head_tracking_`date +"%Y_%m_%d_%H.%M.%S"`.tgz --exclude back

ups *
© www.soinside.com 2019 - 2024. All rights reserved.