#157 linker should pass "-arch xxx" argument directly to libtool

open
Curt Arnold
cpptasks (103)
5
2005-10-05
2005-10-05
Anonymous
No

For building fat (ppc and i386) libs on Mac OS X, it would be nice if linker
worked with the following definition:

<linker id="linker" name="gcc">
<linkerarg value="-arch" />
<linkerarg value="ppc" />
<linkerarg value="-arch" />
<linkerarg value="i386" />
</linker>

however, the above declaration outputs "libtool -Wl,-arch ppc -Wl,-arch
i386 ..." which fails (at least on Mac OS X). It should output "libtool -arch ppc
-arch i386 ..." instead.

decorateLinkerOption in GccLinker.java should pass the "-arch xxx" to GCC
without adding "-Wl" in this case. Ex:

public String decorateLinkerOption(StringBuffer buf, String arg) {
String decoratedArg = arg;
if (arg.length() > 1 && arg.charAt(0) == '-') {
switch (arg.charAt(1)) {
//
// passed automatically by GCC
//
case 'g' :
case 'f' :
case 'F' :
/* Darwin */
case 'a' :
case 'm' :
case 'O' :
case 'W' :
case 'l' :
case 'L' :
case 'u' :
case 'v' :
break;
default :
boolean known = false;
for (int i = 0; i < linkerOptions.length; i++) {
if (linkerOptions[i].equals(arg)) {
known = true;
break;
}
}
if (!known) {
buf.setLength(0);
buf.append("-Wl,");
buf.append(arg);
decoratedArg = buf.toString();
}
break;
}
}
return decoratedArg;
}

Discussion

  • Logged In: NO

    I suppose a better solution would be to add "-arch" as one of the recognized options to
    linkerOptions, ex:

    private static String[] linkerOptions = new String[]{"-arch", "-bundle",
    "-dynamiclib", "-nostartfiles", "-nostdlib", "-prebind", "-s",
    "-static", "-shared", "-symbolic", "-Xlinker",
    "--export-all-symbols", "-static-libgcc",};

    Is it possible to extend the those options using build.xml as a workaround?

     
  • David Hoffer
    David Hoffer
    2007-09-06

    Logged In: YES
    user_id=872165
    Originator: NO

    What is the status of this? I would like to use cpptasks to build OSX universal binary.

     
  • Adding "-arch", to the following files in the linkerOptions Array allows compilation and linking to succeed.
    src/main/java/net/sf/antcontrib/cpptasks/gcc/GccLinker.java
    src/main/java/net/sf/antcontrib/cpptasks/gcc/GppLinker.java

    This is the necessary arguments added to the cc task.

    <!-- Making of the fat binaries -->
    <compilerarg value="-arch" if="osx"/>
    <compilerarg value="i386" if="osx"/>
    <compilerarg value="-arch" if="osx"/>
    <compilerarg value="ppc" if="osx"/>
    <linkerarg value="-arch" if="osx"/>
    <linkerarg value="i386" if="osx"/>
    <linkerarg value="-arch" if="osx"/>
    <linkerarg value="ppc" if="osx"/>

    kc0dhb_at_gmail_dot_com