如何用Ant编译构建C++项目?

How to compile and build C++ projects with Ant?

我有几个 Java 组件都是由 Ant 构建的,但是我想再添加一个组件(用 C++ 编写)并且 compile/build 它也在 Ant 中。

是否有我可以遵循的教程或实现此目的的捷径?

提前致谢。

蚂蚁很古老,但你仍然可以很痛苦地做到这一点。

我建议使用现代构建系统 Gradle which has C++ support as well. You can find tutorials on their web-site

看来您不是第一个尝试完成此类任务的人:

make称为ant exec task 您可以将环境变量传递给 make

<exec executable="make" dir="${cpp.project.dir}">
    <env key="KEY" value="VALUE"/>
</exec>

使用这个:

<?xml version="1.0"?>
<project name="hello" default="compile">
    <taskdef resource="cpptasks.tasks"/>
    <target name="compile">
        <cc outfile="main" objdir="obj" outtype="executable">
            <fileset dir="./" includes="*.cpp"/>
            <compiler id="Linuxgcc" name="g++">
                <compilerarg value="-fPIC"/>
            </compiler>
            <linker id="LinuxLinker" name="g++" libtool="true">
                <linkerarg value="-g" if="debug"/>
                <linkerarg value="-fPIC"/>
                <libset libs="stdc++"/>
            </linker>
        </cc>
    </target>
</project>

确保将 cpptasks.jar(http://www.java2s.com/Code/Jar/c/Downloadcpptasksjar.htm) 放在 ant 的 lib 文件夹中