Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 23, 2012, 04:11 AM   #1
Asuka'
macrumors newbie
 
Join Date: Dec 2012
Location: Paris, FRANCE
How to use X11 in XCode?

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
Asuka' is offline   0 Reply With Quote
Old Dec 23, 2012, 04:53 AM   #2
LPZ
macrumors 65816
 
Join Date: Jul 2006
Quote:
Originally Posted by Asuka' View Post
Hi everybody!

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! =/
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.
LPZ is offline   0 Reply With Quote
Old Dec 23, 2012, 07:18 AM   #3
Platskies
macrumors member
 
Join Date: Jul 2012
Location: NSW, Australia
Quote:
Originally Posted by LPZ View Post
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.
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
Platskies is offline   0 Reply With Quote
Old Dec 23, 2012, 08:01 AM   #4
LPZ
macrumors 65816
 
Join Date: Jul 2006
Quote:
Originally Posted by Platskies View Post
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
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.
LPZ is offline   0 Reply With Quote
Old Dec 23, 2012, 08:35 AM   #5
Asuka'
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Location: Paris, FRANCE
Thanks for answering me, XCode now loads the libs!

But I have a new problem :

Quote:
Originally Posted by Xcode
Undefined symbols for architecture x86_64:
"_XCloseDisplay", referenced from:
_libererAffichage in affichage.o
"_XCreateGC", referenced from:
_initialiserAffichage in affichage.o
"_XCreateImage", referenced from:
_initialiserAffichage in affichage.o
"_XCreateSimpleWindow", referenced from:
_initialiserAffichage in affichage.o
"_XDefaultVisual", referenced from:
_initialiserAffichage in affichage.o
"_XDestroyWindow", referenced from:
_libererAffichage in affichage.o
"_XFlush", referenced from:
_initialiserAffichage in affichage.o
_afficherImage in affichage.o
_changerLigne in affichage.o
_changerBloc in affichage.o
"_XFreeGC", referenced from:
_libererAffichage in affichage.o
"_XMapWindow", referenced from:
_initialiserAffichage in affichage.o
"_XMoveWindow", referenced from:
_initialiserAffichage in affichage.o
"_XOpenDisplay", referenced from:
_initialiserAffichage in affichage.o
"_XPutImage", referenced from:
_afficherImage in affichage.o
_changerLigne in affichage.o
_changerBloc in affichage.o
"_XStoreName", referenced from:
_initialiserAffichage in affichage.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
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.

Last edited by Asuka'; Dec 23, 2012 at 08:45 AM.
Asuka' is offline   0 Reply With Quote
Old Dec 23, 2012, 09:08 AM   #6
LPZ
macrumors 65816
 
Join Date: Jul 2006
Quote:
Originally Posted by Asuka' View Post
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.
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.
LPZ is offline   0 Reply With Quote
Old Dec 23, 2012, 09:20 AM   #7
Asuka'
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Location: Paris, FRANCE
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:
Quote:
Undefined symbols for architecture i386:
...
ld: symbol(s) not found for architecture i386
Moreover, my teachers didn't give me *.o objects, but gave me the *.c/*.h files, so XCode makes the *.o itself.
Asuka' is offline   0 Reply With Quote
Old Dec 23, 2012, 09:54 AM   #8
LPZ
macrumors 65816
 
Join Date: Jul 2006
Quote:
Originally Posted by Asuka' View Post
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.
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.
LPZ is offline   0 Reply With Quote
Old Dec 23, 2012, 10:02 AM   #9
Asuka'
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Location: Paris, FRANCE
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 =/

Last edited by Asuka'; Dec 23, 2012 at 10:19 AM.
Asuka' is offline   0 Reply With Quote
Old Dec 23, 2012, 12:13 PM   #10
Madd the Sane
macrumors 6502
 
Join Date: Nov 2010
Location: Utah
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.
Madd the Sane is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:26 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC