简体   繁体   English

使用opencv时找不到lopencv_core

[英]lopencv_core not found when using opencv

I have opencv3 installed through home-brew and pkg-config can find the linkers too by 我通过home-brew安装opencv3,pkg-config也可以找到连接器

pkg-config --cflags --libs opencv

the outputs contains -lopencv_core, but when I add that in Makefile like this 输出包含-lopencv_core,但是当我像Make这样在Makefile中添加它时

CC=clang++
CFLAGS= -Wall -g -std=c++0x
LFLAGS= -I/usr/local/Cellar/opencv3/3.2.0/include -I/usr/local/Cellar/opencv3/3.2.0/bin -I/usr/local/Cellar/opencv3/3.2.0/lib -lopencv_core

CFILES=blah.cpp
HFILES=blah.hpp
OFILES=blah.o

all:    main

%.o:    %.cpp $(HFILES)                                                                                   
        $(CC) -c $(CFLAGS) $< -o $@ $(LFLAGS)

main:   $(OFILES) $(HFILES)
    $(CC) $(CFLAGS) $(OFILES) -o main $(LFLAGS)

it says 它说

ld: library not found for -lopencv_core
clang: error: linker command failed with exit code 1 (use -v to see invocation)

How should I link that to gcc? 我应该如何将其链接到gcc?

The -l option looks in the usual places for the mentioned library. -l选项查找所提到的库的常用位置。 Where and what it looks varies by OS, which you didn't mention. 它的外观和外观因操作系统而异,您没有提及。 Possibly it can be fixed by adding -L /usr/local/lib or some other path to where you know the libraries are. 可能可以通过添加-L /usr/local/lib或其他路径到您知道库的位置来修复它。

Assuming you want CFLAGS to be the options for compilation and LFLAGS to be the options for linkage, the settings: 假设您希望CFLAGS成为编译选项并且LFLAGS成为链接的选项,则设置为:

CFLAGS= -Wall -g -std=c++0x
LFLAGS= -I/usr/local/Cellar/opencv3/3.2.0/include -I/usr/local/Cellar/opencv3/3.2.0/bin -I/usr/local/Cellar/opencv3/3.2.0/lib -lopencv_core

are confused. 很困惑。

The -I path option is meaningful for compilation and meaningless for linkage. -I path选项对于编译有意义,对于链接没有意义。 It tells the preprocessor to search in path for header files that you #include in the source code. 它告诉预处理器在path搜索源代码中#include头文件。 There will be header files in: 将有头文件:

/usr/local/Cellar/opencv3/3.2.0/include

There will be no header files in: 将来没有头文件:

/usr/local/Cellar/opencv3/3.2.0/bin

just executables, which are irrelevant to building your program. 只是可执行文件,与构建程序无关。 And there will be no header files in: 并且没有头文件:

/usr/local/Cellar/opencv3/3.2.0/lib

just static and or dynamic libraries. 只是静态和/或动态库。

The library libopencv_core that linker can't find is presumably in /usr/local/Cellar/opencv3/3.2.0/lib . 链接器无法找到的库libopencv_core可能位于/usr/local/Cellar/opencv3/3.2.0/lib The way to tell the linker to search there for the library is: 告诉链接器在那里搜索库的方法是:

-L/usr/local/Cellar/opencv3/3.2.0/lib -lopencv_core

So these settings make sense: 所以这些设置是有道理的:

CFLAGS := -Wall -g -std=c++0x -I/usr/local/Cellar/opencv3/3.2.0/include
LFLAGS := -L/usr/local/Cellar/opencv3/3.2.0/lib -lopencv_core

However, to compile and link an opencv program you would probably be better leaving it to pkg-config to get the options right: 但是,要编译和链接opencv程序,您可能最好将其保留到pkg-config以获得正确的选项:

CFLAGS := -Wall -g -std=c++0x $(shell pkg-config --cflags opencv)
LFLAGS := $(shell pkg-config --libs opencv)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM