Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > What the..? Apple's g++, no -shared option?

What the..? Apple's g++, no -shared option?
Thread Tools
Registered User
Join Date: Oct 2003
Status: Offline
Reply With Quote
Sep 12, 2004, 05:45 PM
 
I'm trying to build a simple shared library from a few source code files on OS X 10.3.5.

The relevant command line in my makefile looks like this:

g++ -Wall -Wl,-shared -Wl,-soname="libVecMath.so.1" Point.o Ray.o Triangle.o Vector.o -o libVecMath.so.1.0

but it's failing with this message:

ld: unknown flag: -shared
make: *** [libVecMath.so.1.0] Error 1

which is weird. Then I checked the man page for g++, and it says that Apple's gcc doesn't accept the -shared option. (?!)

Can anyone explain how or why Apple's gcc doesn't let me build a shared lib?

Thanks.
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Sep 12, 2004, 10:37 PM
 
I am out on a limb here... but it probably has to do with MacOS X using dylib's rather than so's. Try a bit of googling a bit on that subject.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Sep 13, 2004, 11:17 AM
 
Try -dynamiclib (and you'll be wanting to use .1.0.dylib instead of .so.1). Oh, and you might like to use -install_name as well.
     
johnMG  (op)
Registered User
Join Date: Oct 2003
Status: Offline
Reply With Quote
Sep 13, 2004, 09:41 PM
 
Ah, there we go. Thanks Angus_D.

Well, I know that you can have both .so's and .dylib's on Mac OS X. However, that said, summing up, porting from GNU/Linux to OS X, to make a dylib, and a run-on sentence, it looks like I need to:

compile with: -fno-common (and *no* -fPIC),

and then link with: -dynamiclib -install_name (no -shared or -Wl,-soname), while naming my object file with a .dylib instead of .so.

Also, thanks again Angus_D for reminding me that on GNU/Linux you name the libs .so.n.m, whereas, on OS X, they're named .n.m.dylib (where n and m are major and minor version numbers, respectively).
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:14 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2