How to use a "C" Library?

Member
Posts: 90
Joined: 2006.11
Post: #1
I've installed a "C" library. I 've checked that it left include and .a files in my usr folder. but when I try to compile a sample program in X11 and terminal, it says "Undefined symbols" and then go on to list some of the commands that are present in the program.

The library also provided make files for those sample programs. I used the make files and the sample programs compiled and ran fine.

So, Whats up with the "undefined symbols"?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
open the makefile in a text editor to see the compiler flags.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 90
Joined: 2006.11
Post: #3
thanks alot!
Although... Should I try to understand this stuff? (it was in the make file. I put it beside the file path in the gcc command, and it compiled, and ran.)
Code:
[i]CFLAGS =[/i] -I../src -I../src/X11 -I../src/PS -I../src/Win32 -I../src/GD -I../src/FIG -g -O2  -I/usr/X11R6/include -I/usr/local/include -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DUNIX=1 -DDO_PS=1 -DDO_FIG=1 -DDO_X11=1 -DDO_XDBE=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIMITS_H=1
[i]CXXFLAGS =[/i] -I../src -I../src/X11 -I../src/PS -I../src/Win32 -I../src/GD/ -I../src/FIG -g -O2 -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DUNIX=1 -DDO_PS=1 -DDO_FIG=1 -DDO_X11=1 -DDO_XDBE=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIMITS_H=1
[i]LIBS =[/i]  -L.. -lg2  -L/usr/X11R6/lib -L/usr/local/lib -lm -lX11 -lXext
I removed the italicised stuff when putting it in, of course. But it looks horribly complicated. I can only partially see that it is referencing my 'official' include/lib folders.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
Its actually quite simple, in a terminal type 'man gcc'
then '/' type "-I" "-L" "-D" "-l" or anything you want to search for, hit n a few times till you find relevant info and learn what each of those compiler flags do.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 90
Joined: 2006.11
Post: #5
Learnt some stuff from there... but it is too much... Sad
Is there anyway to get XCode to use those compile options?
Quote this message in a reply
Member
Posts: 37
Joined: 2006.08
Post: #6
The -L and -l options for GCC are kind of weird. Let's say I want to include the "sqlite3" library for my app: I would use "-lsqlite3" with the lowercase "L" jammed right up to the "sqlite3." I know, it makes no sense. Thank you GNU. The -L option is basically the same thing except you specify a folder instead of the library name.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
it actually does make sense

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #8
You can keep them separated if you want, it's just that the "official" method keeps them together. And yes, it does make sense if you understand how command line arguments work: if you jam them up right next to each other, they are considered to be the same argument. If they are separated, they are completely separate arguments.

For XCode, you can usually link a library by just dragging it into your project and adding it to your target's link build phase. If you want a UNIX library under, say, /usr/lib, then you can add the -llibname option under the "Other link flags" build option.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #9
Why you would try and get Xcode to compile stuff that you already have a working makefile for I have no idea.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 90
Joined: 2006.11
Post: #10
So you want me to make a makefile for every program I write with that library? Why not just stick the compile flags everytime I compile? Considering a make file is so much bigger than just compiler flags...
Quote this message in a reply
Member
Posts: 37
Joined: 2006.08
Post: #11
unknown Wrote:it actually does make sense

I just did a quick survey of man pages, and among ping, tar, gzip, find, ln, traceroute, dig, touch, date, chmod, grep, and finally man itself: exactly zero of them had options where the argument's value was jammed up next to the argument itself, like gcc does.

That's what I was referring to when saying it makes no sense. I've never seen another tool do it.
Quote this message in a reply
Member
Posts: 90
Joined: 2006.11
Post: #12
How to use stuff like open/save dialog in C? can't find it anywhere....
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #13
If you're on the Mac, you're going to have to look at the carbon library. This isn't something there's a cross-platform standard for.
Quote this message in a reply
Member
Posts: 37
Joined: 2006.08
Post: #14
leRiCl Wrote:How to use stuff like open/save dialog in C? can't find it anywhere....

If you're writing a X11 application, then you're going to have to pick a GUI toolkit and then go with whatever functions that supplies for it, or roll your own. There is no standard way to do these things in C. The functionality of C itself is very basic, with some OS hooks for i/o in the standard library.

If you want to get open/save dialogs and other things like that and are not too concerned with cross-platform abilities then why not just use Cocoa and Objective-C?
Quote this message in a reply
Post Reply