Thread: CMake issue with Cairo or libX11

  1. #1
    Registered User
    Join Date
    Oct 2021
    Posts
    4

    CMake issue with Cairo or libX11

    Hi guys!

    CMake issue with Cairo or libX11

    Hi guys!

    I am new here and intend to frequent these forums both to answer questions and look for help when needed.

    Right now I am teaching myself CMake along with C and C Sharp. I have already been using C++ for a while.

    Right now though, I am having an issue with CMake and Cairo Graphics Library and libX11. I have a program I started, when I build I get this message:

    Undefined reference to symbol ‘XOpenDisplay’


    This is the line of code that generates that error:
    Display* d = XOpenDisplay(NULL);

    I update CMake with:
    cmake -S . -B build/

    When I do this it consistently tells me that it is successfully finding the libraries for cairo and libX11, those being:

    libXext.so and libXext.so

    This leads me to believe that there is something I need to do with my CMakeLists.txt that I am not seeing. I have looked all over, researched to death and am at a loss, so now I am posting for help. I am attaching my CMakeLists.txt

    I am using Arch Linux, my IDE is KDevelop. Thank you in advance.
    Attached Files Attached Files

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    The symbol is resolved by libX11.so
    Code:
    $ nm -D /usr/lib/x86_64-linux-gnu/libXext.so | grep XOpenDisplay
    $ nm -D /usr/lib/x86_64-linux-gnu/libX11.so | grep XOpenDisplay
    000000000002d370 T XOpenDisplay
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    FindX11 — CMake 3.22.0-rc1 Documentation

    I would try finding the X11 and then linking the libraries.

    X11_LIBRARIES

    You could try only changing

    Code:
    ${PROJECT_NAME} ${EXTRA_LINKS} glfw ${GLEW_LIBRARIES} GL GLU ${Cairo_LIBRARIES}
    to
    Code:
    ${PROJECT_NAME} ${EXTRA_LINKS} glfw ${GLEW_LIBRARIES} GL GLU ${Cairo_LIBRARIES} ${X11_LIBRARIES}
    But, I am thinking the find is needed to set X11_LIBRARIES

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Registered User
    Join Date
    Oct 2021
    Posts
    4
    Thanks. I just tried that, still getting the same error.

  5. #5
    Registered User
    Join Date
    Oct 2021
    Posts
    4
    UPDATE:

    I can now get a successful build with g++ Source/main.cpp -lX11

    Now I am learning to do this with CMake

  6. #6
    Registered User
    Join Date
    Oct 2021
    Posts
    4
    Solved:

    This solved it:
    Code:
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lX11")
    you guys were very helpful in getting me to look in the right direction on things.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CMake help?
    By Chris87 in forum C Programming
    Replies: 1
    Last Post: 04-06-2019, 06:21 PM
  2. CMake - Specifying Compiler flags to be run
    By Asymptotic in forum C Programming
    Replies: 0
    Last Post: 07-02-2018, 10:51 PM
  3. Cmake file dependancy
    By King Mir in forum C++ Programming
    Replies: 6
    Last Post: 12-26-2017, 08:03 AM
  4. cairo-dock issue
    By Annonymous in forum Linux Programming
    Replies: 2
    Last Post: 06-03-2012, 12:14 AM
  5. i need help with cmake, BISON and FLEX, i am willing to pay
    By Yakir Manor in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 01-17-2012, 04:54 PM

Tags for this Thread