Problems with msvc and mingw g++

Help
Daff
2008-04-04
2013-04-24
  • Daff
    Daff
    2008-04-04

    Hi.

    I'm new to ant and want to use it with cpptasks for a multi plattform and multi language project (C++ and Java using JNI) on Unix and Windows but it doesn't work with the msvc compiler (Visual Studio 2005).
    Using mingw also leads to an error message for c++ source code because it always seems to use the c and not the c++ compiler.

    My current build.xml testfile

    <project name="hello-world" default="compile-msvc">
        <property file="build.properties"/>
        <!-- Load Ant tasks and types for cpp compilers from cpptasks.jar (in current directory) -->
        <taskdef resource="cpptasks.tasks">
            <classpath>
                <pathelement location="cpptasks.jar"/>
            </classpath>
        </taskdef>
        <taskdef resource="cpptasks.types">
            <classpath>
                <pathelement location="cpptasks.jar"/>
            </classpath>   
        </taskdef>   
       
        <target name="compile-msvc">
            <cc outfile="test-msvc.exe" name="msvc">
               <fileset dir="." includes="main.cpp" />
            </cc>
        </target>   
        <target name="compile-gcc">
            <cc outfile="test-gcc.exe" name="g++">
               <fileset dir="." includes="main.cpp" />
            </cc>
        </target>   
    </project>

    ant compile-msvc

    always leads to

    Total time: 1 second
    F:\build>ant compile-msvc
    Buildfile: build.xml

    compile-msvc:
           [cc] 1 total files to be compiled.

    BUILD FAILED
    F:\build\build.xml:16: cl failed with return code -1073741515

    Total time: 1 second

    and compile-gcc results in some linker errors from the gnu c linker for c++ files (but works with c source).
    Is there a way to view the compiler and linker command lines?

    Thanks
    Daff

     
    • Daff
      Daff
      2008-04-09

      Hm, should have tried this batch file before running ant:
      %VS80COMNTOOLS%vsvars32.bat
      echo %VCINSTALLDIR%

      After that it works.
      Strange thing is, that an exec from within the build skript doesn't set the environment variables for ant:

      <target name="init_win32" if="is_win32">
          <property environment="env" />
          <property name="compiler" value="msvc" />
          <property name="vsvars32" value="${env.VS80COMNTOOLS}vsvars32.bat" />
          <echo>Loading Visual Studio environment variables (from ${vsvars32})</echo>       
          <exec executable="${vsvars32}" />
          <echo>${env.VCINSTALLDIR}</echo>
      </target>

       
      • David Haney
        David Haney
        2008-04-09

        The exec task spawns a child process and that child process cannot affect the environment of the parent (ant) process.

         
    • Daff
      Daff
      2008-04-10

      Thanks thats what I feared. Ok... think I have to write a batch file for windows which sets the environment and then calls ant.