Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

How to ensure my linker wins bid?!

Help
2004-09-28
2013-04-24
  • Markus Wankus
    Markus Wankus
    2004-09-28

    Hi there,

    I am trying to compile a static library using my defined linker and I cannot get it to fire no matter what I do.  I have coded up my own compiler and linker (librarian actually).  The compiler takes .ss files, and creates .obj files, and the librarian takes .obj files and produces .lib files.

    I am defining them in my build file as follows:

        <compiler id="my.compiler" classname="name.of.myCompiler">
            <compilerarg value="-g"/>
            <fileset dir=".." includes="*.ss"/>
        </compiler>
        <linker id="my.linker" classname="name.of.myLibrarian">
            <fileset dir="." includes="*.obj"/>
    </linker>

    Then my target looks like:

        <target name="build" depends="init">
            <cc objdir="." outfile="libname" outtype="static">
                <compiler refid="my.compiler"/>
                <linker refid="my.linker"/>
            </cc>
        </target>

    I get my .ss file to compile just fine using my custom compiler, but the CCTask *always* uses the following commands to create the library:

    [cc] Starting link
    [cc] ar rvs liblibname.a file.obj
    [cc] a - file.obj

    I am even specifying the fileset of all .obj files to be handled by my linker.  Why isn't this working?

    Note - CCTask doesn't even call getLinker() on my compiler to find out what linker it should use.  Why not?

    Thanks,
    Mark.

     
    • Markus Wankus
      Markus Wankus
      2004-09-28

      Neevermiiind.  I had used the TI librarian as a reference - which returns null from getLinker(LinkType arg0).  I changed this to return "this", and it seems to be working.  Well, sort of...it fire up my librarian process and waits forever.  When I kill the process, Ant finished sucessfully and creates the library.  Weird.  I am assuming this is my issue now, and not a cpptasks thing.  I'll dig into it tomorrow.

      Mark.

       
    • Curt Arnold
      Curt Arnold
      2004-09-28

      You don't want to specify a fileset within the linker element.  That is used to specify files that are specific to a specific linker which are added in addition to file object files that are generated by the compile steps.  For example, if you had got compiler specific variants of foo.obj from a 3rd party, you might do:

      <linker name="msvc" if="use-msvc">
         <fileset dir="${3rdparty.dir}" name="foo-msvc.obj"/>
      </linker>

      <linker name="bcc" if="use-bcc">
         <fileset dir="${3rdparty.dir}" name="foo-bcc.obj"/>
      </linker>

      The selection of the ONE linker that will process the link step occurs in CCTask::collectExplicitObjectFiles.  It seems likely that LinkerDef::isActive is returning false for your linker since that would stop it before calling getLinker().  However, it would be very helpful if you could step through that code and see where things are going wrong for you.

      Using a reference does complicate the path through the code, you might try defining the linker within the <cc> element to see if that changes the behavior.

      <target name="build" depends="init">
      <cc objdir="." outfile="libname" outtype="static">
      <compiler refid="my.compiler"/>
      <linker classname="name.of.myLibrarian"/>
      </cc>
      </target>