Code Monkey home page Code Monkey logo

javacpp's People

Contributors

saudet avatar

javacpp's Issues

It's tedious to specify each class file when executing JavaCPP.

Right now, unless I missed something, it's required that you specify each class 
file that should be included when generating bindings with JavaCPP.

This works fine but can make you forget to actually update build files
and include files being added. It also makes build files rather ugly.

It would be nice if there was a feature that just lets you specify a root 
package (or directory) that should be included and JavaCPP could locate classes 
that should be included on it's own recursively from
that point (Maybe by looking for the @Platform annotation or some other 
annotation).


Original issue reported on code.google.com by [email protected] on 29 Feb 2012 at 10:03

javacpp.presets does not compile on a fresh checkout

Problem:
javacpp.presets is referencing "javacpp-0.6" which collides with the stable but 
outdated repo version. This results in symbol not found exceptions in maven.

Quick fix:
checkout javacpp source and run mvn install. 

Fix:
rename trunk versions to javacpp-0.6-SNAPSHOT. "-SNAPSHOT is not available" is 
a much cleaner error message.

Florian

Original issue reported on code.google.com by [email protected] on 16 Dec 2013 at 5:36

StringIndexOutOfBoundsException thrown when generating allocate if user forgets to inherit from Pointer.

What steps will reproduce the problem?
1. create a java class with an allocate method mistakenly does not derive from 
Pointer e.g.

public class Foo
{
    public Foo()
    {
        allocate();
    }

    public native void allocate();
}

2. Invoke javacpp on it.

What is the expected output? What do you see instead?

Expect an error message indicating that the problem relates to the class Foo 
but get an exception and stack trace that does not include any mention of the 
problematic class.

     [java] Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
     [java]     at java.lang.String.substring(String.java:1937)
     [java]     at com.googlecode.javacpp.Generator.doCall(Generator.java:929)
     [java]     at com.googlecode.javacpp.Generator.doMethods(Generator.java:636)
     [java]     at com.googlecode.javacpp.Generator.doClasses(Generator.java:498)
     [java]     at com.googlecode.javacpp.Generator.generate(Generator.java:126)
     [java]     at com.googlecode.javacpp.Builder.generateAndCompile(Builder.java:277)
     [java]     at com.googlecode.javacpp.Builder.build(Builder.java:588)
     [java]     at com.googlecode.javacpp.Builder.main(Builder.java:663)


What version of the product are you using? On what operating system?
javacpp-0.1 on OSX.

Please provide any additional information below.

Will attach patch momentarily.

Original issue reported on code.google.com by [email protected] on 4 Jun 2012 at 3:20

Error running ndk-build with javaCPP generated files

Hi,
I am getting several of the following kind of errors from JavaCPP generated 
class when running ndk-build.

In file included from jni/jniTestAccount.cpp:228:   
In file included from 
/Users/resh/android-sdks/android-ndk-r10b/sources/cxx-stl/llvm-libc++/libcxx/inc
lude/vector:265:
/Users/resh/android-sdks/android-ndk-r10b/sources/cxx-stl/llvm-libc++/libcxx/inc
lude/__bit_reference:97:1: error: conflicting types for 'swap'
swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT
^
/Users/resh/android-sdks/android-ndk-r10b/sources/cxx-stl/llvm-libc++/libcxx/inc
lude/__bit_reference:87:1: note: previous definition is here
swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT


At line 228 is a #include <vector>
Wondering if I have to do anything different if doing an ndk-build using clang.
Thanks for any help!

What version of the product are you using? On what operating system?
JavaCPP 0.9

Please provide any additional information below.
I am using ndk-build with NDK_TOOLCHAIN_VERSION=clang

Original issue reported on code.google.com by [email protected] on 1 Oct 2014 at 7:29

passing compiler options does not work

I am not sure if I am using everything correctly, but unfortunately I could not 
find any description on how to pass command line parameters to the compiler.

What steps will reproduce the problem?
1. Try to add "options" annotation value to a class like this:

@Properties({
@Platform(include = { "...", "..." }, link = {"...", "..."}),
@Platform(value = "linux", includepath = linuxIncludepath, linkpath = 
linuxLinkpath, options = "-std=c++0x" ),
...
})

What is the expected output? What do you see instead?

Expected output would be to see g++ called with -std=c++0x parameter added.

NPE is thrown instead:
Exception in thread "main" java.lang.NullPointerException
        at com.googlecode.javacpp.Loader.appendProperty(Loader.java:192)
        at com.googlecode.javacpp.Loader.appendProperties(Loader.java:175)
        at com.googlecode.javacpp.Builder.generateAndCompile(Builder.java:254)
        at com.googlecode.javacpp.Builder.build(Builder.java:585)
        at com.googlecode.javacpp.Builder.main(Builder.java:663)



What version of the product are you using? On what operating system?
 * javacpp v0.2
 * Linux, ia64, Debian 6.0, Oracle VM 1.7.0_05


Thank you!

Original issue reported on code.google.com by [email protected] on 17 Sep 2012 at 3:11

compiler.framework property causes unrecognized command line option error

What steps will reproduce the problem?
1. Use JavaCPP 20120429
2. Add framework properties. eg. framework="Foundation"
3. Run javacpp builder

What is the expected output? What do you see instead?

Dynlib linked with Mac OS X frameworks.

What version of the product are you using? On what operating system?

JavaCPP 20120429, Mac OS X 10.7

Please provide any additional information below.

Here is error message:

g++ -I/System/Library/Frameworks/JavaVM.framework/Headers/ 
-I./../skia/include/core -I./../skia/include/config -I./../skia/include/effects 
-I./../skia/include/images -I./../skia/include/utils 
/Users/eungju/sideprojects/skia-javacpp/target/classes/skia/javacpp/macosx-x86_6
4/jniSkia.cpp -march=x86-64 -m64 -Wall -O3 -fPIC -dynamiclib -o 
/Users/eungju/sideprojects/skia-javacpp/target/classes/skia/javacpp/macosx-x86_6
4/libjniSkia.dylib -L./../skia/out/Release -Wl,-rpath,./../skia/out/Release 
-lcore -lports -lutils -lopts -lopts_ssse3 -leffects -limages -lzlib 
"-framework Foundation" "-framework ApplicationServices" 
cc1plus: error: unrecognized command line option "-framework Foundation"
cc1plus: error: unrecognized command line option "-framework 
ApplicationServices"

JavaCPP should not quote the framework link options. 

Original issue reported on code.google.com by [email protected] on 3 Apr 2012 at 3:43

SIGSEGV on android when native method returns empty string

It seams that NewStringUTF always causes SIGSEGV on android when empty string 
is passed. Even more (and stranger) if empty std::string is used inside JNI 
method then this will also cause segfault, eg:

  std::string rptr("");
  return env->NewStringUTF("test");

will result in SIGSEGV. The solution here seams to be easy, rptr should be 
declared as pointer not reference.

I'm attaching patch that fixes this issue.

Original issue reported on code.google.com by Dariusz.Luksza on 24 Feb 2013 at 9:04

Attachments:

Function parameter annotated with @Const and @ByRef doesn't produce right code

What steps will reproduce the problem?
1. public native void constByrefTest(@Const @ByRef Foobar obj);

What is the expected output? What do you see instead?
pointer->constByrefTest((const unicoi::test::Foobar&)(*pointer0));

but got

pointer->constByrefTest(*(const unicoi::test::Foobar&)pointer0);

What version of the product are you using? On what operating system?
20111001

Please provide any additional information below.
Attached my fix, but would like to know if it can have other bad consequences.

Original issue reported on code.google.com by [email protected] on 17 Oct 2011 at 4:44

Attachments:

javacpp does not find jni.h on OS X Lion

What steps will reproduce the problem?
1. Open any JavaCPP-dependent project in NetBeans (i.e. javacv)
2. Run -> Clean and Build Main Project

What is the expected output? What do you see instead?

Successful output is expected.

 What I see instead:

init:
Deleting: 
/Users/alterscape/src/javacv-read-only/javacv/build/built-jar.properties
deps-jar:
Updating property file: 
/Users/alterscape/src/javacv-read-only/javacv/build/built-jar.properties
javacpp.init:
javacpp.deps-jar:
Updating property file: 
/Users/alterscape/src/javacv-read-only/javacv/build/built-jar.properties
javacpp.compile:
Building jar: /Users/alterscape/src/javacpp-read-only/javacpp/dist/javacpp.jar
To run this application from the command line without Ant, try:
java -cp "/Users/alterscape/src/javacpp-read-only/javacpp/dist/javacpp.jar" 
com.googlecode.javacpp.Builder
Deleting: /Users/alterscape/src/javacpp-read-only/javacpp/dist/README.TXT
Copying 1 file to /Users/alterscape/src/javacpp-read-only/javacpp/dist
javacpp.jar:
Copying 6 files to /Users/alterscape/src/javacv-read-only/javacv/build/classes
Generating source file: 
/Users/alterscape/src/javacv-read-only/javacv/build/classes/com/googlecode/javac
v/cpp/jniopencv_core.cpp
Building library file: 
/Users/alterscape/src/javacv-read-only/javacv/build/classes/com/googlecode/javac
v/cpp/macosx-x86_64/libjniopencv_core.dylib
g++ -I./ 
/Users/alterscape/src/javacv-read-only/javacv/build/classes/com/googlecode/javac
v/cpp/jniopencv_core.cpp -march=x86-64 -m64 -Wall -O3 -fPIC -dynamiclib -o 
/Users/alterscape/src/javacv-read-only/javacv/build/classes/com/googlecode/javac
v/cpp/macosx-x86_64/libjniopencv_core.dylib -L/usr/local/lib/ -lopencv_core 
/Users/alterscape/src/javacv-read-only/javacv/build/classes/com/googlecode/javac
v/cpp/jniopencv_core.cpp:17:17: error: jni.h: No such file or directory

(... more errors follow, a result of missing things that are defined in 
jni.h...)

What version of the product are you using? On what operating system?

javacpp / opencv cloned from google code svn. Compiling on OS X 10.7.1

Please provide any additional information below.

As per 
http://code.google.com/p/javacpp/source/browse/trunk/javacpp/src/com/googlecode/
javacpp/Builder.java?spec=svn10&r=10 lines 47-74, javacpp searches for jni.h up 
to four levels deep in the java.home directory.

On OS X, my java.home resolves to 
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home.

The results of $locate jni.h:

/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.
sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versio
ns/A/Headers/jni.h
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/JavaVM.framework/Versio
ns/A/Headers/jni.h
/Developer-old/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/JavaVM.framework/Ve
rsions/1.4.2/Headers/jni.h
/Developer-old/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/JavaVM.framework/Ve
rsions/1.5.0/Headers/jni.h
/Developer-old/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/JavaVM.framework/Ve
rsions/1.6.0/Headers/jni.h
/Developer-old/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/JavaVM.framework/Ve
rsions/A/Headers/jni.h
/Developer-old/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Ve
rsions/1.6.0/Headers/jni.h
/Developer-old/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Ve
rsions/A/Headers/jni.h
/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h

I can manually modify my javacpp to hardcode the jni.h path, but I'd rather a 
fix get integrated here.

Original issue reported on code.google.com by [email protected] on 28 Sep 2011 at 9:32

Overloaded functions with int and bool parameters don't call the right one

What steps will reproduce the problem?
1. define the following in a class:

   public native int helloTest(int value);
   public native int helloTest(boolean value);

What is the expected output? What do you see instead?
The output is actually logically correct, but at least on Android jboolean is 
being interpreted as int, so when C++ helloTest gets called it goes to the int 
function.

What version of the product are you using? On what operating system?
SVN 2011/10/25, Win 7 x64, Running on Android 2.3.4

Please provide any additional information below.
I found a way around it. If we cast the boolean in Java [@Cast("bool")] then it 
ends up in the right function. But may be we should cast p0 to bool beforehand 
in generated code?

Original issue reported on code.google.com by [email protected] on 25 Oct 2011 at 2:47

JavaCPP_log doesn't print correctly in android

What steps will reproduce the problem?
 - In jniXXX.cpp run 'JavaCPP_log("Test %d", 0);'

What is the expected output? What do you see instead?
 - Expected : Test 0
 - Current  : Test -1098443844

What version of the product are you using? On what operating system?
 - javacpp 0.2
 - android-ndk-r8b
 - Windows7 cygwin

Please provide any additional information below.
 - JavaCPP_log should use __android_log_vprint() instead of __android_log_print().

Original issue reported on code.google.com by [email protected] on 26 Oct 2012 at 2:25

Lack of Maven integration

I have made a quick-n-dirty POM file that enables compilation of JavaCPP with 
Maven 3 and converted the whole project to a maven project. See attachment.

I also made an assembly.xml that creates dist zip files and I had to shuffle 
files around a little to make it conform with "maven recommendations". 

just do:

mvn install 
or
mvn package

to generate a distribution bin dist file that looks pretty much the same as the 
ones under Downloads/. It generates .zip file and includes license texts etc.

This should get you going and should be a good starting point in getting it 
accepted in the central repository.

Original issue reported on code.google.com by [email protected] on 29 Feb 2012 at 9:17

Attachments:

FunctionPointer use was not generating the proper code

What steps will reproduce the problem?
1. Extend a FunctionPointer
2. Add "native void allocate()" & "native OUTPUT call(INPUT)"
3. Generate code

What is the expected output? What do you see instead?
Call to AttachCurrentThread was doing a wrong cast:
if (JavaCPP_vm->AttachCurrentThread((void**)&e, NULL) != JNI_OK) {
should have been
if (JavaCPP_vm->AttachCurrentThread(&e, NULL) != JNI_OK) {

Also there is no DetachCurrentThread, so when the C/C++ threads finish we get a 
seg fault under Android (at least).
if (JavaCPP_vm->DetachCurrentThread() != JNI_OK) {
    return;
}

What version of the product are you using? On what operating system?
20111001 under Win7 x64

Please provide any additional information below.
Attached is the patch for Generator.java.

Original issue reported on code.google.com by [email protected] on 12 Oct 2011 at 7:06

Attachments:

When using inheritance, an objects native pointer is never initialized.

When inheritance is used, the native side is never initialized and isNull() 
equals true after instantiation.

What steps will reproduce the problem?

we have the two following classes:

@Platform(include = 
"BulletCollision/BroadphaseCollision/btBroadphaseInterface.h", link = "bullet")
@Name("btBroadphaseInterface")
public class Broadphase extends Pointer {
    static { Loader.load(BulletNative.class); }
}

@Platform(include = "BulletCollision/BroadphaseCollision/btDbvtBroadphase.h", 
link = "bullet")
@Name("btDbvtBroadphase")
public class DbvtBroadphase extends Broadphase implements IBroadphase {
    static { Loader.load(BulletNative.class); }
}

When creating an instance of this DbvtBroadphase class, isNull()==true after 
creation.

Modifying the DbvtBroadphase class to the following fixes the problem:

@Platform(include = "BulletCollision/BroadphaseCollision/btDbvtBroadphase.h", 
link = "bullet")
@Name("btDbvtBroadphase")
public class DbvtBroadphase extends Broadphase implements IBroadphase {
    static { Loader.load(BulletNative.class); }

    @Allocator private native void allocate();

    public DbvtBroadphase() {
        super();
        allocate();
    }
}


What version of the product are you using? On what operating system?

Using the 2012-01-08 version of JavaCPP.

Original issue reported on code.google.com by [email protected] on 27 Feb 2012 at 10:03

missing maven descriptor pom.xml + groupId/artifactId/version to publish in repositories

Hi,

could you add the following pom.xml (maven) descriptor to your project?
I have added a minimal one as attachment.

It will standardize you project, both for compilation (under eclipse, netbeans, 
intellij, ...), code analysis tools (junit, findbugs, sonar, ..), and it will 
be easy to publish it to maven repositories later (with a given 
groupId,artifactId,version).

Thanks in advance
Thanks for this interesting project


Original issue reported on code.google.com by [email protected] on 7 Apr 2012 at 11:35

  • Merged into: #10

Attachments:

Pointer.equals fail when obj is null

What steps will reproduce the problem?
1. class X extends Pointer
2. X ptr = new X();
3. X.equals(null);

What is the expected output? What do you see instead?
Should show false, but is throwing a NullPointerException

Fix would be in Pointer.java:

    @Override public boolean equals(Object obj) {
        if (obj == null && isNull()) {
            return true;
//fix <--
        } else if (obj == null || isNull()) {
               return false;
//-->
        } else if (obj.getClass() != getClass()) {
            return false;
        } else {
            Pointer other = (Pointer)obj;
            return address == other.address && position == other.position;
        }
    }



Original issue reported on code.google.com by [email protected] on 31 Jul 2012 at 6:59

ffmpeg presets produces uncompileable parsed .java file for avdevice.h

What steps will reproduce the problem?
1. Check out, build and install the latest git head of ffmpeg
2. Build javacpp presets for ffmpeg

What is the expected output? What do you see instead?
The AVAppToDevMessageType and AVDevToAppMessageType enums result in the 
following java code being created:

public static final int public static native @MemberGetter int 
AV_APP_TO_DEV_NONE();

This should simply read:

public static native @MemberGetter int AV_APP_TO_DEV_NONE();

What version of the product are you using? On what operating system?
Latest git head of javacpp and javacpp presets, latest git head of ffmpeg. 
Linux OS.

Please provide any additional information below.
I didn't spend too much time working out how the tokenisation/parsing engine 
works so I can't give a perfect fix. It can however be worked around by adding 
the following code after line 2598 of Parser.h:

decl.text = decl.text.replace("public static final int public static native 
@MemberGetter int", "public static native @MemberGetter int");


Original issue reported on code.google.com by [email protected] on 6 Mar 2014 at 11:55

FunctionPointer call SIGSEGV when the parameter is a class not yet used in Java

What steps will reproduce the problem?
1. protected native void call(FuncTest obj, CallbackEvent evnt);
2. don't use CallbackEvent anywhere in Java the callback is triggered
3. SIGSEGV 

What is the expected output? What do you see instead?
N/A

What version of the product are you using? On what operating system?
20111001, tested on Android 2.3.3

Please provide any additional information below.
I found a potential workaround which seems to work, but don't know the proper 
solution for the problem. If in the first loop of JNI_OnLoad, we do the 
following all the class references are loaded and we don't segfault on call.

jclass jc = JavaCPP_getClass(e, i);

Original issue reported on code.google.com by [email protected] on 17 Oct 2011 at 4:49

BytePointer with nulls getting truncated

Hi,
 I am trying to pass a byte array which has intermittent nulls from Java to C++ using BytePointer.  

byte[] imageBytes = pngAsByteArray(uri);
BytePointer pointer = new BytePointer(imageBytes);

The BytePointer gets truncated at the first null encountered. What is the right 
way to pass such data using JavaCPP?

thanks
- res 

Original issue reported on code.google.com by [email protected] on 9 Jul 2015 at 12:01

Deferred access to @ByVal Pointer callback argument fails

What steps will reproduce the problem?
1. Create a callback function with a @ByVal Pointer-derived argument. 
2. Have the callback method store the argument for later use.
3. Call a method on the stored argument after the callback has exited.

What is the expected output? What do you see instead?

Successful method call.

What is actually happening is that the program fails due to invalid memory 
access.

This is caused as the Pointer.address member is initialised with the address of 
the stack-allocated parameter to the _allocate_callback method. This address 
becomes invalid when the callback method exits.

What version of the product are you using? On what operating system?
20120512 on Android.

Please provide any additional information below.

I think that the argument should remain valid until garbage collected by Java 
as in the Java memory-management paradigm all that is required to keep an 
object alive is to maintain any reference to it.

To achieve this the Pointer.address needs to refer to a heap-allocated copy of 
the argument with a deallocator created the same way as return Pointer objects 
are handled.

This behaviour is more consistent with the usual meaning of by-value parameter 
semantics i.e. pass a copy.

Patch attached.

Original issue reported on code.google.com by [email protected] on 23 May 2012 at 3:32

Attachments:

Core dupmp with callback FunctionPointer

On version 0.3 of JavaCpp I get core dump on android when I try to add callback 
function using Manager.AddEventListener. Here is my native cpp code:

Manger.h:
  namespace Private {
    calss Manager {
      public:
        typedef void (*pnfEvent_t)(Event const* event, void* pointer);
        bool addEventListener(pnfEvent_t event, void* pointer);
    }
  }

Event.h
  Namespace Private {
    class Event {
      public:
        uint8 GetEventId() { return _id; };
    }
  }

which I translated to java:

Manager.java
  @Namespace("Private")
  @Platform(include = {"Manager.h", "Event.h"})
  public class Manager extends Pointer {
    static { load(); }
    @Name("pnfEvent_t")
    public static class OnEvent extends FunctionPointer {
      static { load(); }
      public OnEvent() { allocate(); }
      public OnEvent(Pointer p) { super(p); }
      protected final native void allocate();
      public native void cal(@Const Event, Pointer pointer);
    }
    public native @Cast("bool") boolean AddEventListener(OnEvent event, Pointer pointer);
  }

Event.java
  @Namespace("Private")
  @Platform(include = {"Event.h"})
  public class Event extends Pointer {
    static { load(); }
    public native @Cast("uint8") int GetEventId();
  }

This code works fine on 0.2 and I didn't change anything after updating javacpp 
version. The only thing that I've tried changing was bridge code generation 
with and without "-header" option, but this didn't change anything.

Any hints what could be wrong here?

Original issue reported on code.google.com by Dariusz.Luksza on 11 Dec 2012 at 8:40

Pointer.address()

Please add Pointer.address().
I need this for modifying pointer address.

Code is this.

public long address() {
    return address;
}
public Pointer address(long address) {
    this.address = address;
    return this;
}

Original issue reported on code.google.com by yukoba on 3 Oct 2012 at 2:28

Pass Java fields as a struct on stack, without native heap allocation

This is a suggestion not a request because this is already possible with 
@MemberGetter/Setter way.

My thought is in java, use public member field like c. For example,

Say MyObj.h is like below,

class Option {
  public:
  int write_buffer_size;
  bool create_if_missing;
}
class MyObj {
  public:
  void put(Option& options, std::string& data);
}


Then if I make MyObj.java like below,

class Option extends Pointer {
  @NativeField  // this indicates to sync before/after used.
  public int write_buffer_size;
  @NativeField  // this indicates to sync before/after used.
  public bool create_if_missing;
}
class MyObj extends Pointer {
  native void put(@ByRef Option& options, ...);
}

jniMyObj.cpp would be like below,

JNIEXPORT jobject JNICALL Java_packageName_MyObj_Put(JNIEnv* env, jobject obj, 
jobject arg0, ...) {
  MyObj* ptr = (MyObj*)jlong_to_ptr(env->GetLongField(obj, JavaCPP_addressFID));
  Option* ptr0 = (Option*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID));

  // step 1 : copy from java to c before used
  ptr0->write_buffer_size = env->GetIntFIeld(arg0, Option_write_buffer_sizeFID);
  ptr0->create_if_missing = env->GetBooleanFIeld(arg0, Option_create_if_missingFID);
  ...

  ptr->Put(ptr0, ...);

  // step 2 : copy from c to java after used
  env->SetIntFIeld(arg0, Option_write_buffer_sizeFID, ptr0->write_buffer_size);
  env->SetBooleanFIeld(arg0, Option_create_if_missingFID, ptr0->create_if_missing);
}

If Option is read-only(@Const) then step 2 is unnecessary.
If Option is write-only(?) then step 1 is unnecessary.

This is what I think. There maybe many issues I haven't thought about.
But basically this is my suggestion.
It would make javacpp much more powerful.

Original issue reported on code.google.com by [email protected] on 1 Nov 2012 at 12:52

Nullpointer in Loader.load()

What steps will reproduce the problem?
1. Loading float pointers.
2.
3.

What is the expected output? What do you see instead?

Expecting a floatpointer to successfully allocate, but instead I see a 
NullPointer exception.

What version of the product are you using? On what operating system?

JavaCpp 0.6 on Mac Os X

Please provide any additional information below


import com.googlecode.javacpp.FloatPointer;
import static com.googlecode.javacpp.Loader.load;

public class TestFloatPointer
{

    static {
        load();
    }

    public static void main(String[] args)
    {
        System.out.println("Testing float pointer");
        FloatPointer fp = new FloatPointer(10);
        System.out.println("Built fp of length "+fp.sizeof());

    }
}

---->

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
    at com.googlecode.javacpp.Loader.findLibrary(Loader.java:611)
    at com.googlecode.javacpp.Loader.load(Loader.java:590)
    at com.googlecode.javacpp.Loader.load(Loader.java:541)
    at eclipsecode.floatpointer.TestFloatPointer.<clinit>(TestFloatPointer.java:14)
Java Result: 1

Original issue reported on code.google.com by [email protected] on 17 Oct 2013 at 12:55

Can't get LegacyLibrary example to compile in Windows

In Linux the LegacyLibrary example worked out of the box, but I'm having a lot 
of trouble in Windows. I've setup a clean build server with all Windows 
updates, the latest versions of MinGW (g++4.8) and windows sdk 7.1 to run these 
tests. I've attached more detailed logs for each issue.

mvn -v output:
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 
11:22:22-0400)
Maven home: C:\Program Files\Java\apache-maven-3.1.1
Java version: 1.6.0_45, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_45\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"


======= Bug #1 =======
The MinGW paths in the .properties paths are probably outdated. They should 
reference C:/MinGW/<x> instead of C:/MinGW/local/<x>. 


======= Bug #2 =======
Running "java -jar javacpp.jar LegacyLibrary" with cl set to 
"SetEnv.cmd /Release /x64 /win7" results in the following errors.

jniLegacyLibrary.cpp
C:/MinGW/include/stdio.h(26) : warning C4068: unknown pragma
C:/MinGW/include/_mingw.h(33) : warning C4068: unknown pragma
C:/MinGW/include/sdkddkver.h(26) : warning C4068: unknown pragma
C:/MinGW/include/_mingw.h(51) : fatal error C1189: #error :  ERROR: You must 
use a GNU Compiler.


======= Bug #3 =======
After this I've tried MinGW and replaced the default windows-x86_x64.properties 
with the windows-x86_x64-mingw.properties (and fixed the MinGW paths). 

Btw. is there a better way of switching between properties files ? I haven't 
found anything obvious yet.

This results in the following errors:

jniLegacyLibrary.cpp:1:0: warning: -fPIC ignored for target (all code is 
position independent) [enabled by default]
 /* DO NOT EDIT THIS FILE - IT IS MACHINE GENERATED */
 ^
jniLegacyLibrary.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in


======= Bug #4 =======
Removing -fPic and -amd64 successfully compiles the jniLegacyLibrary.dll. 
However, now I get an unsatisfied linker error due to the missing amd64 mode. 

"Can't load IA 32-bit .dll on a AMD 64-bit platform"

A quick search found that I should install mingw-64 as well, but I haven't had 
time to test that yet.


======================

My experience compiling in Windows is pretty limited, so please stop me if I'm 
going down a wrong path or I'm missing something obvious. I really like the 
idea of your framework and would love to get it to work.

thanks,
Florian

Original issue reported on code.google.com by [email protected] on 16 Dec 2013 at 6:28

Attachments:

Function pointer instances of the same type overwrite each other?

This is a bit of a funny problem and I am not exactly sure if I am doing 
something wrong or facing an actual JavaCPP bug, but I have boiled the issue 
down to a fairly simple code example which is attached to this issue.

The code basically defines a C++ class to which you can attach observers. When 
I create two separate instances of the same class and attach an individual 
observer instance to each one them, the first observer somehow gets overwritten 
by the first. This is only true for the Java version using JavaCPP, though, the 
C++ version works fine. My guess is now that this is a bug in the code 
generated by JavaCPP, but I couldn't figure it out.

Output of the example code:

java -cp javacpp.jar:. Stuff
Observer 2 - value changed: name -> Changed 2
Observer 2 - value changed: name -> Changed
./test
Observer 2 - value changed: name -> Changed 2
Observer 1 - value changed: name -> Changed

Note:

The Makefile was only tested on Mac OS X 10.8 by me.

Original issue reported on code.google.com by [email protected] on 5 Jul 2013 at 12:38

Attachments:

Needed to allow deallocator for factory pattern

In our little project we were using the factory pattern for allocating the 
objects. The problem was that the deallocator was only generated when the when 
the allocator was added. While researching that we realized that anything built 
by the factory pattern was not getting assigned a deallocator in the first 
place.

Since going through the code, we couldn't find a way to allow that, we made the 
attached modification. Using a new annotation "FactoryBuilder" we flag the 
functions which are in the factory pattern so that the they attach the 
deallocator properly.

Attached in the patched Generator.java file and the new annotation.

Original issue reported on code.google.com by [email protected] on 8 Sep 2011 at 3:33

Attachments:

Feature Suggestion : New annotation to specify output library name at java file.

This is a patch for new annotation @Library.
(Related discussion at 
https://groups.google.com/forum/#!msg/javacpp-project/Okyuh93c8Jc/sU4qrrHI4NsJ)

Add '@Library("MyLib")' at java class declaration then
- at build time, all class specified this annotation
will be generated into Mylib.cpp.
- at runtime, Loader.load() of this class will load libMyLib.so

If many java classes use same library, making static final String variable at 
somewhere and using it is good idea for maintainence.

* By definition, @Library can't be used with '-o' command option.
Even if '-o' option is used, @Library will be ignored at build time,
but at runtime Loader.load() still tries to load the annotated library. (you 
have to use Loader.loadLibrary("XXX") anyway.)

* Using @Library at inner class is not supported by current structure. It 
requires more modification.

Original issue reported on code.google.com by [email protected] on 25 Nov 2012 at 2:11

Attachments:

FunctionPointer in method argument generates wrong code

What steps will reproduce the problem?
1. Create some TestClass extends Pointer
2. Define following method:
        public native void someMethod(FunctionPointer func);
3. Generate code

What is the expected output? What do you see instead?
Error in generated code:
 In function 'void Java_Test_00024TestClass_someMethod(JNIEnv*, _jobject*, _jobject*)':
1140: error: 'JavaCPP_com_googlecode_javacpp_FunctionPointer' was not declared 
in this scope
1140: error: 'pointer0' was not declared in this scope
1140: error: expected primary-expression before ')' token
1144: error: 'class iXAPI::Connection' has no member named 'someMethod'

What version of the product are you using? On what operating system?
Mac OS 10.6, Java 7u5

Please provide any additional information below.


Original issue reported on code.google.com by rk3dov on 8 Aug 2012 at 12:33

byte array data (google protobuf) corrupted

What steps will reproduce the problem?
1. Serialize a protobuf message to byte array at Java side then pass it to 
JavaCPP.
2. It's a signed char array in C++ that matches byte array in Java via JavaCPP. 
When C++ gets the signed char array then return it to Java immediately. 
3. Java receives the byte array and compares with the original byte array. It's 
different.

What is the expected output? What do you see instead?
The message go though JavaCPP should not be corrupted.
e.g.
Before is [B@30c2ea0b
After is [B@4c93912f

What version of the product are you using? On what operating system?
JavaCPP 0.8. CentOS-5.8-x86_64

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 8 Aug 2014 at 6:15

Unsafe code produced when returing std::string @ByRef

What steps will reproduce the problem?

Wrapping a function "std::string StringTest()" (using @ByRef) produces the 
following code:


const char* rpointer;
rpointer = (const char*)pointer->StringTest().c_str();
if (rpointer != NULL) {
    r = e->NewStringUTF(rpointer);
}
return r;


This is unsafe, because the temporary std::string holding the result of 
StringTest() does not persist any longer than the calling statement.   So 
rpointer ends up being a pointer into deallocated memory.

Original issue reported on code.google.com by [email protected] on 19 Oct 2012 at 3:21

Feature Request: Provide Means to Access jvm

What steps will reproduce the problem?
1. Attempt to put a Java method call into c++. You can't do it!
2.
3.

What is the expected output? What do you see instead?
Not Relevant.

What version of the product are you using? On what operating system?
Latest on RHEL 5.6

Please provide any additional information below.
I got around this by placing this in my C++ program within the namespace but 
outside of any class:

JavaVM *jvm;

I then purposely placed an error in the C++ to stop javacpp from deleting the 
intermediate c++ file so I could place a line of code to set the jvm. 

Worked like a charm. This would be a killer feature, allowing javacpp to be 
used for new development work that requires bidirectional conversation between 
Java and C++. Not having to fight jni wars and put all that baloney in the  C++ 
code is wonderful, just like jni should have been released from Sun over a 
decade ago...

Original issue reported on code.google.com by [email protected] on 6 Jun 2012 at 12:22

  • Merged into: #13

Compliation fails as Generator uses non-standard std::exception constructor

What steps will reproduce the problem?
1. Use a callback with a @ByVal return type
2. Compile generated code.

What is the expected output? What do you see instead?
Expected successful compilation.
Got, compilation failure due to missing constructor on std::exception


What version of the product are you using? On what operating system?
20120512 on Android compililng on OS X with android-ndk-r7-crystax-5.beta2

Please provide any additional information below.

Generator is generating:
    throw std::exception("Return pointer address is NULL.")

It seems that std::exception does always in include the following constructors 
(see 
http://stackoverflow.com/questions/5157206/why-does-stdexception-have-extra-cons
tructors-in-vc)
    exception(const char *const&);
    exception(const char *const&, int);

Patch attached to change to runtime_error.

Original issue reported on code.google.com by [email protected] on 23 May 2012 at 3:54

Attachments:

Eliminate dependency on libjvm.so when not required

What steps will reproduce the problem?
1.following the LegacyLibrary example on front page;
2.readelf -d linux-x86_64/libjniLegacyLibrary.so shows
  it dependend on libjvm.so

What is the expected output? What do you see instead?
Can we make the libjvm.so dependency optional? I think many JNI so
does not call into JVM, so we can remove libjvm.so?
I guess this could make the result libjniLegacyLibrary.so target much wider 
versions of the JVM.

What version of the product are you using? On what operating system?
HEAD, linux

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 27 May 2013 at 8:54

Enhancement request: User-defined exceptions

Currently, all C++ exceptions are caught by the same function 
JavaCPP_handleException() which either throws a java.lang.RuntimeException with 
the result of what() as message if the causing exception is a std::exception or 
with the message 'Unknown exception.'.

I would like to define mappings between C++ and Java exceptions like this:

@Exception("MyExceptionCPP")
public static class MyExceptionJava extends Exception {
    [...]
}

For the corresponding C++ class defined like this:

class MyExceptionCPP: public std::exception {
    [...]
};

If an exception of type MyExceptionCPP is caught, an exception of type 
MyExceptionJava should be thrown instead of a RuntimeException. This would make 
it easier to distinguish between different kinds of exceptions on the Java side.

Do you think this is feasible?

Original issue reported on code.google.com by [email protected] on 12 Aug 2013 at 9:10

No <Type>Pointer.put(<Type>[] array).

It would be great if there was a method in the pointer classes for directly 
putting an array into memory. This would get rid of some of the "jni overhead" 
from each separate put(pos, value) call that otherwise is needed.

I know it's possible to put in an array via a buffer, however, for some reason, 
the performance of using JavaCPP Pointer classes is several times higher than 
that of the standard Buffer classes (at least under Android 2.3.x), so I tend 
to use <Type>Pointer in my code instead of Buffers.

Original issue reported on code.google.com by [email protected] on 29 Feb 2012 at 9:50

@StdString annotation is ignored for function pointers

I have a class derived from FunctionPointer like this:

public static abstract class Observer extends FunctionPointer {
        public Observer() {
            allocate();
        }

        private native void allocate();

        public abstract void valueChanged(String key, String value);

        public void call(@StdString String key, @StdString String value) {
            this.valueChanged(key, value);
        }
}

The C++ equivalent looks like this:

std::function<void (std::string, std::string)> observer

The generated code will use const char* instead of std::string, leading to 
compiler errors.


Note:

As a workaround, one can post-process the generated file like this:

sed -i 's/(const char\* arg0, const char\* arg1)/(std::string arg0, std::string 
arg1)/g' jniFile.cpp
sed -i 's/obj0 = arg0 == NULL/obj0 = arg0.length() == 0/g' jniFile.cpp
sed -i 's/obj1 = arg1 == NULL/obj1 = arg1.length() == 0/g' jniFile.cpp

Original issue reported on code.google.com by [email protected] on 5 Jul 2013 at 12:26

Generated jini-cpp file Syntax Errors

What steps will reproduce the problem?

Happens every time. Transcript:

[bill@lab-guard1-4600 jni]$ javac -cp javacpp.jar Tps.java
[bill@lab-guard1-4600 jni]$ java -jar javacpp.jar Tps
Generating source file: /home/bill/jni/jniTps.cpp
Building library file: /home/bill/jni/linux-x86/libjniTps.so
g++ -I/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/include 
-I/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/include/linux 
/home/bill/jni/jniTps.cpp -march=i686 -m32 -Wall -O3 -fPIC -shared -s -o 
/home/bill/jni/linux-x86/libjniTps.so 
/home/bill/jni/jniTps.cpp: In function ‘jint JNI_OnLoad(JavaVM*, void*)’:
/home/bill/jni/jniTps.cpp:163: warning: dereferencing type-punned pointer will 
break strict-aliasing rules
/home/bill/jni/jniTps.cpp: In function ‘void JNI_OnUnload(JavaVM*, void*)’:
/home/bill/jni/jniTps.cpp:250: warning: dereferencing type-punned pointer will 
break strict-aliasing rules
/home/bill/jni/jniTps.cpp: In function ‘jboolean 
Java_Tps_00024HmiToTps_init(JNIEnv*, _jobject*)’:
/home/bill/jni/jniTps.cpp:961: error: expected ‘,’ or ‘;’ before 
‘)’ token
/home/bill/jni/jniTps.cpp: In function ‘jboolean 
Java_Tps_00024HmiToTps_cleanup(JNIEnv*, _jobject*)’:
/home/bill/jni/jniTps.cpp:994: error: expected ‘,’ or ‘;’ before 
‘)’ token
/home/bill/jni/jniTps.cpp: In function ‘jboolean 
Java_Tps_00024HmiToTps_startLog(JNIEnv*, _jobject*)’:
/home/bill/jni/jniTps.cpp:1011: error: expected ‘,’ or ‘;’ before 
‘)’ token
/home/bill/jni/jniTps.cpp: In function ‘jboolean 
Java_Tps_00024HmiToTps_stopLog(JNIEnv*, _jobject*)’:
/home/bill/jni/jniTps.cpp:1028: error: expected ‘,’ or ‘;’ before 
‘)’ token
/home/bill/jni/jniTps.cpp: In function ‘jboolean 
Java_Tps_00024HmiToTps_closeLog(JNIEnv*, _jobject*)’:
/home/bill/jni/jniTps.cpp:1045: error: expected ‘,’ or ‘;’ before 
‘)’ token


What is the expected output? What do you see instead?

A clean cpp file that I don't have to remove parenthesis from to get g++ to 
work.

What version of the product are you using? On what operating system?

rhel kernel 2.6.18-308.1.1.el5  on x86 32-bit single cpu
OpenJDK 1.6.0_22
javacpp 20120512

Please provide any additional information below.

Once the cpp is fixed the Java -> cpp works perfectly.

Original issue reported on code.google.com by [email protected] on 24 May 2012 at 1:19

Attachments:

Exception NoSuchMethodError in the beginning of execution on Android 2.2

I launched program based JavaCV on "T-Mobile myTouch 3G" mobile phone and I got 
exception NoSuchMethodError. The exception occurs when the very first command 
from JavaCV is executed

FFmpegFrameGrabber gr = new FFmpegFrameGrabber(video.mp4);

The following stack of the errors was got:

I/dalvikvm(1537): Could not find method java.util.Arrays.copyOf, referenced 
from method com.googlecode.javacpp.Loader.findLibrary
W/dalvikvm(1537): VFY: unable to resolve static method 21064: 
Ljava/util/Arrays;.copyOf ([Ljava/lang/Object;I)[Ljava/lang/Object;
D/dalvikvm(1537): VFY: replacing opcode 0x71 at 0x01bd
D/dalvikvm(1537): VFY: dead code 0x01c0-01c4 in 
Lcom/googlecode/javacpp/Loader;.findLibrary 
(Ljava/lang/Class;Lcom/googlecode/javacpp/Loader$ClassProperties;Ljava/lang/Stri
ng;)[Ljava/net/URL;
I/dalvikvm(1537): Could not find method java.util.Properties.load, referenced 
from method com.googlecode.javacpp.Loader.loadProperties
W/dalvikvm(1537): VFY: unable to resolve virtual method 21145: 
Ljava/util/Properties;.load (Ljava/io/Reader;)V
D/dalvikvm(1537): VFY: replacing opcode 0x6e at 0x002e
I/dalvikvm(1537): Could not find method java.util.Properties.load, referenced 
from method com.googlecode.javacpp.Loader.loadProperties
W/dalvikvm(1537): VFY: unable to resolve virtual method 21145: 
Ljava/util/Properties;.load (Ljava/io/Reader;)V
D/dalvikvm(1537): VFY: replacing opcode 0x6e at 0x0045
D/dalvikvm(1537): VFY: dead code 0x0048-0048 in 
Lcom/googlecode/javacpp/Loader;.loadProperties 
(Ljava/lang/String;)Ljava/util/Properties;
D/dalvikvm(1537): GC_FOR_MALLOC freed 5490 objects / 446584 bytes in 92ms
W/dalvikvm(1537): Exception Ljava/lang/NoSuchMethodError; thrown during 
Lcom/googlecode/javacv/cpp/avformat;.<clinit>

The mobile phone has OS Android 2.2.1

Original issue reported on code.google.com by [email protected] on 4 Nov 2013 at 6:48

Can't run facedetection example

I installed JavaCv into my project follow your instruction. And the code 
doesn't have any bug when I debug it. But when I run it on my android device, 
the program is kicked by itself and throw a message "this application was 
stopped".

What can I do now? Help me, please!

I sent to you my project. SO, can you check it for me?

http://www.mediafire.com/download/yi3y696jcp2nf68/JavaCV-Demo2.rar

Original issue reported on code.google.com by [email protected] on 13 Sep 2013 at 2:31

What's the correct way to implement enums?

What steps will reproduce the problem?
Write a C++ function that takes an enum as a parameter, and another that 
returns an enum. The enum in Java needs to be written.

What is the expected output? What do you see instead?
I don't know what to use for a superclass of my Java enum. There's nothing like 
an EnumPointer class or anything of the sort.

What version of the product are you using? On what operating system?
JavaCPP 0.6. OSX but building for Android.

Please provide any additional information below.
Please provide guidance for how to do something like this. Please add it to the 
tutorial on the main page.

Original issue reported on code.google.com by [email protected] on 18 Nov 2013 at 2:48

problem when using an array of char* as parameter

What steps will reproduce the problem?
1. on eclipse, create an android class using this C dummy signature:
public int callBtSco(int argc, char* argv[]);
2. use the java command line to generate the library for android
3.

What is the expected output? What do you see instead?
The java command line completes successfully but eclipse can not compile the 
class because of "char*". 

If I replace it with:
public native int callBtSco(int argc, CharPointer[] argv); 
The java command line fails:
fabien@dell-debian:~/workspace/btScoTest$ java  -jar libs/javacpp.jar 
-classpath bin/ -classpath bin/classes/ 
-Djava.library.path=/home/fabien/workspace/btScoTest/libs/armeabi -properties 
android-arm  -Dplatform.root=/home/fabien/android/android-ndk-r7  
-Dcompiler.path=/home/fabien/android/android-ndk-r7/toolchains/arm-linux-android
eabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ 
com.test.btsco.BtSco 
Generating source file: 
/home/fabien/workspace/btScoTest/bin/classes/com/test/btsco/jniBtSco.cpp
Building library file: 
/home/fabien/workspace/btScoTest/bin/classes/com/test/btsco/android-arm/libjniBt
Sco.so
/home/fabien/android/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebu
ilt/linux-x86/bin/arm-linux-androideabi-g++ 
--sysroot=/home/fabien/android/android-ndk-r7/platforms/android-9/arch-arm/ 
-I/usr/lib/jvm/java-6-openjdk/include 
-I/usr/lib/jvm/java-6-openjdk/include/linux 
-I/home/fabien/android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/include/ 
-I/home/fabien/android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi
/include/ 
/home/fabien/workspace/btScoTest/bin/classes/com/test/btsco/jniBtSco.cpp 
-march=armv5te -mtune=xscale -msoft-float -Wl,-rpath,lib/ -DANDROID 
-ffunction-sections -funwind-tables -fstack-protector -funswitch-loops 
-finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared 
-Wl,--no-allow-shlib-undefined -s -o 
/home/fabien/workspace/btScoTest/bin/classes/com/test/btsco/android-arm/libjniBt
Sco.so 
-L/home/fabien/android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi
/ -llog -lgnustl_static -lgcc -ldl -lz -lm -lc 
/home/fabien/workspace/btScoTest/bin/classes/com/test/btsco/jniBtSco.cpp: In 
function 'jint Java_com_test_btsco_BtSco_00024BtScoClass_callBtSco(JNIEnv*, 
_jobject*, jint, _jobjectArray*)':
/home/fabien/workspace/btScoTest/bin/classes/com/test/btsco/jniBtSco.cpp:747: 
error: 'pointer1' was not declared in this scope
/home/fabien/workspace/btScoTest/bin/classes/com/test/btsco/jniBtSco.cpp:747: 
error: 'struct JNIEnv_' has no member named 'GetCom'
/home/fabien/workspace/btScoTest/bin/classes/com/test/btsco/jniBtSco.cpp:750: 
error: 'class BtSco::BtScoClass' has no member named 'callBtSco'
/home/fabien/workspace/btScoTest/bin/classes/com/test/btsco/jniBtSco.cpp:752: 
error: 'struct JNIEnv_' has no member named 'ReleaseCom'

What version of the product are you using? On what operating system?
I'm using javacpp-bin-20120218.zip on debian/unstable.

Please provide any additional information below.

This is the corresponding method.
JNIEXPORT jint JNICALL 
Java_com_test_btsco_BtSco_00024BtScoClass_callBtSco(JNIEnv* e, jobject o, jint 
p0, jobjectArray p1) {
    BtSco::BtScoClass* pointer = (BtSco::BtScoClass*)jlong_to_ptr(e->GetLongField(o, JavaCPP_addressFieldID));
    if (pointer == NULL) {
        e->ThrowNew(JavaCPP_getClass(e, 1), "This pointer address is NULL.");
        return 0;
    }
    jint position = e->GetIntField(o, JavaCPP_positionFieldID);
    pointer += position;
     pointer1 = p1 == NULL ? NULL : e->GetCom.googlecode.javacpp.CharPointerArrayElements(p1, NULL);
    jint r = 0;
    try {
        int rvalue = pointer->callBtSco(p0, pointer1);
        r = (jint)rvalue;
        if (p1 != NULL) e->ReleaseCom.googlecode.javacpp.CharPointerArrayElements(p1, pointer1, 0);
    } catch (...) {
        JavaCPP_handleException(e);
    }
    return r;
}

Original issue reported on code.google.com by [email protected] on 24 Feb 2012 at 3:19

Multiple -l<library> when generating bindings with multiple files.

We are using JavaCPP to generate bullet bindings for our 3D engine. When there 
are multiple @Platform(link = "bullet") scattered
in the bindings JavaCPP generates multiple -lbullet arguments. One for each 
file.

We are using the Android NDK.

What steps will reproduce the problem?

Invoke JavaCPP to generate one library using multiple input files with 
individual @Platform() annotations.

We invoke JavaCPP like this:

http://code.google.com/p/dinja-engine/source/browse/physics/pom.xml#66

What is the expected output? What do you see instead?

The following output is generated:

/home/adamw/Archives/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebu
ilt/linux-x86/bin/arm-linux-androideabi-g++ 
-I/usr/lib/jvm/java-6-sun-1.6.0.26/include 
-I/usr/lib/jvm/java-6-sun-1.6.0.26/include/linux 
-I/home/adamw/Archives/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/include/ 
-I/home/adamw/Archives/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi
-v7a/include/ 
-I/home/adamw/Archives/android-ndk-r7/platforms/android-5/arch-arm/usr/include/ 
-I/home/adamw/Projects/dinja-engine/physics/src/main/java/../cpp/ 
/home/adamw/Projects/dinja-engine/physics/target/classes/lib/armeabi-v7a/jniBull
etNative.cpp -march=armv7-a -mtune=xscale 
/home/adamw/Archives/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v
7a/libsupc++.a -Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables 
-fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nostdlib -fPIC 
-shared -Wl,--no-allow-shlib-undefined -s -o 
/home/adamw/Projects/dinja-engine/physics/target/classes/lib/armeabi-v7a/libjniB
ulletNative.so 
-L/home/adamw/Archives/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi
-v7a/ 
-L/home/adamw/Archives/android-ndk-r7/platforms/android-5/arch-arm/usr/lib/ 
-L/home/adamw/Projects/dinja-engine/physics/target/local/armeabi-v7a/ -lbullet 
-lbullet -lbullet -lbullet -lbullet -lbullet -lbullet -lbullet -lbullet 
-lbullet -lbullet -lbullet -lbullet -lbullet -lbullet -lbullet -lbullet 
-lbullet -lbullet -lbullet -lbullet -lbullet -lbullet -lbullet -lbullet -llog 
-lstdc++ -lgcc -ldl -lz -lm -lc 

Please provide any additional information below.

This doesn't really have any negative effect as far as I'm aware at least. 
Also, removing the multiple annotations obviously gets rid of the problem. 
Still, i thought I should report it.

Original issue reported on code.google.com by [email protected] on 27 Feb 2012 at 9:55

Improve debugging

Could you add eg. '-debug' flag which will enable generation of JavaCPP_log 
calls with JNI method name as parameter to all methods. Such debug output would 
be useful on method begin and just before return statement.

Original issue reported on code.google.com by Dariusz.Luksza on 4 Mar 2013 at 4:11

Current snapshot immediately crashes in Windows

What steps will reproduce the problem?

1. calling Loader.java -> loadProperties(String name) in Windows
-> Regex exception on line 118 
-> s.split(File.separator, -1)

Why ?

String.split works on Regex, but File.separator returns "\" which is an escape 
character in both Regex and Java. This causes an immediate crash. This fix 
should make it work on all platforms.

-> s.split(Pattern.quote(File.separator), -1)

Pattern.quote(...) takes an arbitrary String and escapes it. For Windows it 
will return "\\\".

Florian

Original issue reported on code.google.com by [email protected] on 16 Dec 2013 at 3:41

Missing ) when using @Adaptor on method returning String.

What steps will reproduce the problem?
1. Create class method returning string using an @Adaptor annotation.

@Platform(include={"JavaCppExample.h", "MyAdaptor.hpp"})
class Foo extends Pointer
{
      native String @Adaptor("MyAdaptor") foo();
}

2. Run javacpp on class.
3. Compile generated cpp.

What is the expected output? What do you see instead?

Generated cpp compiles with error like:
     [exec] /Users/richard/Asdeq/AndroidPOC/Clients/Android/jni/platform/../../gen/c/javaCpp.cpp: In function '_jstring* Java_com_asdeq_clients_android_javacppexample_MySample_ReturnStringByOptional(JNIEnv*, jobject)':
     [exec] /Users/richard/Asdeq/AndroidPOC/Clients/Android/jni/platform/../../gen/c/javaCpp.cpp:2952:78: error: expected ')' before ';' token

Code generated is like:

    const char* rpointer;
    try {
        MyAdaptor radapter(pointer->foo();   <---- Missing bracket here.
        rpointer = radapter;
        jint rcapacity = (jint)radapter.capacity;
        jlong deallocator = ptr_to_jlong(&(BoostOptionalStringAdaptor::deallocate));

Cause:

doReturnAfter only adds the closing brace for adaptors if the return type is 
assignable to Pointer. 
doReturnBefore allows adaptors to be applied to any non-primitive type 
(including string).

WIll attach a patch momentarily so that doReturnAfter matches doReturnBefore.

However, food for thought, shouldn't adaptors be allowed for any Java type so 
that C++ methods that return  unusual types can have adaptors applied that 
convert to primitives. 

FYI I'm wrapping a class that returns boost::optional<std::string>. I've used 
an adaptor to adapt from boost::optional<string> to String as follows:

#include <boost/optional.hpp>
#include <string>

class BoostOptionalStringAdaptor
{
    public:
        BoostOptionalStringAdaptor(boost::optional<std::string> value)
        {
            this->value = value;
            this->capacity = 1;
        }

        operator const char*()
        {
            // JavaCpp will pass the returned char* to the jni fuction NewStringUTF
            // This will copy the string before the adaptor is destroyed so returning the c_str pointer is ok.
            return value ? value.get().c_str() : NULL;
        }


        static void deallocate(const char* address)
        {
            // Nothing to deallocate
        }

        int capacity;

    private:
        boost::optional<std::string> value;
};



What version of the product are you using? On what operating system?
javacpp-0.1 on OSX.

Please provide any additional information below.

Will attach patch momentarily.


Original issue reported on code.google.com by [email protected] on 5 Jun 2012 at 8:21

Add @Raw annotation for instances where the raw jobject should be passed to C++

What steps will reproduce the problem?
1. Write a C++ method that expects a jobject (actual JVM object)...
2. Try every means known to get it to generate successfully.
3. Receive warnings on generation that you are using an unsupported type.
4. Receive errors on compilation because (in this instance) the parameter being 
passed generates code like the following:

JNIEXPORT void JNICALL Java_com_xxx_XXX_yyy_YYY_00024ZZZ_zzz(JNIEnv* e, jobject 
o, jobject p0) {
    YYY::ZZZ* pointer = (YYY::ZZZ*)jlong_to_ptr(e->GetLongField(o, JavaCPP_addressFieldID));
    if (pointer == NULL) {
        e->ThrowNew(JavaCPP_getClass(e, 1), "This pointer address is NULL.");
        return;
    }
    jint position = e->GetIntField(o, JavaCPP_positionFieldID);
    pointer += position;
     pointer0 = p0;  <--- this is the key line, no type is declared for pointer0 because the intention was to pass the raw jobject
    try {
        pointer->setNodeWrapper(pointer0);
    } catch (...) {
        JavaCPP_handleException(e);
    }
}

What is the expected output? What do you see instead?

JNIEXPORT void JNICALL Java_com_xxx_XXX_yyy_YYY_00024ZZZ_zzz(JNIEnv* e, jobject 
o, jobject p0) {
    YYY::ZZZ* pointer = (YYY::ZZZ*)jlong_to_ptr(e->GetLongField(o, JavaCPP_addressFieldID));
    if (pointer == NULL) {
        e->ThrowNew(JavaCPP_getClass(e, 1), "This pointer address is NULL.");
        return;
    }
    jint position = e->GetIntField(o, JavaCPP_positionFieldID);
    pointer += position;
    jobject pointer0 = p0;  <--- this is the key line, the type is declared for pointer0 as a jobject
    try {
        pointer->setNodeWrapper(pointer0);
    } catch (...) {
        JavaCPP_handleException(e);
    }
}

What version of the product are you using? On what operating system?
2012-02-18

Please provide any additional information below.
Would be a huge deal from my perspective. I've verified that the behavior if 
the source is modified is as desired. (Generate cpp, modify, build without 
regenerating, test).

Original issue reported on code.google.com by [email protected] on 29 Mar 2012 at 8:13

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.