Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should there be a CRFPP.so file being added? #33

Closed
eduOS opened this issue Jul 21, 2016 · 7 comments
Closed

Should there be a CRFPP.so file being added? #33

eduOS opened this issue Jul 21, 2016 · 7 comments

Comments

@eduOS
Copy link

eduOS commented Jul 21, 2016

I followed the README to configure, make and install this program on my Ubuntu 14.04, and in the process of making I encountered an error reads that:

#include "winmain.h"
^
compilation terminated.
make[1]: *** [crf_learn.o] Error 1
make[1]: Leaving directory `/opt/crfpp'
make: *** [all] Error 2

and then I added this from #15 to the project root directory and can pass the make and install processes.

After installation, I tended to run it in eclipse and also tried it in my terminal but both trigger an error again:

Cannot load the example native code.
Make sure your LD_LIBRARY_PATH contains '.'
java.lang.UnsatisfiedLinkError: no CRFPP in java.library.path

I got to know that First of all we must verify that the parameter passed in the System.loadLibrary method is correct and that the library actually exists., so to use the native C++ code we need to load the library as shown bellow in the source code:

static {
try {
System.loadLibrary("CRFPP");
} catch (UnsatisfiedLinkError e) {
System.err.println("Cannot load the example native code.\nMake sure your LD_LIBRARY_PATH contains \'.\'\n" + e);
System.exit(1);
}
}

So according to the the above snippet there should be a CRFPP.so file? But I've not found it. Or where can I find the CRFPP library which I must add to the java.library.path? I guess it may be caused by the later added and non-authoritive winmain.h file. Am I right?

@eduOS eduOS changed the title Should there be a CRFPP.so file added? Should there be a CRFPP.so file being added? Jul 21, 2016
@eduOS
Copy link
Author

eduOS commented Jul 21, 2016

I might have made an embarrassing mistake since the test file is not under the example directory.

@garfieldnate
Copy link

Hi eduOS,
libCRFPP.so is created when you run make in the java/ directory, and you need to add the directory containing it to your java.library.path Java variable. However, it also tries to load libCRFPP.lib (or .dll on Windows) created with make in the project root directory. So you need to make both of those available.

You can look at my fork if you are having trouble compiling on Windows (although there is no installation and you have to configure paths manually).

On Linux I installed it like this:

cd crfpp
chmod +x configure
./configure
make
make install
cd java
make
cp CRFPP.jar /usr/local/lib/CRFPP.jar
cp libCRFPP.so /usr/local/lib/libCRFPP.so
echo "/usr/local/lib" >> /etc/ld.so.conf.d/lib.conf
ldconfig

Then I add /usr/local/lib to my java.library.path and it finds everything.

@eduOS
Copy link
Author

eduOS commented Jul 22, 2016

Thanks so much for your help. I run into one more error now while make in the java directory:

c++ -O3 -c -fpic CRFPP_wrap.cxx  -I/usr/lib/jvm/java-7-openjdk-amd64/include -I/usr/lib/jvm/java-7-openjdk-amd64/include/linux
CRFPP_wrap.cxx:159:17: fatal error: jni.h: No such file or directory
 #include <jni.h>
                 ^
compilation terminated.
make: *** [all] Error 1

It seems that jni.h file is lost.
My OS is Ubuntu 14.04 and the version of my Java is 1.8.x. Should I change Java 8 to Java 1.7.x?

@garfieldnate
Copy link

Yeah, the make files for Linux have hardcoded paths to the Java include files. /usr/lib/jvm/java-7-openjdk-amd64/ probably does not exist. You need to edit the makefile to match your Java installation, probably java-8-... if you installed the latest version.

@eduOS
Copy link
Author

eduOS commented Jul 22, 2016

You're right. I have edited the Makefile replacing the java-7 to the path of java-8 directory containing jni.h. But I met this:

c++ -O3 -c -fpic CRFPP_wrap.cxx  -I/home/leo/lerner/Java/jdk1.8.0_71/include -I/home/leo/lerner/Java/jdk1.8.0_71/include/linux
c++ -shared  CRFPP_wrap.o -o libCRFPP.so -lcrfpp -lpthread
javac org/chasen/crfpp/*.java
javac test.java
jar cfv CRFPP.jar org/chasen/crfpp/*.class
/bin/sh: 1: jar: not found
make: *** [all] Error 127

Should I also tell it where to find the jar?
I found that no jar file exists under the java directory.

I have set the path and I can run jar in my zsh terminal but the error appears all the same.

@eduOS
Copy link
Author

eduOS commented Jul 22, 2016

I thought the CRFPP.jar cannot be created. Everything about java path is properly set in /etc/profile.
Ironically I can manually create the jar file by:
`jar cfv CRFPP.jar org/chasen/crfpp/*.class``
The question is why cannot the script? Is it that the script uses bash and cannot find the jar command while I, using the zsh, can?

I add the java.library.path by:

    Select your project in the Package Explorer area and press a right click on it.
    Select Build Path → Configure Build Path... option.
    In the appearing window, select the Libraries tab.
    Then, expand the JRE System library option and select the Native library location.
    Click on the Edit... button at the right panel.
    Locate the required library and then click OK.
    Close the window.

or for the terminal:

java -Djava.library.path=/usr/local/lib test

But the fourth error occurred:

Exception in thread "main" java.lang.RuntimeException: feature_index.cpp(193) [mmap_.open(model_filename)] mmap.h(153) [(fd = ::open(filename, flag | O_BINARY)) >= 0] open failed: ../model
    at org.chasen.crfpp.CRFPPJNI.new_Tagger(Native Method)
    at org.chasen.crfpp.Tagger.<init>(Tagger.java:183)
    at test.main(test.java:6)

Normally a model is produced after the training, @garfieldnate I reach the place where you are now. Haha.

@eduOS
Copy link
Author

eduOS commented Jul 22, 2016

This issue becomes the same as #26 .

@eduOS eduOS closed this as completed Jul 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants