Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I include and link libxml2 using CMakeLists?
Forum Update on Monday, May 27th 2025

How do I include and link libxml2 using CMakeLists?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 986 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    txtsd
    wrote on 27 Dec 2020, 18:49 last edited by
    #1

    What is the correct way to include and link libxml2?

    I'm not able to find any sample code, and what I've tried results in a:

    :-1: error: cannot find -lLibXml2
    :-1: error: collect2: error: ld returned 1 exit status
    

    This is what I have in my CMakeLists.txt

    ...
    find_package(LibXml2 REQUIRED)
    include_directories(/usr/include/libxml2)
    link_libraries(LibXml2)
    target_link_libraries(xxx PRIVATE
      Qt5::Widgets
      Qt5::Network
      Qt5::Gui
      LibXml2::LibXml2
    )
    
    C 1 Reply Last reply 27 Dec 2020, 19:02
    0
    • T txtsd
      27 Dec 2020, 18:49

      What is the correct way to include and link libxml2?

      I'm not able to find any sample code, and what I've tried results in a:

      :-1: error: cannot find -lLibXml2
      :-1: error: collect2: error: ld returned 1 exit status
      

      This is what I have in my CMakeLists.txt

      ...
      find_package(LibXml2 REQUIRED)
      include_directories(/usr/include/libxml2)
      link_libraries(LibXml2)
      target_link_libraries(xxx PRIVATE
        Qt5::Widgets
        Qt5::Network
        Qt5::Gui
        LibXml2::LibXml2
      )
      
      C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 27 Dec 2020, 19:02 last edited by
      #2

      @txtsd said in How do I include and link libxml2 using CMakeLists?:

      link_libraries(LibXml2)

      This is wrong and not needed at all.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • T Offline
        T Offline
        txtsd
        wrote on 27 Dec 2020, 19:06 last edited by
        #3

        Excellent! Removing that line made it compile!

        1 Reply Last reply
        0

        1/3

        27 Dec 2020, 18:49

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved