Author Topic: Problem with Dynamic Library CB target on MacOSX  (Read 9301 times)

bnilsson

  • Guest
Problem with Dynamic Library CB target on MacOSX
« on: October 29, 2006, 12:14:51 pm »
I am trying to build the CB project wxSmith-unix.cbp which has a target type "Dynamic library".
When linking I get a "error" message:
powerpc-apple-darwin8-g++-4.0.1: unrecognized option '-shared'
but it seems the switch is simply ignored.

Looking thru the man page of my g++ I see this:

       -shared
           Produce a shared object which can then be linked with other objects
           to form an executable.  Not all systems support this option.  For
           predictable results, you must also specify the same set of options
           that were used to generate code (-fpic, -fPIC, or model suboptions)
           when you specify this option.[1]

           This option is not supported on Mac OS X.

In addition to this, the linking fails, reporting that _main is undefined.
If I go in to Settings->Compiler..->Other->Advanced.. and remove the "-shared"  from the "Dynamic library" command line, I get rid of the error message, but the result is the same.
This tells me that the compiler/linker command for targeting a dynamic library on MacOSX is somehow wrong.
If I change the target to "static library" the link completes without errors, but I cannot really tell what kind of library is produced.
I see that the command line for "Static library" is entirely different, it is using ar and ranlib.
Is this a known issue for CB on MacOSX?
Can anyone clairfy this?

Looking at the Makefile in src/plugins/contrib/wxSmith I guess that libtool should be used instead of g++.

Example snip from my working Makefile for libwxsmith.so:
CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \
   $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@

which means, from the definitions i found in the same file:
LIBTOOL = $(SHELL) $(top_builddir)/libtool
CXX = g++
CXXLD = $(CXX)
AM_CXXFLAGS unknown, not found in the file
CXXFLAGS = -O2 -ffast-math -I/opt/local/include -g -DCB_PRECOMP -Winvalid-pch -fPIC -DPIC
AM_LDFLAGS unknown, not found in the file
LDFLAGS = -L/opt/local/lib

« Last Edit: October 29, 2006, 01:31:45 pm by bnilsson »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #1 on: October 29, 2006, 01:39:20 pm »
Try changing -shared to -dynamic
And don't forget to remove any -s from compiler/linker from 10.4 compiles.
Stripping has to be done externally to avoid missing symbols.
« Last Edit: October 29, 2006, 01:43:08 pm by Pecan »

bnilsson

  • Guest
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #2 on: October 29, 2006, 01:47:57 pm »
Thank's, I'll try it.
Quote
And don't forget to remove any -s from compiler/linker from 10.4 compiles.
Please explain in more detail, please.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #3 on: October 29, 2006, 02:02:29 pm »
Thank's, I'll try it.
Quote
And don't forget to remove any -s from compiler/linker from 10.4 compiles.
Please explain in more detail, please.


Google has a lot more details than I.
Also, search this forum for OS X and stipping.

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #4 on: October 29, 2006, 02:22:34 pm »
You might have to verify against the Makefiles for wxSmith,
AFAIK the plugins should be "-bundle" and not "-dynamic" lib ?

FYI: I normally use strip -S afterwards, on Mac OS X...
(that is, when I build with -g debugging symbols enabled)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #5 on: October 29, 2006, 02:55:17 pm »
You're right, my bad. It is -bundle, not -dynamic. The codeblocks.so and other core libraries are -dynamic.

Also: Quotes about lazy pointer errors during stripping (-s)
Quote
I did some Googling and found this:
http://lists.boost.org/boost-build/2005/11/12114.php

Although it doesn't say exactly what is going on, it does state that there is a connection between stripping the debug symbols and the lazy binding problem. This would explain why this happens for Intel Macs and not for PPC Macs: in the "ppc" flavour, stripping is disabled. This is a relic from the time when PPC was equivalent to Mac, but nowadays we support Linux and BSD on PPC and OS X on Intel.

