RE: objective-c categories and static libraries?
RE: objective-c categories and static libraries?
- Subject: RE: objective-c categories and static libraries?
- From: "Sven Hoffmann" <email@hidden>
- Date: Thu, 10 Mar 2005 09:32:30 +0200
- Thread-topic: objective-c categories and static libraries?
Hi Toby,
I have here a simple Cocoa library that is build up very similar to
yours,
lm_cocoa.h and one lm_cocoa.m file. It is built as a xcode project
though and is objective c++ but really that shouldnt matter.
After compiling Libtool is run and than ranlib, maybe that will do the
job for you too.
Check the build protocol:
CompileC
build/prvcocoalib.build/prvcocoalib.build/Objects-normal/ppc/lm_cocoa.o
lm_cocoa.mm normal ppc objective-c++ com.apple.compilers.gcc.3_3
mkdir -p
/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build/prvcocoali
b.build/prvcocoalib.build/Objects-normal/ppc
cd /Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib
/usr/bin/distcc /usr/bin/gcc-3.3 -x objective-c++ -arch ppc -pipe
-Wno-trigraphs -fasm-blocks -fpascal-strings -Os -mtune=G4 -Wall
-Wno-unknown-pragmas -O0 -fmessage-length=0 -fpch-preprocess
-DMAC_OS_X_VERSION_MIN_REQUIRED=1020 -fconstant-cfstrings
-D__CONSTANT_CFSTRINGS__
-F/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build
-I/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build/include
-I../../include
-I/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build/prvcocoa
lib.build/prvcocoalib.build/DerivedSources
-Wp,-header-mapfile,/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoa
lib/build/prvcocoalib.build/prvcocoalib.build/prvcocoalib.hmap -include
/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build/prvcocoali
b.build/SharedCaches/StdAfx-ceyjcsjmrzkkqraqyxdshdtrcute/StdAfx.h -c
/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/lm_cocoa.mm -o
/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build/prvcocoali
b.build/prvcocoalib.build/Objects-normal/ppc/lm_cocoa.o
distcc[5373] (dcc_handle_remote_indirection_request) ERROR: Unable to
compare checksums
distccd[5892] ERROR: unlock failed: Bad file descriptor
Libtool
/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build/libprvcoco
alib.a
setenv MACOSX_DEPLOYMENT_TARGET 10.2
cd /Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib
/usr/bin/libtool -static -o
/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build/libprvcoco
alib.a -L/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build
-filelist
/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build/prvcocoali
b.build/prvcocoalib.build/Objects-normal/prvcocoalib.LinkFileList
Ranlib
/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build/libprvcoco
alib.a
cd /Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib
/usr/bin/ranlib
/Users/sven/Users/svenh/SRCSAFE/6.3/SDK/LIB/prvcocoalib/build/libprvcoco
alib.a
Hope that helps,
------------------------------------------------------------------------
----------
Sven Hoffmann
R&D Macintosh Software Develover
Email: email@hidden Tel. 03-6362211
Aladdin Knowledge Systems Ltd.
http://www.aladdin.com
-----Original Message-----
From: cocoa-dev-bounces+sven.hoffmann=email@hidden
[mailto:cocoa-dev-bounces+sven.hoffmann=email@hidden] On
Behalf Of Tobias Sargeant
Sent: 10 March, 2005 00:38
To: email@hidden
Subject: objective-c categories and static libraries?
[If this belongs on a gcc specific list, could someone please point me
in the direction of an appropriate one? Thanks]
I don't know if this constitutes a bug, or is an expected behaviour, or
is a result of something I'm (not) doing, but objective-c categories in
static libraries don't appear to be linked into executables built with
them.
Details below.
Cheers,
Toby.
I've defined a small category on NSString which is implemented in cat.m
and defined in cat.h like so:
#import <Foundation/Foundation.h>
@interface NSString(Split)
- (NSArray *)componentsSeparatedByString: (NSString *)str
maxSplits: (int)nsplits
keepEmpty: (BOOL)keep_empty;
- (NSArray *)componentsSeparatedByCharacters: (NSCharacterSet *)set
maxSplits: (int)nsplits
keepEmpty: (BOOL)keep_empty;
- (NSArray *)componentsSeparatedByCharacterRuns: (NSCharacterSet *)set
maxSplits: (int)nsplits
keepEmpty: (BOOL)keep_empty;
@end
A small stub, in test.m:
#import "cat.h"
int main(int argc, char **argv) {
id pool = [[NSAutoreleasePool alloc] init];
NSLog(@"%@", [[@"foo bar baz"
componentsSeparatedByCharacterRuns: [NSCharacterSet
whitespaceCharacterSet]
maxSplits: 1
keepEmpty: NO] description]);
[pool release];
}
Compiled like this, it works as expected:
mac1156:~/test sargeant$ gcc -O0 -gfull -o test1 test.m cat.m -framework
Foundation mac1156:~/test sargeant$ ./test1 2005-03-10 09:30:55.872
test1[3774] (foo, "bar baz")
However, compiled like this:
mac1156:~/test sargeant$ gcc -O0 -gfull -c cat.m mac1156:~/test
sargeant$ ar cq libcat.a cat.o mac1156:~/test sargeant$ ranlib libcat.a
mac1156:~/test sargeant$ gcc -O0 -gfull -o test2 test.m -L. -lcat
-framework Foundation mac1156:~/test sargeant$ ./test2 2005-03-10
09:32:10.335 test2[3792] *** -[NSConstantString
componentsSeparatedByCharacterRuns:maxSplits:keepEmpty:]: selector not
recognized 2005-03-10 09:32:10.337 test2[3792] *** Uncaught exception:
<NSInvalidArgumentException> *** -[NSConstantString
componentsSeparatedByCharacterRuns:maxSplits:keepEmpty:]: selector not
recognized Trace/BPT trap
Checking with nm, the category simply doesn't get linked in the second
case:
mac1156:~/test sargeant$ nm test1 | grep Split 000028fc t
-[NSString(Split)
componentsSeparatedByCharacterRuns:maxSplits:keepEmpty:]
000026e4 t -[NSString(Split)
componentsSeparatedByCharacters:maxSplits:keepEmpty:]
000024c0 t -[NSString(Split)
componentsSeparatedByString:maxSplits:keepEmpty:]
00000000 A .objc_category_name_NSString_Split
mac1156:~/test sargeant$ nm test2 | grep Split mac1156:~/test sargeant$
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
n.com
This email sent to email@hidden
**************************************************************************************************
The contents of this email and any attachments are confidential.
It is intended for the named recipient(s) only.
If you have received this email in error please notify the system manager or the
sender immediately and do not disclose the contents to anyone or make copies.
** eSafe scanned this email for viruses, vandals and malicious content **
**************************************************************************************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden