PDA

View Full Version : Obj-C on Linux


Steven
2003.04.07, 07:46 PM
This is probably a stupid question, and I don't expect much of a response other than 'No', but here goes...

Is it possible to use Objective C and the Foundation framework on a Debian Linux machine?
Thanks,
Steven

OneSadCookie
2003.04.07, 07:50 PM
Yes, for some definition of yes :)

Check out GNUStep -- http://www.gnustep.org/

Steven
2003.04.08, 12:27 AM
I've spent all afternoon downloading and fiddling- I'm now stuck where gcc can't compile (my other version was too old)
It's complaining that checking whether the C compiler (gcc -g -O2) works... no
configure: error: installation or configuration problem: C compiler cannon create executables

How do I fix this?
Thanks,
Steven

OneSadCookie
2003.04.08, 01:04 AM
Does gcc work?

Steven
2003.04.08, 09:32 AM
:blush:
No, it doesn't. I don't have the standard includes- like stdio.h
I have no clue why, as gcc is installed. How can I install them?
Thanks,
Steven

OneSadCookie
2003.04.08, 03:53 PM
Looks like you need the libc6-dev package on Debian. You may be able to use 'sudo apt-get install libc6-dev'.

Steven
2003.04.08, 04:13 PM
Thanks, I'll do that when I get home from school...
Steven

Steven
2003.04.08, 08:15 PM
It seems to work now, it's been compiling for something like the last hour...
Steven

Steven
2003.04.08, 09:57 PM
Still compiling... wow, GCC is HUGE!!! I haven't even started on GNUStep yet... almost three hours now.
Steven

Steven
2003.04.09, 07:51 PM
Still compiling GCC, almost 24 hours now...
Steven

Steven
2003.04.10, 07:21 PM
I installed gcc, then compiled and installed gnustep-base-1.5.0 and gnustep-make-1.5.0
I then followed the instructions and tried to do a
defaults write NSGlobalDomain NSLanguages "English"
and it said
defaults: error while loading shared libraries: libgcc_s.so.1: cannot open shared object file: No such file or directory
I can't figure out why this would happen.
Steven

Steven
2003.04.10, 08:11 PM
I managed to fix it by reinstalling it. More later on how it works.
Steven

Steven
2003.04.10, 10:58 PM
Ok, everything seems to be working now. Only problem is that it can't find Foundation.h.
steven@hplmss1:~/war$ gcc main.m
main.m:1:2: warning: #import is obsolete, use an #ifndef wrapper in the header file
main.m:1:34: Foundation/Foundation.h: No such file or directory
In file included from main.m:2:
CardStack.h:9:34: Foundation/Foundation.h: No such file or directory
In file included from CardStack.h:10,
from main.m:2:
Card.h:9:34: Foundation/Foundation.h: No such file or directory
In file included from CardStack.h:10,
from main.m:2:
Card.h:14: cannot find interface declaration for `NSObject', superclass of `Card'
How do I include the Foundation framework? Also, is it safe to assume that #import will be ok to use, or must I really change it?
Thanks,
Steven

Steven
2003.04.10, 11:01 PM
Oh, and one more thing: can I use frameworks like MOKit.framework? If so, how? Thanks a bunch!
Steven

OneSadCookie
2003.04.10, 11:08 PM
Looks like you need to include <Foundation/NSObject.h>, <Foundation/NSString.h>, &c.

You shouldn't use #import with GNUStep. All the include stuff is going to be different on the two platforms, you'll just have to #ifndef it.

External frameworks & libraries will probably need a bit of porting (changing includes, &c). Some will already have been ported.

Google is your friend.

Steven
2003.04.10, 11:36 PM
There is a file called Foundation.h, and it has the proper contents, it's just not being found by gcc.
It's at /usr/GNUstep/System/Headers/Foundation/Foundation.h

