我已成功交叉编译qt5.5.1和opencv3.1.0,也存在问题(烦恼!)。
让我在datail中说出来:
a。在我的电脑ubunutu上,当用opencv编译qt程序时,我通常有两种方式,
第一个是在qt IDE中,我在.pro
中添加了两行#.pro
CONFIG += link_pkgconfig
PKGCONFIG += opencv
第二个是在终端,命令行例如:
g++ main.cpp -o main `pkg-config opencv --cflags --libs`
我知道运行时可以使用pkg-config的原因
echo $PKG_CONFIG_PATH
我明白了:
:/usr/local/opencv-3.1.0/lib/pkgconfig:/usr/local/opencv-3.1.0/lib/pkgconfig:
湾对于交叉编译,我如何使用pkg-config?
我尝试通过添加:
来编辑/home/lmk/.bashrcPKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/newdisk/optnew/opencv-arm/lib/pkgconfig
export PKG_CONFIG_PATH
然后打开一个新终端,运行:
echo $PKG_CONFIG_PATH
给了我:
:/usr/local/opencv-3.1.0/lib/pkgconfig:/usr/local/opencv-3.1.0/lib/pkgconfig:/home/newdisk/optnew/opencv-arm/lib/pkgconfig
问题是: 首先,在qt IDE中编辑.pro
#.pro
CONFIG += link_pkgconfig
PKGCONFIG += arm-opencv
结果是:
:-1: error: arm-opencv development package not found
第二,在终端时:
arm-linux-g++ `pkg-config arm-opencv --cflags --libs` show.cpp -lpthread -lrt -o show
/home/newdisk/optnew/opt/FriendlyARM/toolschain/4.5.1/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: libavcodec.so.57, needed by /home/newdisk/optnew/opencv-arm/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/home/newdisk/optnew/opt/FriendlyARM/toolschain/4.5.1/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: libavformat.so.57, needed by /home/newdisk/optnew/opencv-arm/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/home/newdisk/optnew/opt/FriendlyARM/toolschain/4.5.1/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: libavutil.so.55, needed by /home/newdisk/optnew/opencv-arm/li/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/home/newdisk/optnew/opt/FriendlyARM/toolschain/4.5.1/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: libswscale.so.4, needed by /home/newdisk/optnew/opencv-arm/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/home/newdisk/optnew/opt/FriendlyARM/toolschain/4.5.1/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: libjpeg.so.9, needed by /home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/home/newdisk/optnew/opt/FriendlyARM/toolschain/4.5.1/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: libpng16.so.16, needed by /home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_set_defaults@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_dict_free@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_alloc_huff_table@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_expand_gray_1_2_4_to_8@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avformat_free_context@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_read_end@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_write_info@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_swap@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_gray_to_rgb@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avformat_open_input@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `sws_getCachedContext@LIBSWSCALE_4'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_write_trailer@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_CreateCompress@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_free@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_read_info@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_destroy_read_struct@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avformat_find_stream_info@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avio_open@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_guess_codec@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_set_quality@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avpicture_get_size@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_read_image@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_stdio_src@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_create_read_struct@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_rgb_to_gray@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_filter@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_frame_free@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_log_set_level@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_init_io@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_IHDR@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_get_IHDR@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_free_packet@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_create_write_struct@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_read_update_info@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_seek_frame@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_write_frame@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_longjmp_fn@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avpicture_fill@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_resync_to_restart@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_destroy_compress@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_get_tRNS@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_dict_set@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_rescale_q@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avformat_get_riff_video_tags@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_finish_decompress@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_write_end@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avcodec_get_context_defaults3@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avformat_network_init@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avformat_write_header@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_read_fn@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_bgr@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avformat_get_mov_video_tags@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `sws_freeContext@LIBSWSCALE_4'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_write_scanlines@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_destroy_write_struct@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_frame_alloc@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_read_header@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `sws_getContext@LIBSWSCALE_4'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_CreateDecompress@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_finish_compress@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avcodec_find_encoder@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_start_decompress@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_create_info_struct@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_compression_strategy@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_init_packet@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_interlace_handling@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_strip_alpha@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_compression_level@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_reduce@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_malloc@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avcodec_encode_video2@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_freep@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avio_close@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_read_frame@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avcodec_flush_buffers@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avcodec_decode_video2@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_quality_scaling@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_start_compress@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avformat_alloc_context@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_error@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_sub_q@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_guess_format@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_simple_progression@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avformat_new_stream@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `sws_scale@LIBSWSCALE_4'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_destroy_decompress@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_std_error@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_write_image@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avcodec_find_decoder@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_stdio_dest@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_register_all@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_get_io_ptr@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_write_fn@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avcodec_open2@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_packing@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_codec_get_tag@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_palette_to_rgb@PNG16_0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_lockmgr_register@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_default_qtables@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_opt_set@LIBAVUTIL_55'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_calc_output_dimensions@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avcodec_close@LIBAVCODEC_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `av_codec_get_id@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_videoio.so: undefined reference to `avformat_close_input@LIBAVFORMAT_57'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_read_scanlines@LIBJPEG_9.0'
/home/newdisk/optnew/opencv-arm/lib/libopencv_imgcodecs.so: undefined reference to `png_set_strip_16@PNG16_0'
collect2: ld returned 1 exit status
此外,交叉编译器安装在
中/home/newdisk/optnew/opt/FriendlyARM/toolschain/4.5.1/bin
crosscompile qt安装在
中/home/newdisk/optnew/qt5.5.1
crosscompile opencv安装在
中/home/newdisk/optnew/opencv-arm
crosscompile opencv的第三方安装在
中/home/newdisk/optnew/opencv-rely
opencv的第三方是:
zlib
jpeg
libpng
yasm
x264
xvidcore
ffmpeg
我应该如何设置我的环境变量以使pkg-config运行良好,以便我的程序可以找到opencv以及opencv-depend的include和lib目录?
答案 0 :(得分:0)
昨晚,我通过添加opencv和opencv的第三方库来尝试最直接的方式:
#.pro
######################################################################
# Automatically generated by qmake (3.0) Mon Nov 14 13:01:31 2016
######################################################################
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TEMPLATE = app
TARGET = ImageShow
INCLUDEPATH += .
# Input
HEADERS += mywidget.h
SOURCES += main.cpp mywidget.cpp
INCLUDEPATH+=/home/newdisk/optnew/opencv-arm/include
LIBS += /home/newdisk/optnew/opencv-arm/lib/libopencv_*.so \ //all opencv libs
/home/newdisk/optnew/opencv-rely/lib/libavcodec.so \ //opencv's 3rdparty libs
/home/newdisk/optnew/opencv-rely/lib/libavdevice.so \
/home/newdisk/optnew/opencv-rely/lib/libavfilter.so \
/home/newdisk/optnew/opencv-rely/lib/libavformat.so \
/home/newdisk/optnew/opencv-rely/lib/libavutil.so \
/home/newdisk/optnew/opencv-rely/lib/libjpeg.so \
/home/newdisk/optnew/opencv-rely/lib/libpng.so \
/home/newdisk/optnew/opencv-rely/lib/libpostproc.so \
/home/newdisk/optnew/opencv-rely/lib/libswresample.so \
/home/newdisk/optnew/opencv-rely/lib/libswscale.so \
/home/newdisk/optnew/opencv-rely/lib/libx264.so \
/home/newdisk/optnew/opencv-rely/lib/libxvidcore.so \
/home/newdisk/optnew/opencv-rely/lib/libz.so
我交叉编译了qt程序并成功地在我的扶手板上运行,这也表明我的配置是正确的。
我想知道你们中的任何人都有一些简单的方法来搜索相对的libs,无论是在qt中还是在cmake中,还是只是在termial中。我是一位绿色的手,真诚地感谢您的回复!