OS X Issues (Using JNI)

Help
2002-08-30
2003-02-25
  • Brian Sletten

    Brian Sletten - 2002-08-30

    I'm thrilled about this contributed task and am trying to learn its ins and outs. One of the first tasks I'm trying to use it for is to generate Java code and JNI libraries in the same build.xml file.

    On OS X, the syntax is slightly different than normal and my first attempt at translating that doesn't seem to have worked.

    I think the problem has to do with the outtype. When I don't specify it, it tries to build an executable and complains about the missing main. When I try to specify that it is a shared library, it tries to build the standard .so library (even though I specify and require a different name -- see below) and seems to ignore my compilerargs.

    Is there a way with the current task definition that I can duplicate the following command line:

    cc -bundle -I/System/Library/Frameworks/JavaVM.framework/Headers -o libhello.jnilib -framework JavaVM hello.c goodbye.c

    This is what I tried:

            <cc outfile="${localdist}/lib/libHelloWorld.jnilib"
                objdir="${build}">
                <compiler name="gcc">
                    <compilerarg value="-bundle"/>
                    <compilerarg value="-framework JavaVM"/>
                </compiler>
       
                <includepath location="/System/Library/Frameworks/JavaVM.framework/Headers"/>
                <includepath location="/Users/brian/src/c++/jni/src"/>
                <fileset dir="${src}" includes="*.cpp"/>
            </cc>

    This is what I got:

           [cc] 1 total files to be compiled.
           [cc] gcc -bundle "-framework JavaVM" -c -I/System/Library/Frameworks/JavaVM.framework/Headers -I/Users/brian/src/c++/jni/src -W /Users/brian/src/c++/jni/src/HelloWorld.cpp
           [cc] Starting link
           [cc] gcc -o libHelloWorld ../../build/HelloWorld.o
           [cc] /usr/bin/ld: Undefined symbols:
           [cc] _main

    BUILD FAILED
    file:/Users/brian/src/c++/jni/build.xml:29: gcc failed with return code 1
            at net.sf.antcontrib.cpptasks.compiler.CommandLineLinker.link(CommandLineLinker.java:374)
            at net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration.link(CommandLineLinkerConfiguration.java:134)
            at net.sf.antcontrib.cpptasks.CCTask.execute(CCTask.java:864)
            at org.apache.tools.ant.Task.perform(Task.java:317)
            at org.apache.tools.ant.Target.execute(Target.java:309)
            at org.apache.tools.ant.Target.performTasks(Target.java:334)
            at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
            at org.apache.tools.ant.Project.executeTargets(Project.java:1250)
            at org.apache.tools.ant.Main.runBuild(Main.java:610)
            at org.apache.tools.ant.Main.start(Main.java:196)
            at org.apache.tools.ant.Main.main(Main.java:235)

    When I specify a "shared" outtype, I get the following (note the inclusion of the compiler args but the strange quoting of the framework keyword:

           [cc] 1 total files to be compiled.
           [cc] gcc -bundle "-framework JavaVM" -c -fPIC -I/System/Library/Frameworks/JavaVM.framework/Headers -I/Users/brian/src/c++/jni/src -W /Users/brian/src/c++/jni/src/HelloWorld.cpp
           [cc] Starting link
           [cc] gcc -shared -o liblibHelloWorld.so ../../build/HelloWorld.o
           [cc] /usr/bin/ld: Undefined symbols:
           [cc] _main

    BUILD FAILED
    file:/Users/brian/src/c++/jni/build.xml:30: gcc failed with return code 1
            at net.sf.antcontrib.cpptasks.compiler.CommandLineLinker.link(CommandLineLinker.java:374)
            at net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration.link(CommandLineLinkerConfiguration.java:134)
            at net.sf.antcontrib.cpptasks.CCTask.execute(CCTask.java:864)
            at org.apache.tools.ant.Task.perform(Task.java:317)
            at org.apache.tools.ant.Target.execute(Target.java:309)
            at org.apache.tools.ant.Target.performTasks(Target.java:334)
            at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
            at org.apache.tools.ant.Project.executeTargets(Project.java:1250)
            at org.apache.tools.ant.Main.runBuild(Main.java:610)
            at org.apache.tools.ant.Main.start(Main.java:196)
            at org.apache.tools.ant.Main.main(Main.java:235)

    Any advice or future support for these capabilities would be greatly appreciated.

    Thanks,

    Brian

     
    • Stephen M. Webb

      Stephen M. Webb - 2003-02-25

      This issue has been resolved in the CVS source as of 2003.02.20.  You should use the outtype "plugin" and rename the resultant .bundle file with a .jnilib extension.

      The problem with the -framework argument quoting can be worked around by providing the framework switch and  the framework name as two separate arguments.

          <linkerarg value="-framework"/>
          <linkerarg value="JavaVM"/>

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks