Menu

#238 Darwin linker arguments -arch and -install_name for gcc/g++

open
cpptasks (103)
5
2010-01-10
2010-01-10
No

Hi,

I am porting a project to Mac OS X / Darwin which uses dynamic libraries. In order to build universal binaries for multiple architectures you need to pass the -arch flag for every architecture you want to build for. However, the gcc linker arguments -arch and -install_name get decorated with -Wl,<arg>. For example, this part from the build.xml file:

<linker name="${compiler.ld.cmd}">
<linkerarg value="-arch" />
<linkerarg value="i386" />
<linkerarg value="-arch" />
<linkerarg value="x86_64" />
<linkerarg value="-arch" />
<linkerarg value="ppc" />
<linkerarg value="-arch" />
<linkerarg value="ppc64" />
<linkerarg value="-install_name" />
<linkerarg value="@executable_path/../lib/libanswer.dylib" />
</linker>

results in

[...]
Class org.apache.tools.ant.types.Commandline loaded from parent loader (parentFirst)
[cc] gcc -Wl,-arch i386 -Wl,-arch x86_64 -Wl,-arch ppc -Wl,-arch ppc64 -Wl,-install_name @executable_path/../lib/libanswer.dylib -prebind -dynamiclib -o libanswer.dylib ../obj/answer.o
Class org.apache.tools.ant.taskdefs.LogStreamHandler loaded from parent loader (parentFirst)
Execute:Java13CommandLauncher: Executing 'gcc' with arguments:
'-Wl,-arch'
'i386'
'-Wl,-arch'
'x86_64'
'-Wl,-arch'
'ppc'
'-Wl,-arch'
'ppc64'
'-Wl,-install_name'
'@executable_path/../lib/libanswer.dylib'
'-prebind'
'-dynamiclib'
'-o'
'libanswer.dylib'
'../obj/answer.o'

The ' characters around the executable and arguments are
not part of the command.
[cc] powerpc-apple-darwin9-gcc-4.0.1: i386: No such file or directory
[cc] powerpc-apple-darwin9-gcc-4.0.1: x86_64: No such file or directory
[cc] powerpc-apple-darwin9-gcc-4.0.1: ppc: No such file or directory
[cc] powerpc-apple-darwin9-gcc-4.0.1: ppc64: No such file or directory
[cc] powerpc-apple-darwin9-gcc-4.0.1: @executable_path/../lib/libanswer.dylib: No such file or directory

I am including a patch to address this. I'd appreciate if you accepted this patch.

Thanks!
Andreas

Discussion

  • Andreas Lohr

    Andreas Lohr - 2010-01-10

    patch (Gcc|Gpp)Linker.java to add -arch and -install_name

     
  • Andreas Lohr

    Andreas Lohr - 2010-01-10

    First patch file contained an error - I have fixed it.

     
  • Andreas Lohr

    Andreas Lohr - 2010-01-10

    Someone submitted a patch (2823919) to do the very same same for the -rdynamic linker option. I wonder whether it would be a good idea to remove the decorateLinkerOption() method altogether.

    This method looks like a convenience shortcut which needs to know about a list of linker arguments for which it must not prepend the -Wl flag. Since this exception list is hardcoded, you are lost if you have to use an argument which must not be decorated and is unknown to the Java code.

    With this feature removed, you would still be able add -Wl if needed, e.g. <linkerarg value="-Wl,-whatever"/>. The other way around, i.e. making sure that a specific linker is not prepended with -Wl is not possible at present.

     

Log in to post a comment.