[jitsi-dev] Adding new native library to libjitsi


#1

I'm trying to extend libjitsi with a new native library so I:

- added a directory in src/native
- created a .cpp file which calls the native library
- added a new target in src/native/build.xml which create a shared library
- added a new Java file which calls the native library. It has a
static initializer to load the shared library
- ran "mvn install"

The result was lots of lovely error messages about my Java (I'm not a
very experienced Java programmer).
However, once I fixed those I didn't get any errors about my C++. I
may be experienced at C++, but
that is suspicious, so I added #error to the top of the file - and
still didn't get any errors.

How do I force my new shared library to be generated?

Target from build.xml is as follows (this is copied from the
screencapture target).

  <target name="testing" description="Build testing shared library"
    depends="init-native">
    <cc outtype="shared" name="gcc"
outfile="${native_install_dir}/testing" objdir="${obj}">
      <!-- common compiler flags -->
      <compilerarg value="-D_FORTIFY_SOURCE=2" if="is.running.debian"/>
      <compilerarg value="-O3" />
      <compilerarg value="-std=c99" />
      <compilerarg value="-Wall" />
      <compilerarg value="-Wextra" />
      <compilerarg value="-Werror" />

      <!-- Linux specific flags -->
      <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.linux" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux"
if="is.running.linux" />

      <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <linkerarg value="-Wl,--no-undefined" unless="is.running.macos" />
      <linkerarg value="-Wl,-z,relro" if="is.running.debian"/>

      <!-- Mac OS X specific flags -->
      <compilerarg value="-mmacosx-version-min=10.5" if="is.running.macos"/>
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="x86_64" if="is.running.macos" />
      <!--compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="i386" if="is.running.macos" /-->
      <compilerarg
value="-I/System/Library/Frameworks/ApplicationServices.framework/Headers"
if="is.running.macos" />
      <compilerarg
value="-I/System/Library/Frameworks/JavaVM.framework/Headers"
if="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include/darwin"
if="is.running.macos" />

      <linkerarg value="-o" location="end" if="is.running.macos" />
      <linkerarg value="libtesting.jnilib" location="end"
if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="x86_64" if="is.running.macos" />
      <!--linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="i386" if="is.running.macos" /-->
      <linkerarg value="-framework" if="is.running.macos" />
      <linkerarg value="ApplicationServices" if="is.running.macos" />

      <!-- Windows specific flags -->
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.windows" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32"
if="is.running.windows" />

      <linkerarg value="-lgdi32" location="end" if="is.running.windows" />
      <linkerarg value="-otesting.dll" if="is.running.windows" />
      <linkerarg value="-static-libgcc" if="is.running.windows" />
      <linkerarg value="-Wl,--as-needed" if="is.running.windows" />
      <linkerarg value="-Wl,--kill-at" if="is.running.windows" />

      <fileset dir="${src}/native/testing" includes="*.c*"/>
    </cc>
  </target>

Martin


#2

Hi,

native libraries are not automatically build, you need to run ant
testing in the main folder of the project.

Regards
damencho

···

On Mon, Apr 3, 2017 at 8:11 AM, Martin Bonner <martingreybeard@gmail.com> wrote:

I'm trying to extend libjitsi with a new native library so I:

- added a directory in src/native
- created a .cpp file which calls the native library
- added a new target in src/native/build.xml which create a shared library
- added a new Java file which calls the native library. It has a
static initializer to load the shared library
- ran "mvn install"

The result was lots of lovely error messages about my Java (I'm not a
very experienced Java programmer).
However, once I fixed those I didn't get any errors about my C++. I
may be experienced at C++, but
that is suspicious, so I added #error to the top of the file - and
still didn't get any errors.

How do I force my new shared library to be generated?

Target from build.xml is as follows (this is copied from the
screencapture target).

  <target name="testing" description="Build testing shared library"
    depends="init-native">
    <cc outtype="shared" name="gcc"
outfile="${native_install_dir}/testing" objdir="${obj}">
      <!-- common compiler flags -->
      <compilerarg value="-D_FORTIFY_SOURCE=2" if="is.running.debian"/>
      <compilerarg value="-O3" />
      <compilerarg value="-std=c99" />
      <compilerarg value="-Wall" />
      <compilerarg value="-Wextra" />
      <compilerarg value="-Werror" />

      <!-- Linux specific flags -->
      <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.linux" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux"
if="is.running.linux" />

      <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <linkerarg value="-Wl,--no-undefined" unless="is.running.macos" />
      <linkerarg value="-Wl,-z,relro" if="is.running.debian"/>

      <!-- Mac OS X specific flags -->
      <compilerarg value="-mmacosx-version-min=10.5" if="is.running.macos"/>
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="x86_64" if="is.running.macos" />
      <!--compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="i386" if="is.running.macos" /-->
      <compilerarg
