gpt4 book ai didi

c++ - c++ 程序的 Makefile 无法正确编译

转载 作者:太空宇宙 更新时间:2023-11-03 22:48:51 27 4
gpt4 key购买 nike

我对 C++ Makefile 很陌生。最近,我正在尝试重新实现本文介绍的密集轨迹算法:https://lear.inrialpes.fr/people/wang/dense_trajectories

但是,我很长一段时间都在为他们提供的 Makefile 而苦恼。 Makefile如下:

# set the binaries that have to be built
TARGETS := DenseTrack Video

# set the build configuration set
BUILD := release
#BUILD := debug

# set bin and build dirs
BUILDDIR := .build_$(BUILD)
BINDIR := $(BUILD)

# libraries
LDLIBS = $(addprefix -l, $(LIBS) $(LIBS_$(notdir $*)))
LIBS := \
opencv_core opencv_highgui opencv_video opencv_imgproc \
avformat avdevice avutil avcodec swscale

# set some flags and compiler/linker specific commands
CXXFLAGS = -pipe -D __STDC_CONSTANT_MACROS -D STD=std -Wall $(CXXFLAGS_$(BUILD)) -I. -I/usr/local/include -I/home/wei/ffmpeg_build/include
CXXFLAGS_debug := -ggdb
CXXFLAGS_release := -O3 -DNDEBUG -ggdb
LDFLAGS = -L/usr/local/lib -L/home/wei/ffmpeg_build/lib -pipe -Wall $(LDFLAGS_$(BUILD))
LDFLAGS_debug := -ggdb
LDFLAGS_release := -O3 -ggdb

include make/generic.mk

我可以通过运行使用这两个库的示例来验证我的 opencv2.4.2 和 ffmpeg5.4.0 是否已成功安装在 Ubuntu 16.04 中。

对于 opencv:lib路径为:/usr/local/lib

libavcodec.a                   libopencv_gpu.so.2.4   
libopencv_photo.so.2.4
libavdevice.a libopencv_gpu.so.2.4.2 libopencv_photo.so.2.4.2
libavfilter.a libopencv_highgui.so libopencv_stitching.so
libavformat.a libopencv_highgui.so.2.4 libopencv_stitching.so.2.4
libavutil.a libopencv_highgui.so.2.4.2 libopencv_stitching.so.2.4.2
libopencv_calib3d.so libopencv_imgproc.so libopencv_ts.so
libopencv_calib3d.so.2.4 libopencv_imgproc.so.2.4 libopencv_ts.so.2.4
libopencv_calib3d.so.2.4.2 libopencv_imgproc.so.2.4.2 libopencv_ts.so.2.4.2
libopencv_contrib.so libopencv_legacy.so libopencv_video.so
libopencv_contrib.so.2.4 libopencv_legacy.so.2.4 libopencv_video.so.2.4
libopencv_contrib.so.2.4.2 libopencv_legacy.so.2.4.2 libopencv_video.so.2.4.2
libopencv_core.so libopencv_ml.so libopencv_videostab.so
libopencv_core.so.2.4 libopencv_ml.so.2.4 libopencv_videostab.so.2.4
libopencv_core.so.2.4.2 libopencv_ml.so.2.4.2 libopencv_videostab.so.2.4.2
libopencv_features2d.so libopencv_nonfree.so libpostproc.a
libopencv_features2d.so.2.4 libopencv_nonfree.so.2.4 libswresample.a
libopencv_features2d.so.2.4.2 libopencv_nonfree.so.2.4.2 libswscale.a
libopencv_flann.so libopencv_objdetect.so pkgconfig
libopencv_flann.so.2.4 libopencv_objdetect.so.2.4 python2.7
libopencv_flann.so.2.4.2 libopencv_objdetect.so.2.4.2 python3.5
libopencv_gpu.so libopencv_photo.so

包含路径为:usr/local/include:

libavcodec   libavfilter  libavutil    libswresample  opencv
libavdevice libavformat libpostproc libswscale opencv2

对于 ffmpeg:lib路径为:/home/user/ffmpeg_build/lib

libavcodec.a   libavfilter.a  libavutil.a   libfdk-aac.la  libswresample.a  libx265.a
libavdevice.a libavformat.a libfdk-aac.a libpostproc.a libswscale.a pkgconfig

包含路径为:/home/user/ffmpeg/include

fdk-aac     libavdevice  libavformat  libpostproc    libswscale     x265.h
libavcodec libavfilter libavutil libswresample x265_config.h

因此,当我使用 Makefile 进行编译时,我没有遇到错误,但似乎链接工作正常,编译后的输出也不正常。

我试过直接用g++命令编译。

sudo g++ -o Video -pipe -D __STDC_CONSTANT_MACROS -D STD=std -Wall -I. -I/usr/local/include -O3 -DNDEBUG -ggdb -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_video -lopencv_imgproc -lavformat -lavdevice -lavutil -lavcodec -lswscale *.h Video.cpp

但是,它返回错误如下:

/tmp/ccjYmwI4.o: In function `main':
/home/wei/Documents/dt/dense_trajectory_release_v1.2/Video.cpp:33: undefined reference to `cvCreateFileCapture'
/home/wei/Documents/dt/dense_trajectory_release_v1.2/Video.cpp:48: undefined reference to `cvQueryFrame'
/home/wei/Documents/dt/dense_trajectory_release_v1.2/Video.cpp:57: undefined reference to `cvCopy'
/home/wei/Documents/dt/dense_trajectory_release_v1.2/Video.cpp:60: undefined reference to `cvShowImage'
/home/wei/Documents/dt/dense_trajectory_release_v1.2/Video.cpp:61: undefined reference to `cvWaitKey'
/home/wei/Documents/dt/dense_trajectory_release_v1.2/Video.cpp:53: undefined reference to `cvCreateImage'
/home/wei/Documents/dt/dense_trajectory_release_v1.2/Video.cpp:70: undefined reference to `cvDestroyWindow'
/home/wei/Documents/dt/dense_trajectory_release_v1.2/Video.cpp:41: undefined reference to `cvNamedWindow'
collect2: error: ld returned 1 exit status

几天来我一直在研究这个问题。任何帮助或建议将不胜感激。

谢谢

最佳答案

问题来自您的链接器调用:

库选项 (-l) 必须在要编译或链接的代码之后:

正确:

 # code in foo.cpp need function in libmylib.so
g++ foo.cpp -lmylib

# code in foo.o need function in libmylib.so
g++ foo.o -lmylib

不正确:

 # code in foo.cpp need function in libmylib.so
g++ -lmylib foo.cpp

# code in foo.o need function in libmylib.so
g++ -lmylib foo.o

关于c++ - c++ 程序的 Makefile 无法正确编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42895006/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com