JavaCPP problems compiling the example - javacpp

I just wanted to test JAVACPP and tried the first example from the webpage within my eclipse:
http://code.google.com/p/javacpp/
(LegacyClass and LegacyLibrary)
As soon as I type:
javac -cp libs\javacpp.jar:. src\LegacyLibrary.java
into the commandline I get the following error message:
src\LegacyLibrary.java:1: error: package com.googlecode.javacpp does
not exist import com.googlecode.javacpp.*;
src\LegacyLibrary.java:2: error: package
com.googlecode.javacpp.annotation does not exist import
com.googlecode.javacpp.annotation.*;
src\LegacyLibrary.java:4: error: cannot find symbol
#Platform(include="LegacyLibrary.h")
symbol: class Platform src\LegacyLibrary.java:5: error: cannot find
symbol #Namespace("LegacyLibrary")
symbol: class Namespace src\LegacyLibrary.java:7: error: cannot find
symbol
public static class LegacyClass extends Pointer {
symbol: class Pointer location: class LegacyLibrary src\LegacyLibrary.java:13: error: cannot find symbol
public native #ByRef String get_property(); public native void
set_property(String property);
symbol: class ByRef location: class LegacyClass src\LegacyLibrary.java:16: error: cannot find symbol
public native #ByRef String property(); public native void property(String property);
symbol: class ByRef location: class LegacyClass src\LegacyLibrary.java:8: error: cannot find symbol
static { Loader.load(); }
symbol: variable Loader location: class LegacyClass 8 errors
Why do I get it?
Is it possible to use JavaCPP not having *.cpp and *.h file, but just having a *.dll file?
Or what exactly do I need for using this library?

You're using Windows. Replace the colon ':' by a semi-colon ';'.

Related

How do I find the file containing a ComVisible class registered using regasm?

I have written a class in C# and marked it ComVisible. I uploaded it to my customer's computer and registered it using RegAsm. But when I try to use it from a Python script, I get an error saying "The system cannot find the file specified." If I replace the name of the class with "ThisDoesNotExist.ReportEngine", the error message is "Invalid class string", which is what I would expect. So, it appears that the Python script found the class name ("CrystalReportsRT2.ReportEngine", in case anyone cares) in the registry, but could not find the DLL file containing that class.
If I was working with an old-fashioned COM object, I could find the class name in the registry, note its CLSID, find the registry entry for that CLSID, and file name from the InProcServer32 key. But for a class registered using RegAsm, the InProcServer32 key only contains the class name and other assembly information. How can I find out what file is being looked for so I can verify its existence? Or do I have to add the assembly into the Global Assembly Cache?
I was trying to get a modified version of an existing library to work. I decided to try a brand-new library. I tried this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RegAsmTest
{
[Guid("E476213F-1D62-408C-B89E-D9A8B4814CE1")]
[ComVisible(true)]
public interface ITest
{
int DoSomething(int input);
}
[Guid("C1E26B60-7D25-4EFE-80E9-F958024E22ED")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
[ProgId("RegAsmTest.Test")]
public class Test : ITest
{
public int DoSomething(int input)
{
MessageBox.Show(string.Format("Input was {}", input));
return input;
}
}
}
And I tried using it from Python:
import win32com.client
try:
TestObject = win32com.client.Dispatch("RegAsmTest.Test")
print ("Object created.")
except Exception as ex:
print ("Failed to create object: " + str(ex))
At first I got "Class not registered". I checked to see if I had "Register for COM Interop" checked, and I hadn't. I checked it. I got another error. (I'm sorry, but I've forgotten which.) I tried running RegAsm with /tlb, and I got "System cannot find the file specified." I tried unregistering the library, and got "Invalid class string" where I would have expected "Class not registered". I tried re-registering without /tlb, and got "System cannot find the file specified".
So, I've got three different errors, and I do not know what sequence of operations or missed operations cause them:
Class not registered
Invalid class string
System cannot find the file specified
What do I have to do?

Why is it saying that my public class is not defined when I only have one public class and the class file

import java.util.Scanner;
public class Lab6_2{
public static void main(String[] args){
Scanner sc_1 = new Scanner(System.in);
int numnber, i;
System.out.println("Enter an integer between 1 and 10.");
number = sc_1.nextInt();
}
}
This code is saying "2 errors found:
File: C:\Users\danwr\Downloads\lab 6_2.java [line: 2]
Error: The public type Lab6_2 must be defined in its own file
File: C:\Users\danwr\Downloads\lab 6_2.java [line: 7]
Error: number cannot be resolved to a variable"
Based on your error message I see two issues. The first is it appears that your .java file is named "lab 6_2.java" (with a space character). It needs to be named "lab6_2.java". However, be careful with this - Windows doesn't care that you use "lab" vs. "Lab" but on Unix the file would have to be named "Lab6_2.java".
As for the second error - where is number defined? (and is it spelled correctly)?

redefine static methods with ByteBuddy

Can homebody help me please to give me a hint how to redefine static methods using byte-buddy 1.6.9 ?
I have tried this :
public class Source {
public static String hello(String name) {return null;}
}
public class Target {
public static String hello(String name) {
return "Hello" + name+ "!";
}
}
String helloWorld = new ByteBuddy()
.redefine(Source.class)
.method(named("hello"))
.intercept(MethodDelegation.to(Target.class))
.make()
.load(getClass().getClassLoader())
.getLoaded()
.newInstance()
.hello("World");
I got following Exception :
Exception in thread "main" java.lang.IllegalStateException: Cannot inject already loaded type: class delegation.Source
Thanks
Classes can only be loaded once by each class loader. In order to replace a method, you would need to use a Java agent to hook into the JVM's HotSwap feature.
Byte Buddy provides a class loading strategy that uses such an agent, use:
.load(Source.class.getClassLoader(),
ClassReloadingStrategy.fromInstalledAgent());
This does however require you to install a Java agent. On a JDK, you can do so programmatically, by ByteBuddyAgent.install() (included in the byte-buddy-agent artifact). On a JVM, you have to specify the agent on the command line.

Unity importing DLL causes parser error?

I have a DLL which I am trying to import into my Unity project. I am following this tutorial on their website example. However, this line of code causes a parser error saying that "An extern alias declaration must precede all other elements."
private static extern float FooPluginFunction ();
I have tried searching online for the solution to this error but I do not get any results that are related to Unity. I have the DLL in my assets/plugins folder. Does anyone know what is causing this error and how I would fix it?
Edit: Script containing DLL import.
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class VR : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
[DllImport ("myplugin")]
private static extern TextFunc ();
myplugin.dll is in my Unity assets/plugins folder.
This error says that you have to put your dll import above that line where you use TextFunc() and inside a class.
Edit: Check this.

PDFTRON lib error using proguard

My app is using the pdftron lib (PDFViewCtrlTools). Here there is the class Utils.java and following methods:
public static void debugLogD(String tag, String msg) {
if (BuildConfig.DEBUG) {
Log.d(tag, msg);
}
}
public static void debugLogV(String tag, String msg) {
if (BuildConfig.DEBUG) {
Log.v(tag, msg);
}
}
I am getting following error when release building the app:
[proguard] Initializing...
[proguard] Warning: pdftron.PDF.Utils.Utils: can't find referenced class com.pdftron.pdf.tools.BuildConfig
[proguard] Note: android.support.v4.text.ICUCompatIcs: can't find dynamically referenced class libcore.icu.ICU
[proguard] Note: com.google.android.gms.internal.av calls '(com.google.ads.mediation.MediationAdapter)Class.forName(variable).newInstance()'
[proguard] Note: com.google.android.gms.maps.internal.q: can't find dynamically referenced class com.google.android.gms.maps.internal.CreatorImpl
[proguard] Note: com.google.api.client.util.IOUtils: can't find dynamically referenced class java.nio.file.Files
[proguard] Note: com.google.api.client.util.IOUtils: can't find dynamically referenced class java.nio.file.Path
[proguard] Note: com.google.gson.internal.UnsafeAllocator: can't find dynamically referenced class sun.misc.Unsafe
[proguard] Note: com.sophos.jbase.JBKeyStore: can't find dynamically referenced class android.os.ServiceManager
[proguard] Note: com.sophos.jbase.PRNGFixes: can't find dynamically referenced class org.apache.harmony.xnet.provider.jsse.NativeCrypto
[proguard] Note: com.sophos.jbase.PRNGFixes: can't find dynamically referenced class org.apache.harmony.xnet.provider.jsse.NativeCrypto
[proguard] Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class com.android.org.conscrypt.OpenSSLSocketImpl
[proguard] Note: com.squareup.okhttp.internal.Platform: can't find dynamically referenced class org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl
[proguard] Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
[proguard] Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
[proguard] Note: the configuration refers to the unknown class 'com.pdftron.pdf.tools.BuildConfig'
[proguard] Maybe you meant the fully qualified name 'com.company.product.BuildConfig'?
There are more people having problems when in a project library BuildConfig.DEBUG is used, but I could not find any solution yet for this.
The problem appears only when using tools/proguard/proguard-android-optimize.txt instead of tools/proguard/proguard-android.txt
Have you tried adding the following?
-keep class com.pdftron.pdf.tools.BuildConfig { *; }