value="-I/System/Library/Frameworks/ApplicationServices.framework/Headers"
if="is.running.macos" />
      <compilerarg
value="-I/System/Library/Frameworks/JavaVM.framework/Headers"
if="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include/darwin"
if="is.running.macos" />

      <linkerarg value="-o" location="end" if="is.running.macos" />
      <linkerarg value="libtesting.jnilib" location="end"
if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="x86_64" if="is.running.macos" />
      <!--linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="i386" if="is.running.macos" /-->
      <linkerarg value="-framework" if="is.running.macos" />
      <linkerarg value="ApplicationServices" if="is.running.macos" />

      <!-- Windows specific flags -->
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.windows" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32"
if="is.running.windows" />

      <linkerarg value="-lgdi32" location="end" if="is.running.windows" />
      <linkerarg value="-otesting.dll" if="is.running.windows" />
      <linkerarg value="-static-libgcc" if="is.running.windows" />
      <linkerarg value="-Wl,--as-needed" if="is.running.windows" />
      <linkerarg value="-Wl,--kill-at" if="is.running.windows" />

      <fileset dir="${src}/native/testing" includes="*.c*"/>
    </cc>
  </target>

Martin

_______________________________________________
dev mailing list
dev@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/dev


#3

Yes. I just found that out. To help seed google with instructions,
one needs to:

# As a one time task (and every time you blow away ~/.m2)
mvn dependency:get -DartifactId=maven-ant-tasks
-DgroupId=org.apache.maven -Dversion=2.1.3

# Then to build the library:
ant -lib ~/.m2/repository/org/apache/maven/maven-ant-tasks/2.1.3 jntesting

Then commit the built library in the lib directory.
(I have to say that having built libraries committed like this feels
very icky to me - but it does simplify
deployment a bit.)
Martin

···

On 3 April 2017 at 16:46, Damian Minkov <damencho@jitsi.org> wrote:

Hi,

native libraries are not automatically build, you need to run ant
testing in the main folder of the project.

Regards
damencho

On Mon, Apr 3, 2017 at 8:11 AM, Martin Bonner <martingreybeard@gmail.com> wrote:

I'm trying to extend libjitsi with a new native library so I:

- added a directory in src/native
- created a .cpp file which calls the native library
- added a new target in src/native/build.xml which create a shared library
- added a new Java file which calls the native library. It has a
static initializer to load the shared library
- ran "mvn install"

The result was lots of lovely error messages about my Java (I'm not a
very experienced Java programmer).
However, once I fixed those I didn't get any errors about my C++. I
may be experienced at C++, but
that is suspicious, so I added #error to the top of the file - and
still didn't get any errors.

How do I force my new shared library to be generated?

Target from build.xml is as follows (this is copied from the
screencapture target).

  <target name="testing" description="Build testing shared library"
    depends="init-native">
    <cc outtype="shared" name="gcc"
outfile="${native_install_dir}/testing" objdir="${obj}">
      <!-- common compiler flags -->
      <compilerarg value="-D_FORTIFY_SOURCE=2" if="is.running.debian"/>
      <compilerarg value="-O3" />
      <compilerarg value="-std=c99" />
      <compilerarg value="-Wall" />
      <compilerarg value="-Wextra" />
      <compilerarg value="-Werror" />

      <!-- Linux specific flags -->
      <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.linux" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux"
if="is.running.linux" />

      <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <linkerarg value="-Wl,--no-undefined" unless="is.running.macos" />
      <linkerarg value="-Wl,-z,relro" if="is.running.debian"/>

      <!-- Mac OS X specific flags -->
      <compilerarg value="-mmacosx-version-min=10.5" if="is.running.macos"/>
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="x86_64" if="is.running.macos" />
      <!--compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="i386" if="is.running.macos" /-->
      <compilerarg
value="-I/System/Library/Frameworks/ApplicationServices.framework/Headers"
if="is.running.macos" />
      <compilerarg
value="-I/System/Library/Frameworks/JavaVM.framework/Headers"
if="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include/darwin"
if="is.running.macos" />

      <linkerarg value="-o" location="end" if="is.running.macos" />
      <linkerarg value="libtesting.jnilib" location="end"
if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="x86_64" if="is.running.macos" />
      <!--linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="i386" if="is.running.macos" /-->
      <linkerarg value="-framework" if="is.running.macos" />
      <linkerarg value="ApplicationServices" if="is.running.macos" />

      <!-- Windows specific flags -->
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.windows" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32"
if="is.running.windows" />

      <linkerarg value="-lgdi32" location="end" if="is.running.windows" />
      <linkerarg value="-otesting.dll" if="is.running.windows" />
      <linkerarg value="-static-libgcc" if="is.running.windows" />
      <linkerarg value="-Wl,--as-needed" if="is.running.windows" />
      <linkerarg value="-Wl,--kill-at" if="is.running.windows" />

      <fileset dir="${src}/native/testing" includes="*.c*"/>
    </cc>
  </target>

Martin

_______________________________________________
dev mailing list
dev@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
dev@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/dev


#4

Yes. I just found that out. To help seed google with instructions,
one needs to:

# As a one time task (and every time you blow away ~/.m2)
mvn dependency:get -DartifactId=maven-ant-tasks
-DgroupId=org.apache.maven -Dversion=2.1.3

I also had to add the -DrepoUrl=http://repo.maven.apache.org/maven2/
parameter to avoid
this error:

[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-dependency-plugin:2.1:get
(default-cli) on project standalone-pom: The parameters
'repositoryUrl' for goal
org.apache.maven.plugi
ns:maven-dependency-plugin:2.1:get are missing or invalid -> [Help 1]

···

On Mon, Apr 3, 2017 at 12:16 PM, Martin Bonner <martingreybeard@gmail.com> wrote:

# Then to build the library:
ant -lib ~/.m2/repository/org/apache/maven/maven-ant-tasks/2.1.3 jntesting

Then commit the built library in the lib directory.
(I have to say that having built libraries committed like this feels
very icky to me - but it does simplify
deployment a bit.)
Martin

On 3 April 2017 at 16:46, Damian Minkov <damencho@jitsi.org> wrote:

Hi,

native libraries are not automatically build, you need to run ant
testing in the main folder of the project.

Regards
damencho

On Mon, Apr 3, 2017 at 8:11 AM, Martin Bonner <martingreybeard@gmail.com> wrote:

I'm trying to extend libjitsi with a new native library so I:

- added a directory in src/native
- created a .cpp file which calls the native library
- added a new target in src/native/build.xml which create a shared library
- added a new Java file which calls the native library. It has a
static initializer to load the shared library
- ran "mvn install"

The result was lots of lovely error messages about my Java (I'm not a
very experienced Java programmer).
However, once I fixed those I didn't get any errors about my C++. I
may be experienced at C++, but
that is suspicious, so I added #error to the top of the file - and
still didn't get any errors.

How do I force my new shared library to be generated?

Target from build.xml is as follows (this is copied from the
screencapture target).

  <target name="testing" description="Build testing shared library"
    depends="init-native">
    <cc outtype="shared" name="gcc"
outfile="${native_install_dir}/testing" objdir="${obj}">
      <!-- common compiler flags -->
      <compilerarg value="-D_FORTIFY_SOURCE=2" if="is.running.debian"/>
      <compilerarg value="-O3" />
      <compilerarg value="-std=c99" />
      <compilerarg value="-Wall" />
      <compilerarg value="-Wextra" />
      <compilerarg value="-Werror" />

      <!-- Linux specific flags -->
      <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.linux" />
      <compilerarg value="-I${system.JAVA_HOME}/include/linux"
if="is.running.linux" />

      <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
      <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
      <linkerarg value="-Wl,--no-undefined" unless="is.running.macos" />
      <linkerarg value="-Wl,-z,relro" if="is.running.debian"/>

      <!-- Mac OS X specific flags -->
      <compilerarg value="-mmacosx-version-min=10.5" if="is.running.macos"/>
      <compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="x86_64" if="is.running.macos" />
      <!--compilerarg value="-arch" if="is.running.macos" />
      <compilerarg value="i386" if="is.running.macos" /-->
      <compilerarg
value="-I/System/Library/Frameworks/ApplicationServices.framework/Headers"
if="is.running.macos" />
      <compilerarg
value="-I/System/Library/Frameworks/JavaVM.framework/Headers"
if="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.macos" />
      <compilerarg value="-I${system.JAVA_HOME}/include/darwin"
if="is.running.macos" />

      <linkerarg value="-o" location="end" if="is.running.macos" />
      <linkerarg value="libtesting.jnilib" location="end"
if="is.running.macos" />
      <linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="x86_64" if="is.running.macos" />
      <!--linkerarg value="-arch" if="is.running.macos" />
      <linkerarg value="i386" if="is.running.macos" /-->
      <linkerarg value="-framework" if="is.running.macos" />
      <linkerarg value="ApplicationServices" if="is.running.macos" />

      <!-- Windows specific flags -->
      <compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.windows" />
      <compilerarg value="-I${system.JAVA_HOME}/include/win32"
if="is.running.windows" />

      <linkerarg value="-lgdi32" location="end" if="is.running.windows" />
      <linkerarg value="-otesting.dll" if="is.running.windows" />
      <linkerarg value="-static-libgcc" if="is.running.windows" />
      <linkerarg value="-Wl,--as-needed" if="is.running.windows" />
      <linkerarg value="-Wl,--kill-at" if="is.running.windows" />

      <fileset dir="${src}/native/testing" includes="*.c*"/>
    </cc>
  </target>

Martin

_______________________________________________
dev mailing list
dev@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
dev@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
dev@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/dev