关于Makefile无法找到库 [英] About Makefile can't find libraries

查看:143
本文介绍了关于Makefile无法找到库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

异常在这里:

  g ++ -L / usr / local / lib -I ./include -I。 -lopencv_core -lopencv_highgui -lopencv_imgproc main.o ColorTransfer.o 
main.o:在函数showImg(std :: string,cv :: Mat,int)中:
main.cpp :( .text + 0x21):对`cv :: namedWindow(std :: string const&,int)'的未定义引用
main.cpp :( .text + 0x34):未定义对`cv :: _ InputArray :: _ InputArray cv :: Mat const&)'
main.cpp :(。text + 0x75):对`cv :: imshow(std :: string const& ;,; cv :: _ InputArray const&)的未定义引用'
main.cpp :(。text + 0x9d):对`cv :: waitKey(int)'的未定义引用
main.o:在函数`main'中:

Makefile 在这里:

  CC = g ++ 
FLAGS = -L。/ lib -I./include -I。 -lopencv_core -lopencv_highgui -lopencv_imgproc

全部:ColorTransfer

ColorTransfer:main.o ColorTransfer.o
$(CC)$(FLAGS)main.o ColorTransfer。 o -o ColorTransfer

main.o:main.cpp
$(CC)$(FLAGS)-c main.cpp -o main.o

ColorTransfer .o:ColorTransfer.cpp ColorTransfer.h
$(CC)$(FLAGS)-c ColorTransfer.cpp -o ColorTransfer.o

clean:
rm -rf main。 o ColorTransfer.o

当前目录包含名为lib的目录,其中包含opencv库。

解决方案

您真的应该注意 g ++ ;它很重要(图书馆应该保持良好状态 - 从最高级到最低级)。



使用 make -p 以了解 make ....的规则,然后改进您的 Makefile ,如下所示

  CXX = g ++ 
CXXFLAGS = -I./include -I。 -g -Wall
LDLIBS = -L./lib -lopencv_core -lopencv_highgui -lopencv_imgproc

all:ColorTransfer

ColorTransfer:main.o ColorTransfer.o
$(LINK.cc)$ ^ $(LDLIBS)-o $ @

#etc ...

我让你纠正你的 Makefile 的其他行...参见

我更正了上面的制作规则: $ ^ 必须位于 $(LDLIBS)



顺便说一句,重拍是一个很好的工具来调试 Makefile -s;例如,用 remake -x


The Exception is here:

g++ -L/usr/local/lib -I./include -I. -lopencv_core -lopencv_highgui -lopencv_imgproc main.o ColorTransfer.o
main.o: In function `showImg(std::string, cv::Mat, int)':
main.cpp:(.text+0x21): undefined reference to `cv::namedWindow(std::string const&, int)'
main.cpp:(.text+0x34): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
main.cpp:(.text+0x75): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
main.cpp:(.text+0x9d): undefined reference to `cv::waitKey(int)'
main.o: In function `main':

And the Makefile is here:

CC=g++
FLAGS=-L./lib -I./include -I. -lopencv_core -lopencv_highgui -lopencv_imgproc

all: ColorTransfer

ColorTransfer: main.o ColorTransfer.o
    $(CC) $(FLAGS) main.o ColorTransfer.o -o ColorTransfer

main.o: main.cpp 
    $(CC) $(FLAGS) -c main.cpp -o main.o

ColorTransfer.o: ColorTransfer.cpp ColorTransfer.h
    $(CC) $(FLAGS) -c ColorTransfer.cpp -o ColorTransfer.o

clean :
    rm -rf main.o ColorTransfer.o

And current directory contains directory named lib, which has opencv libraries.

解决方案

You really should pay attention to the order of arguments to g++ ; it matters a lot (libraries should go last in good order - highest level to lowest level).

Use  make -p to learn about rules known to make.... Then improve your Makefile as follow

 CXX=g++
 CXXFLAGS= -I./include -I. -g -Wall
 LDLIBS= -L./lib -lopencv_core -lopencv_highgui -lopencv_imgproc

 all: ColorTransfer

 ColorTransfer: main.o ColorTransfer.o
           $(LINK.cc)  $^ $(LDLIBS) -o $@

 # etc....

I leave you to correct the other lines of your Makefile ... See also this answer ...

I corrected my make rules above : $^ has to be before $(LDLIBS) !

BTW, remake is a nice tool to debug Makefile-s; for instance, with remake -x

这篇关于关于Makefile无法找到库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