How to use X11 in XCode?

Discussion in 'Mac Programming' started by Asuka', Dec 23, 2012.

  1. macrumors newbie

    Joined:
    Dec 23, 2012
    Location:
    Paris, FRANCE
    #1
    Hi everybody!

    First, sorry if my english is bad, I'm french so I may do some mistakes! =)

    I'm a student, and my school gave me the source code of a program, written in C.
    I have to finish that one.

    But this program is using X11 libraries, and we don't have these libs on Mac OSX since 10.5 or 10.6 right?
    Whatever, my MBP is running on Mountain Lion, so I don't have these libs and XCode tells me:
    #include <X11/Xlib.h>
    -> X11/Xlib.h not found

    So I've installed XQuartz, but I've the same issue! =/

    I've read something that I should make an "External Build System" project and use my own build tool or something like that, but I don't understand how to do this... (I tried to install CMake, but what should I do next?)

    Someone can explain me how to build my program?

    Thanks for your attention, and merry christmas for the next days! =)

    PS: Sorry again if my english is pretty bad
     
  2. LPZ
    macrumors 65816

    Joined:
    Jul 11, 2006
    #2
    If you installed XQuartz then the X11 headers and libraries are installed in /opt/X11. For example, the header Xlib.h is in /opt/X11/include/X11. You need to inform XCode where to find the header. You could try changing #include <X11/Xlib.h> to #include "/opt/X11/include/X11/Xlib.h" .

    I don't use XCode, but another option would be to modify the path that XCode uses when searching for headers. You'll need to consult the XCode documentation, or wait for a more enlightened user to reply.
     
  3. macrumors member

    Joined:
    Jul 24, 2012
    Location:
    NSW, Australia
    #3
    I'm pretty sure you can do that by:
    1. Selecting the Xcode project file in the Project Navigator (the left sidebar's folder icon)
    2. Click the Build Settings tab
    3. Find the "Header Search Paths" setting, and add /opt/X11/include
     
  4. LPZ
    macrumors 65816

    Joined:
    Jul 11, 2006
    #4
    Thanks. This seems the right way to proceed. My earlier suggestion (to edit the source file) might help XCode find the one header file, but undoubtably Xlib.h will want to include additional header files, which will also need to be found.

    I'm puzzled/curious about what kind of programming exercise this is, that needs to include X11 headers.
     
  5. Asuka', Dec 23, 2012
    Last edited: Dec 23, 2012

    thread starter macrumors newbie

    Joined:
    Dec 23, 2012
    Location:
    Paris, FRANCE
    #5
    Thanks for answering me, XCode now loads the libs!

    But I have a new problem :

    I don't know why I got this, I don't use any of these _Xnames in my code.
    So, does this means that my X11 libraries are wrong? (I don't think so)

    @LPZ: This is a program to smooth a picture.
     
  6. LPZ
    macrumors 65816

    Joined:
    Jul 11, 2006
    #6
    Seems like the affichage.o you are linking is an i386 (32 bit) object file and your system needs an x86_64 (64 bit) version. The affichage.o available here is 64 bit; perhaps it is what you need.
     
  7. thread starter macrumors newbie

    Joined:
    Dec 23, 2012
    Location:
    Paris, FRANCE
    #7
    Thanks, but this is not the file I need.

    I don't think the issue is about a 32 or 64 bits version, I tried to compile my program in 32 bits and I get a similar error:
    Moreover, my teachers didn't give me *.o objects, but gave me the *.c/*.h files, so XCode makes the *.o itself.
     
  8. LPZ
    macrumors 65816

    Joined:
    Jul 11, 2006
    #8
    So you are compiling a program named affichage.c to produce affichage.o? Perhaps XCode simply cannot find the X11 libraries? It seems to have found the headers.
     
  9. Asuka', Dec 23, 2012
    Last edited: Dec 23, 2012

    thread starter macrumors newbie

    Joined:
    Dec 23, 2012
    Location:
    Paris, FRANCE
    #9
    My program is made of several .c, but affichage.c is the only one that use X11 libs.
    I don't know why XCode doesn't find the libs, I have added '/opt' recursively under LIBRARY SEARCH PATH to be sure that Xcode find them, but maybe I'm wrong!


    EDIT: I reached to make it worked, I need to add "-lX11" during the building.
    This works in the Terminal, but I can't find where add this option under XCode =/
     
  10. macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #10
    Look at additional linker flags. Or you could add the X11 library to the Xcode project and tell the project to link to it.

    You might also need to set the library search path if you haven't already done that.
     

Share This Page