how to build a shared object in OSX

couzteau

Registered
how to build a shared object in OSX

hello,

this question comes in two flavors:

1. how do i normally implement something like shared objects with
project buider mac os x 10.1? is that a library or a framework or ...???

2. how do i create a shared object on the command line using cc? i'm
working on a project that has been developed on linux/solaris and has
some quite sophisticated makefiles. can modify and keep them? i'
currently stuck because good ol'"cc -shared libacl.so ..." doesn't
work. the compiler is complaining because main is not defined.

thanks

jochen
 
Head over to http://gnu-darwin.sourceforge.net/porting.html ... they provide tips for porting programs over to darwin. One of the tips is how to create dummy libraries for those you are missing ...

It doesn't cover shared libraries, but there's enough there to get you started and point you in the right direction.

You can probably also ask on their mailing list how you might go about doing shared libaries.

Good Luck,
__nether
 
Hey missed some of the answers.

Answer 1: It depends on your application :) ... What do you want to do with it? Should it be portable? If so, it should be a unix style shared library. If it's just for OS X, then a framework will be better.

Answer 2: See my post above. In addition:
When you compile a large program (and libraries in your case), you need to first compile the object files, then link then. When you do a straight cc, you are telling the compiler to both compile and link then. What you want to do is in CFLAGS, add a -c (and also probably -no-cpp-precompile). You might also need to do -flat_namespace and quite possibly -traditional_cpp.

Take a look at the release notes of Project Builder.

__nether
 
i looked it up in a makefile. you have to compile the sources with the flag -dynamic and then rename the object files in mylib.so

many thanx
couzteau
 
replace the compiler option
-shared
to build a shared lib
with
-dynamiclib.

the object files that are used to build the shared object have to be compiled with
-fno_commons
as gcc flag to avoid namespaceproblems.
 
Back
Top