关闭

编译qt5中的multimedia时出fatal error: xxx No such file or directory

2031人阅读 评论(0) 收藏 举报
分类:

问题描述:

利用buildroot勾选中QT5中的multimedia,编译时出现如下错误:

In file included from ../../include/QtMultimedia/qtmultimediadefs.h:1:0,
                 from qmediaservice.h:37,
                 from qmediaservice.cpp:34:
../../include/QtMultimedia/../../src/multimedia/qtmultimediadefs.h:48:28: fatal error: QtCore/qglobal.h: No such file or directory
 #include <QtCore/qglobal.h>
                            ^
compilation terminated.
qmediaobject.cpp:34:32: fatal error: QtCore/qmetaobject.h: No such file or directory
 #include <QtCore/qmetaobject.h>
                                ^
compilation terminated.
make[4]: *** [.obj/qmediaobject.o] Error 1
make[4]: *** Waiting for unfinished jobs....
In file included from qmediapluginloader_p.h:48:0,
                 from qmediapluginloader.cpp:34:
./qtmultimediadefs.h:48:28: fatal error: QtCore/qglobal.h: No such file or directory
 #include <QtCore/qglobal.h>
                            ^
compilation terminated.
make[4]: *** [.obj/qmediapluginloader.o] Error 1
make[4]: *** [.obj/qmediaservice.o] Error 1
make[3]: *** [sub-multimedia-make_first] Error 2
make[2]: *** [sub-src-make_first] Error 2
make[1]: *** [/home/anzyelay/Downloads/buildroot-2016.05/output/build/qt5multimedia-5.6.0/.stamp_built] Error 2

解决过程:

In file included from
../../include/QtMultimedia/qtmultimediadefs.h:1:0,
from qmediaservice.h:37,
from qmediaservice.cpp:34:

这段说明错误原因是从qmediaservice.cpp:34行开始的,并由些追述到 include/QtMultimedia/qtmultimediadefs.h:1行,
在这个文件中的#include <QtCore/qglobal.h>,编译器无法找到.<QtCore/qmetaobject.h>也是一样的,都是无法定位。find了一下,在buildroot目录下存在多个此文件,

anzyelay@ubuntu:buildroot-2016.05$ find . -name qmediaobject.h
./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/include/qt5/QtMultimedia/qmediaobject.h
./output/build/qt5multimedia-5.6.0/include/QtMultimedia/qmediaobject.h
./output/build/qt5multimedia-5.6.0/src/multimedia/qmediaobject.h
anzyelay@ubuntu:buildroot-2016.05$ 

我也是个qt新手,网上搜了好多没有解决的办法,刚开始自己想了个死办法直接修改错误文件更改include到找到的目录文件,可是会接连出现N多问题,这是死胡同,后来直接定位到multimedia项目中的.pro文件中,在此增加INCLUDEPATH路径,还是有点效果的。
先找个项目文件.pro ,打开编辑
anzyelay@ubuntu:buildroot-2016.05$ vi output/build/qt5multimedia-5.6.0/src/multimedia/multimedia.pro
要添加的目录由find找到目标文件后直接将include目录添加进来吧,省的麻烦,如果后面还有类似未找到的,就依上逐个添加,

  1 TARGET = QtMultimedia                                                                           
  2 QT = core-private network gui-private
  3 
  4 MODULE_PLUGIN_TYPES = \
  5     mediaservice \
  6     audio \
  7     video/bufferpool \
  8     video/gstvideorenderer \
  9     video/videonode \
 10     playlistformats \
 11     resourcepolicy
 12 
 13 QMAKE_DOCS = $$PWD/doc/qtmultimedia.qdocconf
 14 
 15 load(qt_module)
 16 
 17 INCLUDEPATH *= .
 ##以下是我添加的
 18 INCLUDEPATH +=/home/anzyelay/Downloads/buildroot-2016.05/output/build/qt5base-5.6.0/include

 ##以上是我添加的
 20 
 21 PRIVATE_HEADERS += \
 22     qmediacontrol_p.h \
 23     qmediaobject_p.h \
 24     qmediapluginloader_p.h \
 25     qmediaservice_p.h \
 26     qmediaserviceprovider_p.h \
 27     qmediaresourcepolicyplugin_p.h \
 28     qmediaresourcepolicy_p.h \
 29     qmediaresourceset_p.h \
 30     qmediastoragelocation_p.h \
 31     qmediaopenglhelper_p.h \
 32     qmultimediautils_p.h

忘了说,修改好后make如果不行就试试删除同层次目录及下层中的所有Makefile,重新make时qmake会依此修改的.pro文件新建

重新make后的问题就变了,而且是可喜的变化换成了另一些个同类错误,说明上述方法OK,新错误如下:

qmediapluginloader.cpp:38:38: fatal error: private/qfactoryloader_p.h: No such file or directory
 #include <private/qfactoryloader_p.h>
                                      ^
compilation terminated.
make[4]: *** [.obj/qmediapluginloader.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [sub-multimedia-make_first] Error 2
make[2]: *** [sub-src-make_first] Error 2
make[1]: *** [/home/anzyelay/Downloads/buildroot-2016.05/output/build/qt5multimedia-5.6.0/.stamp_built] Error 2
make: *** [_all] Error 2

一样的错误格式吧,只不过终于换了头文件,同样找到该文件,然后将目录加入就好,

总共加的有这些:

INCLUDEPATH +=/home/anzyelay/Downloads/buildroot-2016.05/output/build/qt5base-5.6.0/include
INCLUDEPATH +=/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/include
INCLUDEPATH +=/home/anzyelay/Downloads/buildroot-2016.05/output/build/qt5base-5.6.0/include/QtCore/5.6.0/QtCore
INCLUDEPATH +=/home/anzyelay/Downloads/buildroot-2016.05/output/build/qt5base-5.6.0/include/QtCore
INCLUDEPATH +=/home/anzyelay/Downloads/buildroot-2016.05/output/build/qt5base-5.6.0/include/QtGui

这些都ok了,这次就出现新问题了

/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find crti.o: No such file or directory
/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find -lQt5Network
/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find -lQt5Gui
/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find -lQt5Core
/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find -lrt
/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find -ldl
/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find -lpthread
/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find -lm
collect2: error: ld returned 1 exit status
make[4]: *** [../../lib/libQt5Multimedia.so.5.6.0] Error 1
make[3]: *** [sub-multimedia-make_first] Error 2
make[2]: *** [sub-src-make_first] Error 2
make[1]: *** [/home/anzyelay/Downloads/buildroot-2016.05/output/build/qt5multimedia-5.6.0/.stamp_built] Error 2
make: *** [_all] Error 2

上面中除第一个错误外,错误格式如下的:

arm-buildroot-linux-gnueabi/bin/ld: cannot find -lXXXX 

这是由于编译器找不到相应的lib库,同样我们find . -name libXXXX,然后在.pro文件中增加就行
格式如下:

LIBS += -L+目录名  (不要有空隔)
LIBS += -l+库文件名   (.so可以省去)

我修改后如下:

LIBS += \
 27     -L/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/arm-buildroot-linux-gnueabi/sys    root/usr/lib/ \
 28     -L/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/arm-buildroot-linux-gnueabi/sys    root/

再次make后错误信息如下:

/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find crti.o: No such file or directory
/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find /lib/libpthread.so.0
/home/anzyelay/Downloads/buildroot-2016.05/output/host/usr/lib/gcc/arm-buildroot-linux-gnueabi/4.9.3/../../../../arm-buildroot-linux-gnueabi/bin/ld: cannot find /usr/lib/libpthread_nonshared.a
collect2: error: ld returned 1 exit status
make[4]: *** [../../lib/libQt5Multimedia.so.5.6.0] Error 1
make[3]: *** [sub-multimedia-make_first] Error 2
make[2]: *** [sub-src-make_first] Error 2
make[1]: *** [/home/anzyelay/Downloads/buildroot-2016.05/output/build/qt5multimedia-5.6.0/.stamp_built] Error 2
make: *** [_all] Error 2

依然上面中除第一个错误外,错误格式如下的:

arm-buildroot-linux-gnueabi/bin/ld: cannot find /path/to/libxxx

我开始按上面的法子发现没有效果,然后grep 了一下,有大发现了:

anzyelay@ubuntu:buildroot-2016.05$ grep 'libpthread_nonshared' . -r
grep: ./system/skeleton/etc/resolv.conf: No such file or directory
grep: ./system/skeleton/dev/log: No such file or directory
./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/lib/libpthread.so:GROUP ( /lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a )
./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/lib32/libpthread.so:GROUP ( /lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a )

/lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a 两个错误的库都是因它libpthread.so而起,百度了下,这文件居然可以改,又学习了,
vi ./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/lib/libpthread.so

  1 /* GNU ld script                                                                                
  2    Use the shared library, but some functions are only in
  3    the static library, so try that secondarily.  */
  4 OUTPUT_FORMAT(elf32-littlearm)
  5 GROUP ( /lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a )

重新find下libpthread.so.0和libpthread_nonshared.a,找到相应位置,更改之

anzyelay@ubuntu:buildroot-2016.05$ find . -name libpthread*
./package/libpthread-stubs
./package/libpthread-stubs/libpthread-stubs.hash
./package/libpthread-stubs/libpthread-stubs.mk
./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/lib/libpthread.so
./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/lib/libpthread.a
./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/usr/lib/libpthread_nonshared.a
./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/lib/libpthread.so.0
./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/lib/libpthread-2.22.so
./output/target/lib/libpthread.so.0
./output/target/lib/libpthread-2.22.so

依此更改如下:

5 GROUP ( ../../lib/libpthread.so.0 libpthread_nonshared.a )

再次make,ok了,

第一个错误ld: cannot find crti.o: No such file or directory,一直得不到解决,换个其它地方下载的编译器就OK了,不知道buildroot编译出来的gcc哪里不对。。

总结

在QT项目中如有出现编译器无法找到某个文件时,可以自己通过修改.pro文件来增加编译器的寻找路径,无认是fatal error: xxx No such file or directorycannot find -lXXX
如果找不到函数定义,未知符什么的,这才需要在代码中增加对应头文件。

具体方法:

  • 如果是出现 yyy/xxx.h: No such file or directory
    find . -name xxx.h
    如果找到的结果是:path/to/yyy/xxx.h
    在.pro中添加:
    INCLUDEPATH += path/to
    注意yyy就不需要了。
  • 如果是出现 ld: cannot find -lxxx
    find . -name libxxx*
    在.pro中添加:
    目录用-L ,某个库文件用-l,L/l与目录或文件之间不要有空隔
    LIBS += -Lpath/to/lib
    或LIBS += -lxxx.so

  • 如果出现的是: ld: cannot find /path/to/xxx
    那是相应的编译器的库连接文件libxxx.so连接到的实际库路径有问题,修改libxxx.so里对应的库到正确的指向。buildroot做出来的gcc为什么会有路径不正常的情况????不明白,BUG吧

.pro文件的说明格式自行百度。这里有一篇QT中PRO文件写法的详细介绍,很有用,很重要!

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:76131次
    • 积分:1571
    • 等级:
    • 排名:千里之外
    • 原创:85篇
    • 转载:5篇
    • 译文:0篇
    • 评论:14条
    文章分类
    最新评论