Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > cc/ld X11 undefined symbols

cc/ld X11 undefined symbols
Thread Tools
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 18, 2002, 07:31 PM
 
Please forgive me if this is a stupid question, but it's many years (back to Uni) since I've done anything in the C language. I'm trying to re-learn it, and got one of my old Uni projects which uses X11 (X-Windows). I cannot get it to link successfully. When I enter "cc <progname.c>" I get the following output:

/usr/bin/ld: Undefined symbols:
_XCreateColormap
_XCreateSimpleWindow
_XDrawPoint
_XFlush
_XMapRaised
_XNextEvent
_XOpenDisplay
_XResizeWindow
_XSelectInput
_XSetForeground
_XSetWindowColormap
_XStoreColor

Yes, I do have X11 installed correctly (using XDarwin and OroborOSX). And I know that it's found the required Xlib.h library header, because before I created a link to the Xfree86 library in /usr/include I got a completely different error (couldn't find the library). Also, I'm getting much the same error with the same source code on the Solaris box here too, and I know that's set up correctly.

Can somebody help me get over this hump on the road to re-learning Unix/C programming?

[ 04-19-2002: Message edited by: Brass ]
     
Dedicated MacNNer
Join Date: Apr 2001
Location: Bethesda, MD
Status: Offline
Reply With Quote
Apr 19, 2002, 01:09 PM
 
Are you linking with the X11 library properly?

your link line should look something like:

cc -o program program.c -L/usr/X11R6/lib -lX11


Those symbols are in the file /usr/X11R6/lib/libX11.a
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 19, 2002, 08:33 PM
 
Aha! It works (or at least, it compiles - causes X-Windows errors when it runs *sigh*)

Thanks for your help. I'm so out of touch with all this now. I need to look up some info on program linking, I guess. There's nothing on it at all in the C textbook I'm using - just the C language, itself. I guess I can use "man cc" and "man ld". I can't even remember what the -L and -l are for.
     
Dedicated MacNNer
Join Date: Apr 2001
Location: Bethesda, MD
Status: Offline
Reply With Quote
Apr 20, 2002, 05:41 PM
 
Yeah, you always have to make sure you include the right libraries in the right order when you link.

The "-Ldirectory" flag says add "directory" to the library path, so it can find the library. The "-llibrary" says link with the file liblibrary.a or liblibrary.dylib (on Macs). On most Unixes, dynamic libraries are .so, not .dylib.

About link order, if you have two libraries, libfoo.a and libbar.a, and libfoo depends on libbar, libfoo should come first on the link line, then libbar. I.e.

cc -o program program.c -lfoo -lbar

dave
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:49 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2