And this does happen on the ppc, not just intel.
It catches me about once a month.


« Last Edit: October 29, 2006, 02:56:53 pm by Pecan »

bnilsson

  • Guest
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #6 on: October 29, 2006, 03:49:59 pm »
-bundle was working fine, thanks.
wxSmith built by the CB project works the same way as built from command, which I guess is a proper criteria for success.

Would it be possible to have this "-bundle" setting from start when building CB for MacOSX to avoid confusion for new users?
« Last Edit: October 29, 2006, 04:20:15 pm by bnilsson »

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #7 on: October 29, 2006, 05:05:03 pm »
It looks like you have to create a wxSmith-Mac.cbp project file (groan), or you could add a build script that sets that based on platform.

bnilsson

  • Guest
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #8 on: October 29, 2006, 07:27:30 pm »
This is not specific to wxSmith.
Any dynamic library that would be built by CB would have -bundle instead of -shared since -shared is not supported on MacOSX.

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #9 on: October 29, 2006, 07:50:52 pm »
To clarify, there are two kinds of shared libraries present on Mac OS X:
"dynamic libraries" (.dylib) such as libcodeblocks.dylib or libwx_mac-2.6.dylib
"bundles" (.bundle or .so) for plugins such as libcompiler.so or libdebugger.so

The dynamic libraries are normally wrapped in a .framework bundle (with headers),
just as program binaries are normally wrapped in a .app bundle (with the resources)

So which of the two -shared should be converted to, that depends on the project...
(on Linux, for instance, both of these two types of shared libraries are .so files)

bnilsson

  • Guest
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #10 on: October 29, 2006, 07:57:03 pm »
Thanks, afb.
Noticed I changed my signature back to what it was before?  I think I need it.
« Last Edit: October 29, 2006, 08:59:34 pm by bnilsson »

bnilsson

  • Guest
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #11 on: October 31, 2006, 08:45:32 am »
As an exercise, I am trying to build a test version of CB using CB.
The build of CoreBlocks-unix.cbp fails, probably for reasons discussed in this thread.
The target "Core app plugins" reports
"/usr/bin/ld: devel/libwxscintilla.so is input for the dynamic link editor, is not relocatable by the static link editor again
collect2: ld returned 1 exit status"

There is no difference(execept for the -shared error message) if I use -shared, -bundle or -dynamic in the command line.

Is it true to say that CB cannot be built using CB on MacOSX?
Or can the original CoreBlocks-unix.cbp be modified to make it work?


BTW: Does this kind of topic belong here? Or should it be in "Using Code::Blocks"?
« Last Edit: October 31, 2006, 08:48:31 am by bnilsson »

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #12 on: October 31, 2006, 08:48:38 am »
Is it true to say that CB cannot be built using CB on MacOSX?

Of course not, but you just have to realize that Code::Blocks projects files are not really portable, so even though its called a Unix project file its really a Linux one.  I think Pecan had/maintains a Codeblocks-mac.cbp project file.  Hopefully he will post.

bnilsson

  • Guest
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #13 on: October 31, 2006, 09:04:47 am »
That's good news.
May I humbly ask if it would be possible to bundle it with the svn distribution?

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #14 on: October 31, 2006, 02:24:29 pm »
That's good news.
May I humbly ask if it would be possible to bundle it with the svn distribution?

I have cbp's for svn 2984 for OSX 10.3 ansi and unicode.
I have attached a zip file to this message.

I create the projects by comparing my old mac-cbp's with the unix-cbp's.
You will have to update them to the current svn.

I believe you will also have to modify the link sections of these 10.3 cbp's for 10.4.



[attachment deleted by admin]

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Problem with Dynamic Library CB target on MacOSX
« Reply #15 on: November 03, 2006, 08:02:59 am »
I tried this project with Mac OS X 10.4, but Code::Blocks seemed to hang on it.  :(