0

i'm currently trying to port a Qmake project to Cmake. I'm facing problems including the gstreamer library through pkgconfig. My Qmake, which works, is :

INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += \
    $$PWD/QmlVideoPlayer.hpp
SOURCES += \
    $$PWD/private/QmlVideoPlayer.cpp
unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += gstreamer-1.0
unix: PKGCONFIG += gstreamer-video-1.0

The cmake seems like:

find_package(PkgConfig REQUIRED)
find_package(Qt5 COMPONENTS Core Gui Quick Widgets REQUIRED)
if(NOT PKG_CONFIG_FOUND)
  message(FATAL_ERROR "pkg-config not found!" )
endif()
pkg_check_modules(GST REQUIRED gstreamer-1.0 gstreamer-video-1.0)
include_directories(${GST_INCLUDE_DIRS})
link_directories(${GST_LIBRARY_DIRS})
add_definitions(${GST_CFLAGS_OTHER})
add_library(qmlvideoplayer
    QmlVideoPlayer.hpp
    private/QmlVideoPlayer.cpp
)
target_link_libraries(qmlvideoplayer
    PRIVATE Qt5::Core Qt5::Gui Qt5::Quick Qt5::Widgets
    PUBLIC ${GST_LIBRARIES})

The build works fine if deployed locally, but when i try to deploy in an external board (Linux OS) it trhows the following errors:

error: WARNING: unsafe header/library path used in cross-compilation: '-I/usr/include/gstreamer-1.0'
error: WARNING: unsafe header/library path used in cross-compilation: '-I/usr/include/glib-2.0'
error: WARNING: unsafe header/library path used in cross-compilation: '-I/usr/lib/glib-2.0/include'
error: glibconfig.h: No such file or directory
error: ninja: build stopped: subcommand failed.

The libraries path in the external board is:

root@test:/usr/share# ls
alsa              fontconfig        gst-plugins-base  sounds
dhcpcd            fonts             gstreamer-1.0     terminfo
drirc.d           gettext           icons             udhcpc
ffmpeg            glib-2.0          locale            xml

Any idea about how to accomplish this porting?

  • 1
    Something wrong in your [toolchain file](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling) which you pass to CMake via `CMAKE_TOOLCHAIN_FILE` parameter when **cross-compile** your project. The toolchain shouldn't allow `find_*` commands to search things under the host. And no, `/usr/share` is never a path to the libraries. Under the `share/` subdirectory the packages are usually stored their architecture-independent **data**. The libraries are normally contained under `lib*/` subdirectory. – Tsyvarev Apr 19 '23 at 14:51
  • Hi, thank you for your answer. The libraries I need are not found in lib subdirectory. I cannot modify the bsp, and so, the location of the library. I haven't specified the path of the toolchain file anywhere, so where can I find it and where can I put it? Also, I've never specified such file with QMake and everything was working fine. – mungimatte Apr 19 '23 at 15:33
  • 1
    The [link](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling) in my previous comment contains many information about what a toolchain file is and how to write it. Cross-compiling without a toolchain file is wrong: https://stackoverflow.com/a/63944545/3440745 – Tsyvarev Apr 19 '23 at 16:20
  • I've said something wrong in the previous comment, actually i'm compiling through QTCreator which creates an integrated toolchain at build phase. But to me, is not clear how to specify where to look for the libraries. Just to be clear the libraries are located in /usr/lib. – mungimatte Apr 20 '23 at 10:15
  • "Just to be clear the libraries are located in /usr/lib" - But you have the clear warning that paths from `/usr/lib` shouldn't be used for cross-compilation: `unsafe header/library path used in cross-compilation: '-I/usr/lib/glib-2.0/include'`. It seems you don't quite understand what you are doing... – Tsyvarev Apr 20 '23 at 10:46
  • I think you are right, I don't know where to put my hand – mungimatte Apr 20 '23 at 14:49
  • the main problem is probably that the library gstreamer has wrong paths. The bsp has the library files stored in a location which is not the "default" one. For this reason every time I try to cross-compile I get an error as a result. I don't know how to indicate the correct path to the compiler. – mungimatte Apr 21 '23 at 14:46
  • If your cross-compiling setup involves sysroot, then set `CMAKE_SYSROOT` variable. This is covered in the link about toolchains which I have posted in the first comment. If your cross-compiling involves other directory with prebuilt libraries for the target machine, then setting [CMAKE_FIND_ROOT_PATH](https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_ROOT_PATH.html) could help. Note, that `PkgConfig` module and its command `pkg_check_modules` use `pkg-config` utility, so make sure that your prebuild libraries have `.pc` files. – Tsyvarev Apr 21 '23 at 15:30
  • I followed your advice, firstly I checked within my buildroot the path of the libraries (/home/user/Downloads/buildroot/buildroot-linux/sysroot/usr/lib) and I set the variable CMAKE-SYSROOT with previous path, with poor results. secondly, for test, I set the variable CMAKE_FIND_ROOT_PATH with the same path but even in this with poor results. I also checked the existence of the .pc files and they do exist. any other tips? – mungimatte Apr 26 '23 at 07:27
  • If you suspect that pkg-config finds host `.pc` files instead of ones under sysroot, then you could check [that question](https://stackoverflow.com/questions/9221236/pkg-config-fails-to-find-package-under-sysroot-directory) and its answers. – Tsyvarev Apr 26 '23 at 09:10
  • I don't think this is the problem, I tried to follow the advice from the other forum but it was not helpful – mungimatte Apr 27 '23 at 06:44
  • Please note, that Stack Overflow is NOT a help desk. We create a library of Question/Answer pairs, and treat every question post as a candidate for such pair. In the current form your question doesn't fit for that role because it lacks for details which are vital for answering. Comments are used for request improvement of the post. But if after several iterations of comments a **question post** still doesn't contain sufficient details, then it means the post doesn't fit for our library at all. – Tsyvarev Apr 27 '23 at 07:37
  • Addios hermano (AT SALUDI) – mungimatte Apr 27 '23 at 08:03

0 Answers0