Issues with JNI .so for FRC

We are attempting to build a JNI shared library for use in our java code. We are using ant to build the library as follows:

  <target name="CowMXP_JNI-build">
      <echo>Building CowGyroJNI shared object for RoboRIO...</echo>
      <apply executable="/usr/local/bin/arm-frc-linux-gnueabi-g++">
      <arg value="-I${user.home}/wpilib/cpp/current/include"/>
          <arg value="-I${java.home}/../include"/>
          <arg value="-I${java.home}/../include/darwin"/>
          <arg value="-std=c++14"/>
          <arg value="-fPIC"/>
          <arg value="-shared"/>
          <arg value="-oCowMXP_JNI.so"/>
          <arg value="-Wl,--whole-archive"/>
          <arg value="-L${user.home}/wpilib/cpp/current/lib"/>
          <arg value="-lwpilib_nonshared"/>
          <arg value="-lntcore"/>
          <arg value="-lHALAthena"/>
          <arg value="-Wl,--no-whole-archive"/>
          <fileset dir="src/com/team1538/lib/c">
            <include name="*.cpp"/>
        </fileset>
      </apply>
  </target>

and running into an error resolving _ZN5nFPGA16nFRC_2016_16_1_020g_currentTargetClassE. Does anyone know what static library provides this? We are already using all static libraries available in wpilib/cpp/current/lib.

austin[23463] iron ~/local/robotics/971-Robot-Code/bazel-971-Robot-Code/external/allwpilib_ni_libraries_repo
$ grep -R "_ZN5nFPGA16nFRC_2016_16_1_020g_currentTargetClassE" ./
Binary file ./libFRC_NetworkCommunicationLV.so.16.0.0 matches
Binary file ./libRoboRIO_FRC_ChipObject.so.16.0.0 matches
austin[23464] iron ~/local/robotics/971-Robot-Code/bazel-971-Robot-Code/external/allwpilib_ni_libraries_repo
$ c++filt 
_ZN5nFPGA16nFRC_2016_16_1_020g_currentTargetClassE
nFPGA::nFRC_2016_16_1_0::g_currentTargetClass
austin[23461] iron (master) ~/local/robotics/971-Robot-Code
$ git grep g_currentTargetClass
third_party/allwpilib_2016/hal/lib/Athena/FRC_FPGA_ChipObject/nInvariantFPGANamespace/nInterfaceGlobals.h:   extern unsigned int g_currentTargetClass;
third_party/allwpilib_2016/hal/lib/Athena/FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/nInterfaceGlobals.h:   extern unsigned int g_currentTargetClass;
third_party/allwpilib_2016/hal/lib/Athena/FRC_FPGA_ChipObject/nRuntimeFPGANamespace/nInterfaceGlobals.h:   extern unsigned int g_currentTargetClass;

Looks like part of libRoboRIO_FRC_ChipObject.so

Note that libRoboRIO_FRC_ChipObject requires other libraries, so you’ll probably need to link to nearly every .so in cpp/current/lib. There’s two ways to do this: the standard JNI .so (which is built using gradle) explicitly links every .so except libwpi.so and libwpi_2015.so. When building C++ via eclipse, libwpi.so is referenced, which is actually a text file which references libwpi_2015.so, which is also a text file which references a bunch of .so’s as well as a couple of .a’s.

Got it - we later found that libHALAthena.so was missing from the roboRIO and copied over all libs to /usr/lib. Finally worked.

All of of those libraries (with the exception of libHALAthena.so) were taken directly from the roboRIO to start with. They’re in a few ni locations, a find on /usr should show them.

New issue - when the JNI library is loaded, our Talons refuse to enable in auto / teleop. Any insight into this?

Do they enable but not get commands (solid yellow), or stay disabled (blinking yellow) when you switch to auto and teleop?

One thing I do wonder about is if you are using the default WPILib in addition to the custom built JNI. The default WPILib has the JNI library built into the JAR, and I wonder if the built in one is conflicting with the custom one you built. Are you modifying WPILib completely, or just trying to add something on top?

They’re blinking yellow/orange (pardon my colorblindness). We’re wrapping some 3rd party MXP code in JNI rather than porting it. I also suspect a conflict, but I’m not sure where it would arise.

Nevermind - found the bug in our JNI code! Had multiple calls to HALInitialize. I’ll post notes on the stuff we did when I have some free time.