在 64 位 Mac 上编译 OpenCV 代码

发布于 2024-11-03 03:44:08 字数 1148 浏览 0 评论 0原文

我最近继承了一些OpenCV代码。我在我的 mac 上安装了 openCV,内置在 XCode 中,然后编译并成功运行了我的第一个 openCV“hello world”程序。

现在,我尝试运行给定的代码,但出现错误,这让我相信这是在 32 位 Windows 系统上运行的原始代码和在 64 位 Mac 上运行的原始代码的问题。

当我通过输入“make”运行 Makefile 时,

CC = g++
CFLAGS =
LDFLAGS = -I/usr/local/include/opencv -lm -lopencv_core -lopencv_highgui -lopencv_video
ALL = vision

all: $(ALL)

vision: vision.o
    $(CC) $(LDFLAGS) -o $@ $^

vision.o: vision.cpp
    $(CC) $(LDFLAGS) -c $<

.PHONY: clean

clean:
    rm -rf *.o core* $(ALL)

我得到以下输出……

g++ -I/usr/local/include/opencv -lm -lopencv_core -lopencv_highgui -lopencv_video -o vision vision.o
Undefined symbols for architecture x86_64:
  "cv::equalizeHist(cv::Mat const&, cv::Mat&)", referenced from:
      _main in vision.o
  "cv::threshold(cv::Mat const&, cv::Mat&, double, double, int)", referenced from:
      _main in vision.o

ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [vision] Error 1

我很困惑;这是否意味着我安装的 OpenCV 是错误的,代码(特别是那些方法)需要更改,或者完全是其他什么?

注意:当我从 Vision.cpp 代码中注释掉问题方法时,一切都可以正常编译。

I recently inherited some OpenCV code. I installed openCV on my mac, built in in XCode, and then compiled and successfully ran my first openCV "hello world"-ish program.

Now I'm trying to run the code I was given, but I get errors that lead me to believe it's an issue with the original code being run on a 32-bit Windows system and mine being on a 64-bit Mac.

When I run the Makefile by entering "make"

CC = g++
CFLAGS =
LDFLAGS = -I/usr/local/include/opencv -lm -lopencv_core -lopencv_highgui -lopencv_video
ALL = vision

all: $(ALL)

vision: vision.o
    $(CC) $(LDFLAGS) -o $@ $^

vision.o: vision.cpp
    $(CC) $(LDFLAGS) -c 
lt;

.PHONY: clean

clean:
    rm -rf *.o core* $(ALL)

I get the following output…

g++ -I/usr/local/include/opencv -lm -lopencv_core -lopencv_highgui -lopencv_video -o vision vision.o
Undefined symbols for architecture x86_64:
  "cv::equalizeHist(cv::Mat const&, cv::Mat&)", referenced from:
      _main in vision.o
  "cv::threshold(cv::Mat const&, cv::Mat&, double, double, int)", referenced from:
      _main in vision.o

ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [vision] Error 1

I'm confused; does this mean my install of OpenCV is wrong, the code (those methods specifically) needs to be changed, or something else entirely?

Note: When I comment out the problem methods from the vision.cpp code, everything compiles just fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苏辞 2024-11-10 03:44:08

opencv_imgproc 添加到您的 LDFLAGS:

LDFLAGS = -I/usr/local/include/opencv -lm -lopencv_core -lopencv_highgui -lopencv_video -lopencv_imgproc

Add opencv_imgprocto your LDFLAGS:

LDFLAGS = -I/usr/local/include/opencv -lm -lopencv_core -lopencv_highgui -lopencv_video -lopencv_imgproc
天冷不及心凉 2024-11-10 03:44:08

这是一个工作示例:

CXX = g++

SOURCES = aaa.cpp bbb.cpp
OBJS = $(SOURCES:.cpp=.o)

CXXFLAGS = -I. -I/opt/local/include \
            -std=c++11 -stdlib=libc++ \
            -g3 -Wall -O0
            # -std=c++0x -arch x86_64 -stdlib=libc++ \

LDFLAGS = -L/opt/local/lib -L/usr/lib $(pkg-config --libs --cflags opencv) -lm -ljpeg
LDFLAGS = -L/opt/local/lib -L/usr/lib -I/opt/local/include/opencv -I/opt/local/include -L/opt/local/lib -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_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lm -ljpeg

.o:
    $(CXX) $(CXXFLAGS) -o $@ -c $^

all: $(OBJS)
    $(CXX) $(CXXFLAGS) $(LDFLAGS) -o out $(OBJS)

clean:
    rm -rf *.o

Here is a working example:

CXX = g++

SOURCES = aaa.cpp bbb.cpp
OBJS = $(SOURCES:.cpp=.o)

CXXFLAGS = -I. -I/opt/local/include \
            -std=c++11 -stdlib=libc++ \
            -g3 -Wall -O0
            # -std=c++0x -arch x86_64 -stdlib=libc++ \

LDFLAGS = -L/opt/local/lib -L/usr/lib $(pkg-config --libs --cflags opencv) -lm -ljpeg
LDFLAGS = -L/opt/local/lib -L/usr/lib -I/opt/local/include/opencv -I/opt/local/include -L/opt/local/lib -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_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lm -ljpeg

.o:
    $(CXX) $(CXXFLAGS) -o $@ -c $^

all: $(OBJS)
    $(CXX) $(CXXFLAGS) $(LDFLAGS) -o out $(OBJS)

clean:
    rm -rf *.o
鼻尖触碰 2024-11-10 03:44:08

您还可以让计算机自动猜测您的库:

CFLAGS = `pkg-config --cflags opencv` 
LDFLAGS = `pkg-config --libs opencv` -lm

You can also have the computer guess you the libraries automatically:

CFLAGS = `pkg-config --cflags opencv` 
LDFLAGS = `pkg-config --libs opencv` -lm
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文