Apache Ant and gcc/g++

Hi comunity...

I need to learn how to manage the compilations of c/c++ programs with apache ant. (labor reasons)

The problem is that, most of the aviable information is java oriented.


For now, to begining, the compilation from a all *.cpp inside a folder is enough.

Someone so kind so help me? (Thanks in advance)

I tryed the next code but don`t works,

1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0"?>
<project name="mytask" default="gcc" basedir=".">
	<target name="init">
		<property name="build" location="ejecutables"/> <!-- location ejecutables es el directorio que se creara -->
	</target>
	<target name="gcc" depends="init">
		<cc>
			<mkdir dir="${build}"/>
			<targetdir value="${build}" />
			<sources dir="." includes="*.cpp" />     
		</cc>
	</target> 
</project>


Here is the ant's output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 ant -v
Apache Ant(TM) version 1.9.7 compiled on April 9 2016
Trying the default build file: build.xml
Buildfile: C:\Users\Z003vdhe\JArchivos\ant\02b\build.xml
Detected Java version: 1.8 in: C:\Program Files (x86)\Java\java-1.8.0-openjdk-1.8.x86\jre
Detected OS: Windows 7
parsing buildfile C:\Users\Z003vdhe\JArchivos\ant\02b\build.xml with URI = file:/C:/Users/Z003vdhe/JArchivos/ant/02b/build.xml
Project base dir set to: C:\Users\Z003vdhe\JArchivos\ant\02b
Build sequence for target(s) `gcc' is [init, gcc]
Complete build sequence is [init, gcc, ]

init:
parsing buildfile jar:file:/F:/HV_Branch/Contributions/pnio_tools/ant/apache-ant-1.9.7/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/F:/HV_Branch/Contributions/pnio_tools/ant/apache-ant-1.9.7/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file

gcc:

BUILD FAILED
C:\Users\Z003vdhe\JArchivos\ant\02b\build.xml:7: Problem: failed to create task or type cc
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

        at org.apache.tools.ant.UnknownElement.getNotFoundException(UnknownElement.java:500)
        at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:432)
        at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:164)
        at org.apache.tools.ant.Task.perform(Task.java:347)
        at org.apache.tools.ant.Target.execute(Target.java:435)
        at org.apache.tools.ant.Target.performTasks(Target.java:456)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
        at org.apache.tools.ant.Main.runBuild(Main.java:854)
        at org.apache.tools.ant.Main.startAnt(Main.java:236)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

Total time: 0 seconds
 


Why can not create the cc task? (No idea...)
Problem: failed to create task or type cc

Somewhere there might be a line similar to the one below, which assigns gcc (your c++ compiler) to the value of the property cc.

<condition property="cc" value="gcc">

I think you need to set up an import of some lib or xml file that defines that. If you're in Eclipse, it would involve making sure your paths and stuff are all set up correctly. It simply cannot move forward because it doesn't know where the gcc compiler is - something like that. Or perhaps it can't even understand how to assign a condition property which is on a slightly more fundamental level.

Could there be an ant-contrib-xxx jar that needs importing?

Sorry, that's my best guess for now.
Last edited on
Registered users can post here. Sign in or register to post.