Steven
2003.04.10, 11:38 PM
I browsed GCC's docs, and set the environment variable OBJC_INCLUDE_PATH to /usr/GNUstep/System/Headers/
Now it shows this:
main.m:1:2: warning: #import is obsolete, use an #ifndef wrapper in the header file
In file included from /usr/GNUstep/System/Headers/Foundation/Foundation.h:29,
from main.m:1:
/usr/GNUstep/System/Headers/Foundation/NSObjCRuntime.h:112:32: base/objc-gnu2next.h: No such file or directory
In file included from main.m:1:
/usr/GNUstep/System/Headers/Foundation/Foundation.h:30:22: GSConfig.h: No such file or directory
In file included from /usr/GNUstep/System/Headers/Foundation/NSDebug.h:30,
from /usr/GNUstep/System/Headers/Foundation/Foundation.h:31,
from main.m:1:
/usr/GNUstep/System/Headers/Foundation/NSObject.h:39:26: base/preface.h: No such file or directory
/usr/GNUstep/System/Headers/Foundation/NSObject.h:40:22: GSConfig.h: No such file or directory
In file included from /usr/GNUstep/System/Headers/Foundation/Foundation.h:39,
from main.m:1:
/usr/GNUstep/System/Headers/Foundation/NSByteOrder.h:27:22: GSConfig.h: No such file or directory
In file included from /usr/GNUstep/System/Headers/Foundation/Foundation.h:39,
from main.m:1:
/usr/GNUstep/System/Headers/Foundation/NSByteOrder.h:32: parse error before "NSSwappedFloat"
/usr/GNUstep/System/Headers/Foundation/NSByteOrder.h:33: parse error before "NSSwappedDouble"
/usr/GNUstep/System/Headers/Foundation/NSByteOrder.h:53: parse error before "GSSwapI16"
/usr/GNUstep/System/Headers/Foundation/NSByteOrder.h:53: parse error before "in"
/usr/GNUstep/System/Headers/Foundation/NSByteOrder.h:55: parse error before "GSSwapI32"
/usr/GNUstep/System/Headers/Foundation/NSByteOrder.h:55: parse error before "in"
/usr/GNUstep/System/Headers/Foundation/NSByteOrder.h:57: parse error before "GSSwapI64"
/usr/GNUstep/System/Headers/Foundation/NSByteOrder.h:57: parse error before "in"
/usr/GNUstep/System/Headers/Foundation/NSByteOrder.h:59: parse error before "GSSwapI128"

... lots of similar errors omitted from NSByteOrder.h ...

In file included from /usr/GNUstep/System/Headers/Foundation/NSDecimalNumber.h:31,
from /usr/GNUstep/System/Headers/Foundation/Foundation.h:49,
from main.m:1:
/usr/GNUstep/System/Headers/Foundation/NSDecimal.h:30:22: GSConfig.h: No such file or directory
main.m:141:2: warning: no newline at end of file

Thanks,
Steven

OneSadCookie
2003.04.10, 11:47 PM
Find that base directory and add its parent to the header search paths.

Steven
2003.04.10, 11:58 PM
Ok, thanks. After adding that and a few other directories to the search path, it compiles. But, the linker barfs up:
/tmp/ccL6nm6c.o: In function `main':
/tmp/ccL6nm6c.o(.text+0x28): undefined reference to `objc_get_class'
/tmp/ccL6nm6c.o(.text+0x28): relocation truncated to fit: R_PPC_REL24 objc_get_class
/tmp/ccL6nm6c.o(.text+0x3c): undefined reference to `objc_msg_lookup'
/tmp/ccL6nm6c.o(.text+0x3c): relocation truncated to fit: R_PPC_REL24 objc_msg_lookup
/tmp/ccL6nm6c.o(.text+0x64): undefined reference to `objc_msg_lookup'
/tmp/ccL6nm6c.o(.text+0x64): relocation truncated to fit: R_PPC_REL24 objc_msg_lookup
for thousands of lines. I think I need to tell the linker where the compiled Foundation code is, but I don't know how.
Steven

OneSadCookie
2003.04.11, 12:12 AM
probably -lobjc -lfoundation -lappkit or something... what are the libraries called and where are they installed?

Steven
2003.04.11, 12:15 AM
Now it says this:
/usr/bin/ld: cannot find -lFoundation
And I honestly don't know what to look for- what will it be named? I've been using locate to find stuff, but I need a file name.
Steven

OneSadCookie
2003.04.11, 12:17 AM
It'll be called something like libFoundation.so or libfoundation.so. At a wild guess, /usr/X11R6/lib/, /usr/GNUstep/Libraries/, /usr/X11R6/lib/GNUstep/ seem like reasonable places to try.

Steven
2003.04.11, 12:49 AM
I tried doing
locate *foundation*.so
locate *Foundation*.so
locate *.so

and there was nothing like libfoundation.so.
However, I did find /usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so
I don't know if that's right though, or how to pass it to the linker. And, I don't have X11 installed, so those other paths don't exist.
Steven

Steven
2003.04.11, 12:51 AM
I'm off to bed now, so I'll try anything that you say tomorrow morning... thanks OSC.
Steven

OneSadCookie
2003.04.11, 01:06 AM
Try adding this to your link arguments:

-L/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu -lgnustep-base

Steven
2003.04.11, 09:36 AM
I added the above path to LIBRARY_PATH and now use this command to compile:
gcc -lobjc -lgnustep-base Card.m CardStack.m main.m -o war

and it spits out ten thousand lines like this, including the stuff mentioned before:
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `objc_lookup_class'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `objc_get_type_qualifiers'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `sel_types_match'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `search_for_method_in_list'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `dlerror'

Thanks,
Steven

