Re: Building shared objects in Xcode?
Re: Building shared objects in Xcode?
- Subject: Re: Building shared objects in Xcode?
- From: Art Isbell <email@hidden>
- Date: Sun, 25 Dec 2005 16:57:03 -1000
On Dec 25, 2005, at 9:42 AM, Anand Patil wrote:
I'm a novice C programmer trying to turn C function libraries into
shared
objects that can be loaded by the statistical language R.
I don't know the answer about whether shared objects are supported
under OS X, but I created a small Xcode 2.2. project that produces a
product named marcdemo_shared_object.so:
$ file /Users/art/marcdemo_shared_object/build/Debug/
marcdemo_shared_object.so
/Users/art/marcdemo_shared_object/build/Debug/
marcdemo_shared_object.so: Mach-O bundle ppc
So if that description is what R needs, Xcode can build it.
A Makefile that works follows. How would I build an equivalent shored
object in Xcode?
CC = gcc -O3 -Wall
RPP = g++ -bundle -flat_namespace -undefined suppress
OBJS = marcdemo_c_file.o
all: marcdemo_shared_object
clean:
- rm -i *.o
marcdemo.o: ${OBJS} marcdemo_c_file.c
${CC} -c marcdemo_c_file.c
marcdemo_shared_object: ${OBJS} marcdemo_c_file.o
${RPP} -o marcdemo_shared_object.so ${OBJS}
I started by creating a new CFPlugin Bundle project named
marcdemo_shared_object in Xcode (2.2, in my case) because your
Makefile specified the "-bundle" argument to the linker. However, an
OS X bundle is by default a directory with a "bundle" file extension
containing an executable and other resources.
I added marcdemo_c_file.c to the Source group. I assumed that a
header file, marcdemo_c_file.h, existed as well and added that to the
Source group.
I deleted the Resources group references and files because the
project won't need them. Likewise, I deleted the External Frameworks
group references because the project won't need to link against
CoreFoundation.framework.
I don't understand why the Makefile specifies gcc for compiling and g
++ for linking, so I just let Xcode's default rules decide what to
use for compiling and linking. I left the optimization level the
default -O0 for the Debug configuration, but changed the Release
configuration's value in the Target inspector to match that in the
Makefile, -O3. I added "-Wall" to the Other C Flags value and "-
flat_namespace -undefined suppress" to the Other Linker Flags value
for all configurations to match those flags in the Makefile.
The Release configuration by default produces both PowerPC and Intel
executables, so I set the Release configuration's Architectures value
to match that of the Debug configuration which is just PowerPC.
By default, other compiler and linker settings are used in this type
of project; I didn't change these.
I added a Run Script build phase to the target:
cd ${BUILD_DIR}/${CONFIGURATION}
mv ${PRODUCT_NAME}.${WRAPPER_EXTENSION}/Contents/MacOS/$
{PRODUCT_NAME} ${PRODUCT_NAME}.so
rm -rf ${PRODUCT_NAME}.${WRAPPER_EXTENSION}
This script moves the executable out of the bundle directory, appends
an "so" file extension, and deletes the bundle directory. Note that
this script will not work with some Xcode versions earlier than 2.2
due to a different build directory layout.
The resulting Debug configuration compiler command:
/usr/bin/gcc-4.0 -x c -arch ppc -pipe -Wno-trigraphs -fpascal-strings
-fasm-blocks -g -O0 -Wreturn-type -Wunused-variable -fmessage-
length=0 -mtune=G5 -mfix-and-continue -I/Users/art/
marcdemo_shared_object/build/marcdemo_shared_object.build/Debug/
marcdemo_shared_object.build/marcdemo_shared_object.hmap -F/Users/art/
marcdemo_shared_object/build/Debug -I/Users/art/
marcdemo_shared_object/build/Debug/include -I/Users/art/
marcdemo_shared_object/build/marcdemo_shared_object.build/Debug/
marcdemo_shared_object.build/DerivedSources -Wall -isysroot /
Developer/SDKs/MacOSX10.4u.sdk -c /Users/art/marcdemo_shared_object/
marcdemo_c_file.c -o /Users/art/marcdemo_shared_object/build/
marcdemo_shared_object.build/Debug/marcdemo_shared_object.build/
Objects-normal/ppc/marcdemo_c_file.o
The resulting Debug configuration linker command:
/usr/bin/gcc-4.0 -o /Users/art/marcdemo_shared_object/build/Debug/
marcdemo_shared_object.bundle/Contents/MacOS/marcdemo_shared_object -
L/Users/art/marcdemo_shared_object/build/Debug -F/Users/art/
marcdemo_shared_object/build/Debug -filelist /Users/art/
marcdemo_shared_object/build/marcdemo_shared_object.build/Debug/
marcdemo_shared_object.build/Objects-normal/ppc/
marcdemo_shared_object.LinkFileList -arch ppc -bundle -flat_namespace
-undefined suppress -isysroot /Developer/SDKs/MacOSX10.4u.sdk
Someone more familiar with executable formats, the requirements of
the R language, etc. can probably determine whether this Xcode
project would create an executable that works as expected. But even
if it doesn't, I'd be surprise if Xcode couldn't be configured to
produce a working executable.
Aloha,
Art
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden