我是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
我已经在这个问题上工作了好几天。任何帮助或建议将非常感激。
由于
答案 0 :(得分:1)
问题来自你的链接器调用:
库选项(-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