如何在 Ant 中使用 GCJ? [英] How to use GCJ with Ant?

查看:34
本文介绍了如何在 Ant 中使用 GCJ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Apache Ant 和 GCJ 都很陌生,我很难通过 Ant 使用 GCJ 进行构建.

I'm fairly new to both Apache Ant and GCJ, and I'm having a hard time trying to build with GCJ via Ant.

我的应用程序在 Scala 中,所以我需要使用 GCJ 将 .class 文件作为源.使用 Ant 将 .scala 编译为 .class 没问题.

My app is in Scala, so I need to use GCJ to take .class files as source. No problem compiling .scala to .class with Ant.

首先我想出了如何手动将 .class 文件编译为 .o(对象),方法如下:

First I figured out how to manually compile a .class file to .o (object), this way:

gcj --classpath=(...) -c (somepath)MouseClickListener.class -o (somepath)MouseClickListener.o

我在这里看到Ant通过javac标签支持GCJ编译.所以我认为这应该有效:

I see here that Ant supports GCJ compilation through the javac tag. So I figured this should work:

<target name="gcjCompile" depends="compile">
    <mkdir dir="${object.dir}" />
    <javac srcdir="${build.dir}"
           destdir="${object.dir}"
           compiler="gcj"
           executable="C:/gcc/gcc-4.3/bin/gcj.exe"
           classpathref="gcjProject.classpath">
        <include name="**/*.class"/>
    </javac>
</target>

但是这个 javac 任务什么也不做,我也没有收到任何错误.有什么线索吗?谢谢

But this javac task does nothing and I get no errors. Any clues? Thanks

推荐答案

听起来您想将您的应用程序链接到本机可执行文件中.这意味着您已经将源代码编译成 JVM 字节码(正如您已经通过将 .scala 编译成 .class 文件所想到的那样).您需要使用 <exec> 任务手动运行 gcj 命令以将字节码编译为 gcc 目标代码文件.

It sounds like you want to link your app into a native executable. That means that you've already compiled the source into JVM bytecode (as you've figured out to do by compiling .scala into .class files). You'll need to run the gcj command manually using the <exec> task to compile the bytecode into gcc object code files.

我会推荐这样的:

<property name="main.class" value="Main" />
<property name="class.dir" value="${basedir}/classes" />
<target name="compile">
  <mkdir dir="${class.dir}" />
  <javac srcdir="${build.dir}"
         destdir="${class.dir}"
         compiler="gcj"
         executable="C:/gcc/gcc-4.3/bin/gcj.exe"
         classpathref="gcjProject.classpath">
    <include name="**/*.java"/>
  </javac>
</target>
<target name="link" depends="compile">
  <mkdir dir="${object.dir"} />
  <exec cmd="C:/gcc/gcc-4.3/bin/gcj.exe">
    <arg value="-classpath=${object.dir}" />
    <arg value="-c" />
    <arg value="*.class" />
  </exec>
</target>

请记住,您需要定义build.dirobject.dir 属性,并且您可能需要添加一个depends编译目标中 javac 之前的任务(或者每次都从头开始重新编译).我可能遗漏了很多东西,如果一开始不起作用,您应该查看手册页(gcj、gcc 和 ant).

Keep in mind that you need to define the build.dir and object.dir properties, and you may need to add a depends task before the javac in the compile target (or just recompile from scratch each time). I may have missed a lot of things, you should check the manual pages (for gcj, gcc, and ant) if it doesn't work at first.

这篇关于如何在 Ant 中使用 GCJ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