Lib problem & how to include .def in cc

  • cancri7

    cancri7 - 2006-06-16

    Need help as I am new to Ant and Cpptasks.

    I can build my project successfully using Visual Studio 6 (VC6).

    However, I faced two problems when using ccptask.

    1. The output from cc only generates dll. Why does not it generate lib?
    I have verified that the cpptask which I installed on my PC can generate both dll and lib when the outtype="shared" but my lib is not generated.

    2. How to include .def files in cc? (more urgent)
    The def file in my project exports the function in the dll.

    The following shows the Device.def

    LIBRARY "Device.dll"

    The following shows how I use cl and link (command line) to generate the dll and lib.

    cl /nologo /MT /W3 /GX /O2 /I "D:\WINDDK\2600.1106\INC\DDK\WDM\WXP" /D WIN32 /D NDEBUG /D _WINDOWS /D _MBCS /D "_USRDLL" /D "DEVICE_EXPORTS" /YX /FD /c Device.c

    link kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib setupapi.lib hid.lib hidparse.lib /nologo /dll /machine:I386 /DEF:Device /libpath:"D:\WINDDK\2600.1106\LIB\WXP\I386" Device.obj

    As you can see, I have to include /DEF:Device when I call link command.

    Here is the build.xml which I use.

    project name="DeviceService" xmlns:cpptasks="" default="all">   

        <property name="src.dir"   value="sourcecode"/>
        <property name="rel.dir"   value="Release"/>
        <property name="obj.dir"   value="Obj"/>
        <property name="hidinclude.dir"   value="include"/>
        <property name="hidlib.dir"   value="lib"/>

        <taskdef resource="cpptasks.tasks"/>
        <typedef resource="cpptasks.types"/>   

        <target name="compile" >
            <mkdir dir="${rel.dir}"/>
            <cc name="msvc"
                <fileset dir="${src.dir}" includes="*.c" />
                <includepath path="${src.dir};${hidinclude.dir}"/>
                <libset dir="${hidlib.dir}" libs="kernel32,user32,advapi32,shell32,uuid,setupapi,hid,hidparse"/>           
        <target name="clean">
            <echo message="Entering: Deleting Release directory ..." />
            <delete verbose="true" dir="${rel.dir}" />
            <echo message="Exiting: Deleting Release directory ..." />
        <target name="all" depends="clean,compile">
            <echo message="Building Device DLLs ..."/>

    Thanks in advance

    • Mathieu Champlon

      Hello !

      In order to use a definition file I usually add a linkerarg to the cc task like this :
      <cc ...>
         <linkerarg value="/DEF:Device.def"/>

      Actually cpptasks performs as a wrapper above compilers/linkers, therefore most of the time you can use 'compilerarg' and 'linkerarg' as workarounds if a feature is not handled directly.

      Run ant using -v -d and you will be able to see the command lines invoked.

      As for the 'shared' compilation mode not generating the .lib I suspect it's because nothing is exported, try and see with the .def file ?



Log in to post a comment.