Feanor
2003.04.11, 12:11 PM
Please tell me that you have read this: Installation instructions (http://www.gnustep.org/resources/documentation/GNUstep-HOWTO)

Granted it is complicated. There appear to be some support libraries needed. The instructions suggest that you need to compile the gnustep libraries. Did you do that, or do they have binaries? (I cannot find any binary downloads...)

There are other links to docs, but they don't work. :mad:

Steven
2003.04.11, 06:14 PM
I did follow those instructions, except I didn't install the gui package as I don't have an X server installed on the computer. I compiled my own.
Steven

OneSadCookie
2003.04.11, 08:06 PM
Have you tried -lobjc and/or -ldl ?

Have you tried 'sudo apt-get install gnustep'?

Steven
2003.04.13, 11:24 AM
I didn't think of using apt-get, I just reinstalled GNUstep from the package.
gcc -lobjc -lgnustep-base -ldl Card.m CardStack.m main.m -o war

returns:

/tmp/cc2IsoPM.o: In function `_i_Card__compare_':
/tmp/cc2IsoPM.o(.text+0x84): undefined reference to `objc_msg_lookup'
/tmp/cc2IsoPM.o(.text+0x84): relocation truncated to fit: R_PPC_REL24 objc_msg_lookup
/tmp/cc2IsoPM.o(.text+0xb0): undefined reference to `objc_msg_lookup'
/tmp/cc2IsoPM.o(.text+0xb0): relocation truncated to fit: R_PPC_REL24 objc_msg_lookup
...
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `objc_lookup_class'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `objc_get_type_qualifiers'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `sel_types_match'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `search_for_method_in_list'
Could there be another library which defines all of these? What would it be called?
Thanks,
Steven

OneSadCookie
2003.04.13, 04:16 PM
Are there any other libs in the same place as libgnustep-base.so?

find /usr/lib -type f -name '*.so' | xargs nm | grep objc_lookup_class will at least tell you if any of the libraries in /usr/lib define objc_lookup_class. Probably also worth running a similar command on /usr/GNUstep/System/Libraries .

Steven
2003.04.13, 09:50 PM
For /usr/lib, it prints a bunch of lines saying 'no symbols'

When I tried the second one, it printed a line saying
'nm: a.out: No such file or directory.'

So I then ran nm on libgnustep-base.so and piped it thru grep, and it returned this:

U objc_lookup_class

Now, trying again:

steven@hplmss1:~/war$ gcc -lgnustep-base -lobjc Card.m CardStack.m main.m
Card.m:9:2: warning: #import is obsolete, use an #ifndef wrapper in the header file
CardStack.m:9:2: warning: #import is obsolete, use an #ifndef wrapper in the header file
main.m:1:2: warning: #import is obsolete, use an #ifndef wrapper in the header file
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `dlerror'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `ceil'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `floor'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `dlclose'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `rint'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `dlopen'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `pow'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `dlsym'
collect2: ld returned 1 exit status
steven@hplmss1:~/war$
Looks like I'm getting there.

I'll try adding -ldl to the command line.

steven@hplmss1:~/war$ gcc -lgnustep-base -lobjc -ldl Card.m CardStack.m main.m
Card.m:9:2: warning: #import is obsolete, use an #ifndef wrapper in the header file
CardStack.m:9:2: warning: #import is obsolete, use an #ifndef wrapper in the header file
main.m:1:2: warning: #import is obsolete, use an #ifndef wrapper in the header file
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `ceil'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `floor'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `rint'
/usr/GNUstep/System/Libraries/powerpc/linux-gnu/gnu-gnu-gnu/libgnustep-base.so: undefined reference to `pow'
collect2: ld returned 1 exit status
steven@hplmss1:~/war$
Gah! Down to four errors. Where would the above be?
Thanks a bunch,
Steven

OneSadCookie
2003.04.13, 09:55 PM
-lm

Steven
2003.04.13, 10:11 PM
WOOHOO!
It works! Now, can I have all of those -l parameters as the default or something? I don't want to have to write them over and over again.
Thanks a bunch OSC.
Steven

OneSadCookie
2003.04.13, 10:29 PM
You only need them in the linking command, not in the commands to compile individual source files...

Steven
2003.04.13, 11:42 PM
Yeah, but then anytime I want an updated executable, I have to do that :/
Any way to do it better?
Steven

OneSadCookie
2003.04.13, 11:52 PM
Put it in a Makefile!

Steven
2003.04.14, 09:44 AM
I haven't really used makefiles, and the size of my project doesn't seem to really warrant learning it. I've decided to alias it to something like occ.
Steven

OneSadCookie
2003.04.14, 04:06 PM
It's always worth having a makefile.

Steven
2003.04.14, 05:11 PM
Really? Why?

OneSadCookie
2003.04.14, 05:34 PM
Because even when you've only got one source file, it's quicker to type make than it is to type gcc -g -c -Wall -W -Wno-unused-parameter -Werror -Os -I/usr/X11R6/include main.c; gcc -o Executable main.o -L/usr/X11R6/lib -lGL -lGLU -lglut -lX11 -lm, and when you've got more than one file keeping track of dependencies and what needs to be rebuilt makes such a huge improvement to compile times that it's pointless to avoid the makefile...