taku910 / crfpp

CRF++: Yet Another CRF toolkit
Other
505 stars 192 forks source link

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

Closed eduOS closed 8 years ago

eduOS commented 8 years ago

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 commented 8 years ago

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

garfieldnate commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

This issue becomes the same as #26 .