[SOLVED] Compile Java API in Mac OS 10.11.4

Submitted by mmineo on Sat, 04/23/2016 - 23:31
Forums

I want to complile java API on Mac using FreeLing-4.0-beta2

First I had some compilation errors in tree.h. I added a space between '>'

line 887: template tree_sibling_iterator::tree_sibling_iterator(const basic_sibling_iterator > &p)

and in some other lines the same error. The same issue in dep-tree.h and dep-symbols.h

But now I can't solve the issue with viterbi.h

/usr/local/include/treeler/tag/viterbi.h:100:13: error: unknown type name 'tuple'
typedef tuple Value_t;
^
/usr/local/include/treeler/tag/viterbi.h:100:18: error: expected member name or ';' after declaration specifiers
typedef tuple Value_t;
~~~~~~~~~~~~~^
/usr/local/include/treeler/tag/viterbi.h:101:20: error: use of undeclared identifier 'Value_t'
typedef vector Alpha_t;
^
/usr/local/include/treeler/tag/viterbi.h:252:35: error: use of undeclared identifier 'make_tuple'
Chart_t C(n, Alpha_t(config.L,make_tuple(-HUGE_VAL, -1)));
^
/usr/local/include/treeler/tag/viterbi.h:257:14: error: subscripted value is not an array, pointer, or vector
get<0>(alpha[r.b]) = scores(r);
~~~~~^~~~
/usr/local/include/treeler/tag/viterbi.h:258:14: error: subscripted value is not an array, pointer, or vector
get<1>(alpha[r.b]) = r.a;
~~~~~^~~~
/usr/local/include/treeler/tag/viterbi.h:267:29: error: subscripted value is not an array, pointer, or vector
double& maxs = get<0>(alpha[r.b]);
~~~~~^~~~
/usr/local/include/treeler/tag/viterbi.h:268:26: error: subscripted value is not an array, pointer, or vector
int& maxa = get<1>(alpha[r.b]);
~~~~~^~~~
/usr/local/include/treeler/tag/viterbi.h:271:38: error: subscripted value is not an array, pointer, or vector
maxs = scores(r) + get<0>(alphaP[r.a]);
~~~~~~^~~~
/usr/local/include/treeler/tag/viterbi.h:276:42: error: subscripted value is not an array, pointer, or vector
double s = scores(r) + get<0>(alphaP[r.a]);
~~~~~~^~~~
/usr/local/include/treeler/tag/viterbi.h:294:26: error: subscripted value is not an array, pointer, or vector
maxs = get<0>(alpha[0]);
~~~~~^~
/usr/local/include/treeler/tag/viterbi.h:295:26: error: subscripted value is not an array, pointer, or vector
maxa = get<1>(alpha[0]);
~~~~~^~
/usr/local/include/treeler/tag/viterbi.h:297:18: error: subscripted value is not an array, pointer, or vector
if (get<0>(alpha[l])>maxs) {
~~~~~^~
/usr/local/include/treeler/tag/viterbi.h:299:23: error: subscripted value is not an array, pointer, or vector
maxs = get<0>(alpha[l]);
~~~~~^~
/usr/local/include/treeler/tag/viterbi.h:300:23: error: subscripted value is not an array, pointer, or vector
maxa = get<1>(alpha[l]);
~~~~~^~
/usr/local/include/treeler/tag/viterbi.h:307:25: error: subscripted value is not an array, pointer, or vector
maxa = get<1>(C[i][maxb]);
~~~~^~~~~
/usr/local/include/treeler/tag/viterbi.h:333:37: error: use of undeclared identifier 'make_tuple'
Chart_t FWD(n, Alpha_t(config.L,make_tuple(-HUGE_VAL, -1)));
^
/usr/local/include/treeler/tag/viterbi.h:334:37: error: use of undeclared identifier 'make_tuple'
Chart_t BWD(n, Alpha_t(config.L,make_tuple(-HUGE_VAL, -1)));
^
/usr/local/include/treeler/tag/viterbi.h:345:14: error: subscripted value is not an array, pointer, or vector
get<0>(alpha[r.b]) = scores(r)*config.gamma;
~~~~~^~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.
make: *** [libfreeling_javaAPI.dylib] Error 1

Could you please help me to have my java libraries?

/usr/local/include/treeler/dep/dep-symbols.h:71:64: error: a space is required between consecutive right angle brackets
(use '> >')
inline std::pair map_value>(const Dictionary& d, const string& t) {
^
/usr/local/include/treeler/dep/dep-symbols.h:76:76: error: a space is required between consecutive right angle brackets
(use '> >')
inline std::pair map_value>(const Dictionary& d, const string& t) {
^
/usr/local/include/treeler/dep/dep-symbols.h:81:64: error: a space is required between consecutive right angle brackets
(use '> >')
inline std::pair map_value>(const Dictionary& d, const int& t) {
^
/usr/local/include/treeler/dep/dep-symbols.h:86:76: error: a space is required between consecutive right angle brackets
(use '> >')
inline std::pair map_value>(const Dictionary& d, const int& t) {

FreeLing 4.0 needs C++11.
It seems your compiler does not recognize some C++11 structures.
You need a newer version of your C++ compiler.

I installed C++11 but now I have another problem, I think is in the makefile.

I have this

libfreeling_javaAPI.dylib: freeling_javaAPI.cxx
gcc -lstdc++ /opt/local/lib/libfreeling.dylib -shared -o libfreeling_javaAPI.dylib freeling_javaAPI.cxx -lfreeling -I$(FREELINGDIR)/src/include -L$(FREELINGDIR)/src/libfreeling -L$(FREELINGDIR)/src/libtreeler -I$(FREELINGDIR)/include -I$(FREELINGDIR)/include/treeler -I$(JAVADIR)/include -I/opt/local/include/ -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers -fPIC -std=c++0x -L/opt/local/lib -lboost_system-mt -dynamiclib
$(JAVADIR)/bin/javac $(PACKAGE)/*.java
$(JAVADIR)/bin/jar -cf freeling.jar $(PACKAGE)

and I get this messaje

...
_Java_edu_upc_freeling_freelingJNI_Predicate_1hasArgument in freeling_javaAPI-9b3b16.o
"freeling::predicate::get_argument_by_pos(int) const", referenced from:
_Java_edu_upc_freeling_freelingJNI_Predicate_1getArgumentByPos in freeling_javaAPI-9b3b16.o
"freeling::predicate::get_sense() const", referenced from:
_Java_edu_upc_freeling_freelingJNI_Predicate_1getSense in freeling_javaAPI-9b3b16.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libfreeling_javaAPI.dylib] Error 1

FreeLing is a C++ library, which is contained in libfreeling.so (in Mac, libfreeeling.dylib, I guess). This library is installed by `make install` in `/usr/local/lib`when you compile FreeLing (in Mac, I think it is '/opt/local/lib`or the like).

When you have this library built and installed, you can go to APIs/java and generate the Java API, which is another library (libfreeling_javaAPI.dylib) that contains code that bridges bewteen your Java program and the C++ library mentioned above).

So, you need to make sure that your API (libfreeling_javaAPI.dylib) is properly linked with the actual library, otherwise it is a bridge to nowhere.

The Makefile should take care of that, but it is written for linux, and it may require some tuning to work on Mac. Please read the README in APIs/java, and the comments in the Makefile.

I have compiled Java API in Mac

If somebody else is having the same trouble as me, here is the makefile I used to compile

FREELINGDIR = /Users/martinmineo/Downloads/FreeLing-4.0-beta2
SWIGDIR = /opt/local/share/swig/3.0.7
JAVADIR = /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

# you may change the package name if you want
PACKAGE = edu/upc/freeling
JPACKAGE = edu.upc.freeling

# Change your compiler, if necessary.
GCC=g++

all: freeling_javaAPI.cxx libfreeling_javaAPI.dylib

.PHONY: all

# Compile the C++ API
#Do not forget to to include: /opt/local/include/
#To generate the dynamic library you should use -dynamiclib flag not -shared
libfreeling_javaAPI.dylib: freeling_javaAPI.cxx
$(GCC) /usr/local/lib/libfreeling.dylib -dynamiclib -o libfreeling_javaAPI.dylib freeling_javaAPI.cxx -lfreeling -I$(FREELINGDIR)/include -I$(FREELINGDIR)/include/treeler -I$(FREELINGDIR)/src/include -I$(JAVADIR)/include -I/opt/local/include/ -I$(JAVADIR)/include/linux -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers -fPIC -std=c++0x -L/opt/local/lib -lboost_system-mt
$(JAVADIR)/bin/javac $(PACKAGE)/*.java
$(JAVADIR)/bin/jar -cf freeling.jar $(PACKAGE)

# Build the Java JNI wrapper classes.
freeling_javaAPI.cxx: freeling_javaAPI.i ../common/freeling.i
rm -rf $(PACKAGE)
mkdir -p $(PACKAGE)
swig -java -c++ -package $(JPACKAGE) -outdir $(PACKAGE) -o freeling_javaAPI.cxx -I$(SWIGDIR)/java -I$(SWIGDIR)/std -I$(SWIGDIR) freeling_javaAPI.i

clean:
rm -rf *.jar *.dylib *.cxx *.class edu

You can set this thread as SOLVED :)

Now I have to update my code to work with 4.0 version instead of 3.1 but that's another story
Regards

The problem was that I was using this root "/opt/local/lib/libfreeling.dylib" to compile my java API, but that library was the compiled in freeling 3.1

Now when you compile freeling 4.0 this file is in "/usr/local/lib/libfreeling.dylib"

That was the main problem

I used your Makefile as a basis to write one for Mac.
I included it in APIs/java in the distribution

thanks!