Menu

problem building under macosx

Help
mike
2007-03-13
2012-12-06
  • mike

    mike - 2007-03-13

    Hi,

    I'm interesting in building libusbJava under Mac OSX. However, I'm having some problems, and would appreciate any help on this matter.

    -- Mike

    I have modified the build.xml file and the project.properties file.

    Below is the project.properties file:

    ------------------------------------------------------------
    ############################
    # common build properties  #
    ############################
    # folders
    build.dir.src=src
    build.dir.bin=bin

    # filenames
    build.lib.libusb=libusb.a
    build.lib.libusbpp=libusbpp.a
    build.shlib.srcname=LibusbJava.cpp
    build.shlib.win.shlibname=LibusbJava.dll
    build.shlib.linux.shlibname=libusbJava.so
    build.shlib.mac.shlibname=libusbJava.so
    build.test.srcname=LibusbTest
    build.test.execname=LibusbTest

    #####################################
    # Windows specific build properties #
    #####################################
    build.win.compiler=g++
    build.win.windres=windres
    build.win.resource.rc=resource.rc
    build.win.resource.obj=resource.o

    ####################################
    # Linux specific build properties  #
    ####################################
    build.linux.compiler=g++
    build.linux.includes=/usr/lib

    ####################################
    # Mac specific build properties  #
    ####################################
    build.mac.compiler=g++
    build.mac.includes=/usr/local/lib
    build.mac.jni=/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers
    ------------------------------------------------------------

    and here are the additions I made to the build.xml file

    Note: I inserted -dynamiclib, and -dynamiclib arguments because Mac OSX gcc
          doesn't support the -shared argument, and I saw somewhere on the web that these
          two arguments might work.

    ------------------------------------------------------------
        <property name="version.mac" value="${version.major}.${version.minor}.${version.micro}" />
       
        and
       
       
        <target name="macosx" depends="clean" description="--> Build ${build.shlib.mac.shlibname}">

            <exec dir="." executable="${build.mac.compiler}">

                <!-- for debugging -->
                <arg value="-v" />

                <!-- Mac OSX doesn't support -shared -->
                <arg value="-dynamiclib" />

                <arg value="-Wl,-soname,${build.shlib.mac.shlibname}" />

                <arg value="-I${build.mac.includes}" />

                <!-- couldn't find jni.h so added this -->
                <arg value="-I${build.mac.jni}" />

                <!-- Mac OSX doesn't support -shared -->
                <arg value="-dynamiclib" />

                <arg value="${build.shlib.srcname}" />

                <arg value="-o ${build.shlib.mac.shlibname}.${version.mac}" />

                <arg value="${build.mac.includes}/${build.lib.libusb}" />

                <arg value="${build.mac.includes}/${build.lib.libusbpp}" />

            </exec>

        </target>
    ------------------------------------------------------------

    and below is the results of issuing the ant command

    ------------------------------------------------------------
    sudo ant -verbose -debug macosx
    Apache Ant version 1.6.5 compiled on April 11 2006
    Apache Ant version 1.6.5 compiled on April 11 2006
    Buildfile: build.xml
    Adding reference: ant.PropertyHelper
    Detected Java version: 1.5 in: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
    Detected OS: Mac OS X
    Adding reference: ant.ComponentHelper
    Setting ro project property: ant.version -> Apache Ant version 1.6.5 compiled on April 11 2006
    Setting ro project property: ant.file -> /Users/mike/Development/JavaProjects/LibUsbJavaProject/trunk/LibusbJava/build.xml
    Adding reference: ant.projectHelper
    Adding reference: ant.parsing.context
    Adding reference: ant.targets
    parsing buildfile /Users/mike/Development/JavaProjects/LibUsbJavaProject/trunk/LibusbJava/build.xml with URI = file:///Users/mike/Development/JavaProjects/LibUsbJavaProject/trunk/LibusbJava/build.xml
    Setting ro project property: ant.project.name -> LibusbJava
    Adding reference: LibusbJava
    Setting ro project property: ant.file.LibusbJava -> /Users/mike/Development/JavaProjects/LibUsbJavaProject/trunk/LibusbJava/build.xml
    Project base dir set to: /Users/mike/Development/JavaProjects/LibUsbJavaProject/trunk/LibusbJava
    +Target:
    Adding reference: buildfiles
    +Target: clean
    +Target: windows
    +Target: linux
    +Target: macosx
    [property] Loading /Users/mike/Development/JavaProjects/LibUsbJavaProject/trunk/LibusbJava/project.properties
    Setting project property: build.win.resource.obj -> resource.o
    Setting project property: build.test.execname -> LibusbTest
    Setting project property: build.dir.bin -> bin
    Setting project property: build.linux.compiler -> g++
    Setting project property: build.mac.includes -> /usr/local/lib
    Setting project property: build.test.srcname -> LibusbTest
    Setting project property: build.lib.libusbpp -> libusbpp.a
    Setting project property: build.shlib.mac.shlibname -> libusbJava.so
    Setting project property: build.win.resource.rc -> resource.rc
    Setting project property: build.mac.jni -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers
    Setting project property: build.mac.compiler -> g++
    Setting project property: build.shlib.srcname -> LibusbJava.cpp
    Setting project property: build.win.compiler -> g++
    Setting project property: build.dir.src -> src
    Setting project property: build.lib.libusb -> libusb.a
    Setting project property: build.linux.includes -> /usr/lib
    Setting project property: build.win.windres -> windres
    Setting project property: build.shlib.linux.shlibname -> libusbJava.so
    Setting project property: build.shlib.win.shlibname -> LibusbJava.dll
    [property] Loading /Users/mike/Development/JavaProjects/LibUsbJavaProject/trunk/LibusbJava/version.properties
    Setting project property: version.micro -> 2
    Setting project property: version.minor -> 4
    Setting project property: version.nano -> 0
    Setting project property: version.major -> 0
    Setting project property: version.win.rc -> 0,4,2,0
    Setting project property: version.win.str -> 0.4.2.0
    Setting project property: version.linux -> 0.4.2
    Setting project property: version.mac -> 0.4.2
    Could not load a dependent class (com/jcraft/jsch/UserInfo) for type sshexec
    Could not load a dependent class (com/jcraft/jsch/UserInfo) for type scp
    Could not load a dependent class (jdepend/xmlui/JDepend) for type jdepend
    Could not load a dependent class (junit/framework/Test) for type junit
    Adding reference: buildfiles
    Attempting to create object of type org.apache.tools.ant.helper.DefaultExecutor
    Adding reference: ant.executor
    Build sequence for target(s) `macosx' is [clean, macosx]
    Complete build sequence is [clean, macosx, linux, windows, ]

    clean:
    Could not load a dependent class (com/jcraft/jsch/UserInfo) for type sshexec
    Could not load a dependent class (com/jcraft/jsch/UserInfo) for type scp
    Could not load a dependent class (jdepend/xmlui/JDepend) for type jdepend
    Could not load a dependent class (junit/framework/Test) for type junit
    fileset: Setup scanner in dir /Users/mike/Development/JavaProjects/LibUsbJavaProject/trunk/LibusbJava with patternSet{ includes: [**/*.o, **/*.dll, **/*.so.*] excludes: [] }

    macosx:
         [exec] Current OS is Mac OS X
         [exec] Executing 'g++' with arguments:
         [exec] '-v'
         [exec] '-dynamiclib'
         [exec] '-Wl,-soname,libusbJava.so'
         [exec] '-I/usr/local/lib'
         [exec] '-I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers'
         [exec] '-dylib'
         [exec] 'LibusbJava.cpp'
         [exec] '-o libusbJava.so.0.4.2'
         [exec] '/usr/local/lib/libusb.a'
         [exec] '/usr/local/lib/libusbpp.a'
         [exec]
         [exec] The ' characters around the executable and arguments are
         [exec] not part of the command.
    Execute:Java13CommandLauncher: Executing 'g++' with arguments:
    '-v'
    '-dynamiclib'
    '-Wl,-soname,libusbJava.so'
    '-I/usr/local/lib'
    '-I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers'
    '-dylib'
    'LibusbJava.cpp'
    '-o libusbJava.so.0.4.2'
    '/usr/local/lib/libusb.a'
    '/usr/local/lib/libusbpp.a'

    The ' characters around the executable and arguments are
    not part of the command.
         [exec] Using built-in specs.
         [exec] Target: powerpc-apple-darwin8
         [exec] Configured with: /private/var/tmp/gcc/gcc-5341.obj~1/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=powerpc-apple-darwin8 --host=powerpc-apple-darwin8 --target=powerpc-apple-darwin8
         [exec] Thread model: posix
         [exec] gcc version 4.0.1 (Apple Computer, Inc. build 5341)
         [exec]  /usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/cc1plus -quiet -v -I/usr/local/lib -I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers -D__DYNAMIC__ LibusbJava.cpp -fPIC -quiet -dumpbase LibusbJava.cpp -dylib -auxbase LibusbJava -version -D__private_extern__=extern -o /var/tmp//ccpHaxhO.s
         [exec] ignoring nonexistent directory "/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/../../../../powerpc-apple-darwin8/include"
         [exec] #include "..." search starts here:
         [exec] #include <...> search starts here:
         [exec]  /usr/local/lib
         [exec]  /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers
         [exec]  /usr/include/c++/4.0.0
         [exec]  /usr/include/c++/4.0.0/powerpc-apple-darwin8
         [exec]  /usr/include/c++/4.0.0/backward
         [exec]  /usr/local/include
         [exec]  /usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include
         [exec]  /usr/include
         [exec]  /System/Library/Frameworks
         [exec]  /Library/Frameworks
         [exec] End of search list.
         [exec] GNU C++ version 4.0.1 (Apple Computer, Inc. build 5341) (powerpc-apple-darwin8)
         [exec]     compiled by GNU C version 4.0.1 (Apple Computer, Inc. build 5341).
         [exec] GGC heuristics: --param ggc-min-expand=73 --param ggc-min-heapsize=81920
         [exec] Compiler executable checksum: 4f3dfc1e1dae2832661a538a73ff9412
         [exec]  as -arch ppc -o /var/tmp//cc6oL4mm.o /var/tmp//ccpHaxhO.s
         [exec]  /usr/bin/libtool -dynamic -arch_only ppc -noall_load -macosx_version_min 10.3 -multiply_defined suppress -weak_reference_mismatches non-weak -o libusbJava.so.0.4.2 -o a.out /usr/lib/gcc/powerpc-apple-darwin8/4.0.1/crt3.o -L/usr/lib/gcc/powerpc-apple-darwin8/4.0.1 -L/usr/lib/gcc/powerpc-apple-darwin8/4.0.1 -L/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/../../.. -soname libusbJava.so /var/tmp//cc6oL4mm.o /usr/local/lib/libusb.a /usr/local/lib/libusbpp.a -lstdc++ -lgcc_s.10.4 -lgcc -lSystemStubs -lSystem
         [exec] /usr/bin/libtool: unknown option character `o' in: -o libusbJava.so.0.4.2
         [exec] Usage: /usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT]
         [exec] Usage: /usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
         [exec] Result: 1

    BUILD SUCCESSFUL
    Total time: 4 seconds
    ------------------------------------------------------------

     
    • andi

      andi - 2007-03-22

      Hi Mike

      For your output I can only guess, that libtool has a problem with the -o option. Unfortunately I don't have a Mac and don't know how to build a shared library on OS X. I didn't find much documentation either. These are some links which may be helpful.
      Maybe you build some sample application first to see if it works in principal (first link). I'd also recommend to compile and build on the command line and not with the ant script...
      Maybe they can tell you how to build a JNI library in some MAC forum?

      Sorry for not being able to help. But if you get it to work, I'm very interested to include it into the build file...

      Regards, Andreas

      http://developer.apple.com/documentation/Java/Conceptual/Java14Development/05-CoreJavaAPIs/CoreJavaAPIs.html#//apple_ref/doc/uid/TP40001902-210780-TPXREF144

      http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix/compiling/chapter_4_section_9.html#//apple_ref/doc/uid/TP40002850-DontLinkElementID_4

      http://lists.apple.com/archives/java-dev/2001/Jan/msg00474.html

       
    • mike

      mike - 2007-03-23

      Hi Andreas,

      Thanks for the links. I hope to take a look at these this weekend.

      I'll keep you informed on my progress.

      -- Mike

       
    • mike

      mike - 2007-04-08

      Hey  Andreas,

      I used your advice and built the LibusbJava without Ant on my Mac.

      Then I modified the build and property file according so Ant would work.

      Below is the modified build.xml file.

      ---------------------------------------------------------

      <?xml version="1.0"?>
      <!-- ======================================================================

           Build file for LibusbJava Shared Library

          

           REQUIREMENTS:

               winres (only on windows)

               g++

           schlaepfer                                                               
           ====================================================================== -->
      <project name="LibusbJava" basedir=".">
          <description>
                  Build file for LibusbJava Shared Library
          </description>

          <property file="project.properties" />

          <property file="version.properties" />

          <property name="version.win.rc" value="${version.major},${version.minor},${version.micro},${version.nano}" />
          <property name="version.win.str" value="${version.major}.${version.minor}.${version.micro}.${version.nano}" />

          <property name="version.linux" value="${version.major}.${version.minor}.${version.micro}" />

          <property name="version.mac" value="${version.major}.${version.minor}.${version.micro}" />

          <patternset id="buildfiles">

              <include name="**/*.o" />

              <include name="**/*.dll" />

              <include name="**/*.so.*" />

              <include name="**/*.jnilib" />

          </patternset>

          <target name="clean" description="--> Clean build files">

              <delete>

                  <fileset dir=".">

                      <patternset refid="buildfiles" />

                  </fileset>

              </delete>

          </target>

          <target name="windows" description="--> Build ${build.shlib.win.shlibname}">

              <!-- The RC_VERSION_STR string is not recognized by windres as command line argument.

                  I think this is a bug. The only (nasty) workaround I found is to write it directly to the file. -->

              <!--

              <exec dir="." executable="${build.win.windres}">

                  <arg value="-o${build.win.resource.obj}" />

                  <arg value="${build.win.resource.rc}" />

                  <arg value="-DRC_VERSION=${version.rc}" />

                  <arg value="-DRC_VERSION_STR=&apos;\&amp;quot;${version.str}\&amp;quot;&apos;" />

              </exec>

              -->

              <echo level="warning" message="WARNING: If the version has changed -> change the RC_VERSION_STR define in resource.rc to &quot;${version.win.str}&quot;" />

              <exec dir="." executable="${build.win.windres}">

                  <arg value="-o${build.win.resource.obj}" />

                  <arg value="${build.win.resource.rc}" />

                  <arg value="-DRC_VERSION=${version.win.rc}" />

              </exec>

              <exec dir="." executable="${build.win.compiler}">

                  <arg value="-Wall" />

                  <arg value="-D_JNI_IMPLEMENTATION_" />

                  <arg value="-Wl,--kill-at" />

                  <arg value="-mwindows" />

                  <arg value="-shared" />

                  <arg value="-I${basedir}" />

                  <arg value="${build.shlib.srcname}" />

                  <arg value="-o${build.shlib.win.shlibname}" />

                  <arg value="${build.win.resource.obj}" />

                  <arg value="${build.lib.libusb}" />

              </exec>

          </target>

          <target name="linux" depends="clean" description="--> Build ${build.shlib.linux.shlibname}">

              <exec dir="." executable="${build.linux.compiler}">

                  <arg value="-shared" />

                  <arg value="-Wl,-soname,${build.shlib.linux.shlibname}" />

                  <arg value="-I${build.linux.includes}" />

                  <arg value="-shared" />

                  <arg value="${build.shlib.srcname}" />
                  <arg value="-o${build.shlib.linux.shlibname}.${version.linux}" />

                  <arg value="${build.linux.includes}/${build.lib.libusb}" />

                  <arg value="${build.linux.includes}/${build.lib.libusbpp}" />

              </exec>

          </target>

          <target name="mac" depends="clean" description="--> Build ${build.shlib.mac.shlibname}">

              <exec dir="." executable="${build.mac.compiler}">

                  <!-- arguments to pass to gcc -->

                  <arg value="-v" />
                 
                  <arg value="-dynamiclib" />

                  <arg line="-I ${build.mac.jni}" />
                 
                  <arg value="${build.shlib.srcname}" />

                  <arg line="-o ${build.shlib.mac.shlibname}" />

                  <arg line="-current_version ${version.mac}" />
                 
                  <arg line="-l ${build.mac.stdclib}" />
                 
                  <arg value="${build.mac.includes}/${build.mac.lib.libusb}" />

                  <arg value="${build.mac.includes}/${build.mac.lib.libusbpp}" />
             
              </exec>
                 
         
          </target>

      </project>

      ---------------------------------------------------------

      Also, below is the modified project.properties file.

      ---------------------------------------------------------

      ############################
      # common build properties  #
      ############################
      # folders
      build.dir.src=src
      build.dir.bin=bin

      # filenames
      build.lib.libusb=libusb.a
      build.lib.libusbpp=libusbpp.a
      build.mac.lib.libusb=libusb.dylib
      build.mac.lib.libusbpp=libusbpp.dylib
      build.shlib.srcname=LibusbJava.cpp
      build.shlib.win.shlibname=LibusbJava.dll
      build.shlib.linux.shlibname=libusbJava.so
      build.shlib.mac.shlibname=libusbJava.jnilib
      build.test.srcname=LibusbTest
      build.test.execname=LibusbTest

      #####################################
      # Windows specific build properties #
      #####################################
      build.win.compiler=g++
      build.win.windres=windres
      build.win.resource.rc=resource.rc
      build.win.resource.obj=resource.o

      ####################################
      # Linux specific build properties  #
      ####################################
      build.linux.compiler=g++
      build.linux.includes=/usr/lib

      ####################################
      # Mac specific build properties    #
      ####################################
      build.mac.compiler=gcc
      build.mac.jni=/System/Library/Frameworks/JavaVM.framework/Headers/
      build.mac.includes=/usr/local/lib
      build.mac.stdclib=stdc++

      ---------------------------------------------------------

      Thanks again for the help,

      -- Mike

       
      • andi

        andi - 2007-04-09

        Hi Mike

        I've included the changes in the trunk. Thanks for sharing!
        I assume the library works fine on the Mac then?

        Regards, Andreas

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.