Linking libraries to a QT project using pkg-config output

前端 未结 5 1298
太阳男子
太阳男子 2020-12-09 02:32

This is a bit of a newbie question. I am trying to add the OpenCV libraries to a QT project.

This question says the link flags are given by

pkg-confi         


        
相关标签:
5条回答
  • 2020-12-09 03:01

    Something like this in your qmake file should do

    LIBS += `pkg-config --libs opencv`
    

    Edit: Hmm, Ken Bloom's answer might be more portable, but erhm not documented?

    0 讨论(0)
  • 2020-12-09 03:14
    CONFIG += link_pkgconfig
    PKGCONFIG += opencv
    

    (I got this answer from http://beaufour.dk/blog/2008/02/using-pkgconfig.html)

    0 讨论(0)
  • 2020-12-09 03:14

    Ken's answer worked great. I just had to remove the spaces on either side of the += first.

    CONFIG+=link_pkgconfig PKGCONFIG+=opencv
    
    0 讨论(0)
  • 2020-12-09 03:16

    In the newer version of Qt, this needs to be done to avoid a package not found error:

    QT_CONFIG -= no-pkg-config
    CONFIG += link_pkgconfig
    PKGCONFIG += protobuf #or whatever package here
    

    Also had to do this for Mac:

    mac {
      PKG_CONFIG = /usr/local/bin/pkg-config
    }
    
    0 讨论(0)
  • 2020-12-09 03:21

    Add the following lines to your .pro file:

    INCLUDEPATH += `pkg-config --cflags opencv`
    LIBS += `pkg-config --libs opencv`
    
    0 讨论(0)
提交回复
热议问题