libjsmile.so compilation error on OS X
-
- Posts: 5
- Joined: Fri Aug 22, 2008 11:47 pm
libjsmile.so compilation error on OS X
I've been trying to get jSMILE to compile on OS X and I may be very close to having it work but there seems to be an error that I can't quite figure out.
This is what I did.
1) Download jsmile.
2) Download smile binaries for OS X.
3) cd jsmile
4) copy #2 into jsmile/cppsmile
5) chmod 755 build
6) edit build
a) add
export JINC=/System/Library/Frameworks/JavaVM.framework/Headers/
echo $JINC
to the top of the file.
b) edit the g++ line to change -fpic to -fPIC (gets rid of a host of annoying warnings) and remove -l$JINC/linux.
g++ -O3 -DNDEBUG -feliminate-unused-debug-symbols -fPIC -s -shared -o libjsmile.so ../*.cpp -I$JINC -I../cppsmile -L../cppsmile -lsmilearn -lsmile
7) run ./build
The output is as follows:
$ ./build
/System/Library/Frameworks/JavaVM.framework/Headers/
compiling java source
compiling JNI wrapper
../smile_Network.cpp: In function 'void Java_smile_Network_setEvidence__II(JNIEnv*, _jobject*, jint, jint)':
../smile_Network.cpp:1493: error: call of overloaded 'SetEvidence(jint&)' is ambiguous
../cppsmile/nodeval.h:86: note: candidates are: virtual int DSL_nodeValue::SetEvidence(double)
../cppsmile/nodeval.h:87: note: virtual int DSL_nodeValue::SetEvidence(int)
../smile_learning_Dataset.cpp: In function 'void Java_smile_learning_DataSet_setInt(JNIEnv*, _jobject*, jint, jint, jint)':
../smile_learning_Dataset.cpp:133: error: ambiguous overload for 'operator=' in 'ds-> DSL_dataset::At(((int)variable), ((int)record)) = value'
../cppsmile/dataset.h:21: note: candidates are: DSL_dataElement& DSL_dataElement::operator=(int)
../cppsmile/dataset.h:22: note: DSL_dataElement& DSL_dataElement::operator=(float)
ls: *.so: No such file or directory
-rw-r--r-- 1 stephyn stephyn 29720 Aug 24 12:10 smile.jar
As you can see the libjsmile.so file does not exist and there is an error about an ambiguous overload call to SetEvidence(jint&). I assume the error prevented compilation but I know nothing about C++ so I have no idea how to fix it or if it is the gcc version, or whatnot. What version of gcc was used to compile the OS X binaries?
I'm using g++ is gcc version 4.0.1 (Apple Inc. build 5484)
Any ideas?
Cheers,
Steve
This is what I did.
1) Download jsmile.
2) Download smile binaries for OS X.
3) cd jsmile
4) copy #2 into jsmile/cppsmile
5) chmod 755 build
6) edit build
a) add
export JINC=/System/Library/Frameworks/JavaVM.framework/Headers/
echo $JINC
to the top of the file.
b) edit the g++ line to change -fpic to -fPIC (gets rid of a host of annoying warnings) and remove -l$JINC/linux.
g++ -O3 -DNDEBUG -feliminate-unused-debug-symbols -fPIC -s -shared -o libjsmile.so ../*.cpp -I$JINC -I../cppsmile -L../cppsmile -lsmilearn -lsmile
7) run ./build
The output is as follows:
$ ./build
/System/Library/Frameworks/JavaVM.framework/Headers/
compiling java source
compiling JNI wrapper
../smile_Network.cpp: In function 'void Java_smile_Network_setEvidence__II(JNIEnv*, _jobject*, jint, jint)':
../smile_Network.cpp:1493: error: call of overloaded 'SetEvidence(jint&)' is ambiguous
../cppsmile/nodeval.h:86: note: candidates are: virtual int DSL_nodeValue::SetEvidence(double)
../cppsmile/nodeval.h:87: note: virtual int DSL_nodeValue::SetEvidence(int)
../smile_learning_Dataset.cpp: In function 'void Java_smile_learning_DataSet_setInt(JNIEnv*, _jobject*, jint, jint, jint)':
../smile_learning_Dataset.cpp:133: error: ambiguous overload for 'operator=' in 'ds-> DSL_dataset::At(((int)variable), ((int)record)) = value'
../cppsmile/dataset.h:21: note: candidates are: DSL_dataElement& DSL_dataElement::operator=(int)
../cppsmile/dataset.h:22: note: DSL_dataElement& DSL_dataElement::operator=(float)
ls: *.so: No such file or directory
-rw-r--r-- 1 stephyn stephyn 29720 Aug 24 12:10 smile.jar
As you can see the libjsmile.so file does not exist and there is an error about an ambiguous overload call to SetEvidence(jint&). I assume the error prevented compilation but I know nothing about C++ so I have no idea how to fix it or if it is the gcc version, or whatnot. What version of gcc was used to compile the OS X binaries?
I'm using g++ is gcc version 4.0.1 (Apple Inc. build 5484)
Any ideas?
Cheers,
Steve
-
- Site Admin
- Posts: 1457
- Joined: Mon Nov 26, 2007 5:51 pm
Re: libjsmile.so compilation error on OS X
We're using gcc 4.0.0 build 4061 on Darwin virtualized under VMware.What version of gcc was used to compile the OS X binaries?
To fix the compilation errors you may try to do the following:
Change line 133 in file smile_learning_Dataset.cpp to this:
Code: Select all
ds->At(variable, record).i = value
Code: Select all
int res = node->Value()->SetEvidence(int(outcomeIndex));
-
- Posts: 5
- Joined: Fri Aug 22, 2008 11:47 pm
Re: libjsmile.so compilation error on OS X
Well, we're getting warmer...
I changed the lines you suggested and that fixed that problem. The compiler complained that "-s" was obsolete so I removed it. Additionally, I learned that JNI libraries on OS X should be named with the extension ".jnilib" so I changed *that*. Now, I have the following error:
$ ./build
/System/Library/Frameworks/JavaVM.framework/Headers/
compiling java source
compiling JNI wrapper
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
ls: *.jnilib: No such file or directory
-rw-r--r-- 1 stephyn stephyn 29720 Aug 25 10:34 smile.jar
From what I can glean off the web, this error is due to there not being a "main" method...but there shouldn't be, should there? Is there an option on the g++ command I'm missing? I would have thought that "-shared" would have taken care of that.
Cheers,
Steve
I changed the lines you suggested and that fixed that problem. The compiler complained that "-s" was obsolete so I removed it. Additionally, I learned that JNI libraries on OS X should be named with the extension ".jnilib" so I changed *that*. Now, I have the following error:
$ ./build
/System/Library/Frameworks/JavaVM.framework/Headers/
compiling java source
compiling JNI wrapper
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
ls: *.jnilib: No such file or directory
-rw-r--r-- 1 stephyn stephyn 29720 Aug 25 10:34 smile.jar
From what I can glean off the web, this error is due to there not being a "main" method...but there shouldn't be, should there? Is there an option on the g++ command I'm missing? I would have thought that "-shared" would have taken care of that.
Cheers,
Steve
-
- Site Admin
- Posts: 1457
- Joined: Mon Nov 26, 2007 5:51 pm
Re: libjsmile.so compilation error on OS X
Yes, the 'main' function is the entrypoint for standalone C/C++ executables. '-shared' should indeed result in shared object being built. What happens if you revert back from .jnilib to .so in the command line? If linking succeeds, you should be able to rename .so to .jnilib and continue.sgwbutcher wrote:From what I can glean off the web, this error is due to there not being a "main" method...but there shouldn't be, should there? Is there an option on the g++ command I'm missing? I would have thought that "-shared" would have taken care of that.
-
- Posts: 5
- Joined: Fri Aug 22, 2008 11:47 pm
Re: libjsmile.so compilation error on OS X
Unfornately, whether the output ends with ".so" or ".jnilib" has no bearing on the result. The compilation still fails.
Can't quite figure this one out...
Can't quite figure this one out...
-
- Posts: 5
- Joined: Fri Aug 22, 2008 11:47 pm
Re: libjsmile.so compilation error on OS X
But luckily there are more knowledgeable people out there who can. As the kind soul implicitly noted, this is a Linux to Mac problem, not a JNI problem.sgwbutcher wrote:Unfornately, whether the output ends with ".so" or ".jnilib" has no bearing on the result. The compilation still fails.
Can't quite figure this one out...
1) Put all of the OS X binaries contents into ./cppsmile.
1a) make the changes noted above to cpp files.
2) Make the following changes to the "build" file:
a) Put this at the top:
export JINC=/System/Library/Frameworks/JavaVM.framework/Headers/
echo $JINC
b) Replace the last lines with:
g++ -O3 -DNDEBUG -feliminate-unused-debug-symbols -dynamiclib -o libjsmile.jnilib ../*.cpp -I$JINC -I../cppsmile -L../cppsmile -lsmilearn -lsmile
ls -l *.jnilib *.jar
3) chmod 755 build
4) chmod 755 verify
5) ./build
6) ./verify
and it works as of 2008/08/25, OS X 10.5.4 anyway.
Cheers,
Steve
-
- Site Admin
- Posts: 1457
- Joined: Mon Nov 26, 2007 5:51 pm
Re: libjsmile.so compilation error on OS X
[quote="sgwbutcher]g++ -O3 -DNDEBUG -feliminate-unused-debug-symbols -dynamiclib -o libjsmile.jnilib ../*.cpp -I$JINC -I../cppsmile -L../cppsmile -lsmilearn -lsmile[/quote]
Ok, so it seems that -dynamiclib replaces -shared on OSX.
Ok, so it seems that -dynamiclib replaces -shared on OSX.
Compile but won't link at runtime
I managed to compile SMILE on MacOS using the instructions above - however I cannot bind with the jnilib at runtime. On the running the "verify" script I get the following exception.
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/XXX/Documents/jsmile_src/java/libjsmile.jnilib:
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1822)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1739)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at smile.Wrapper.<clinit>(Wrapper.java:28)
at testApp.loadDataSet(testApp.java:545)
at testApp.main(testApp.java:27)
Any ideas?
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/XXX/Documents/jsmile_src/java/libjsmile.jnilib:
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1822)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1739)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at smile.Wrapper.<clinit>(Wrapper.java:28)
at testApp.loadDataSet(testApp.java:545)
at testApp.main(testApp.java:27)
Any ideas?
-
- Site Admin
- Posts: 1457
- Joined: Mon Nov 26, 2007 5:51 pm
Re: Compile but won't link at runtime
The script sets the LD_LIBRARY_PATH to ensure that JVM can find the native code library. This may not work on Mac - try using -Djava.library.path argument in the java command line.etf wrote:I managed to compile SMILE on MacOS using the instructions above - however I cannot bind with the jnilib at runtime. On the running the "verify" script I get the following exception.
Re: Compile but won't link at runtime
Didn't work... any other ideas?shooltz wrote:The script sets the LD_LIBRARY_PATH to ensure that JVM can find the native code library. This may not work on Mac - try using -Djava.library.path argument in the java command line.etf wrote:I managed to compile SMILE on MacOS using the instructions above - however I cannot bind with the jnilib at runtime. On the running the "verify" script I get the following exception.
Thanks.
-
- Site Admin
- Posts: 1457
- Joined: Mon Nov 26, 2007 5:51 pm
Re: Compile but won't link at runtime
The exception info you've posted contains the complete path to jnilib (/Users/xxx.../libjsmile.jnilib). By any chance, did you modify argument of the System.loadLibary call in Wrapper.java before building jSMILE?etf wrote:Didn't work... any other ideas?
Re: Compile but won't link at runtime
No I did not. I just replaced my username with xxx in the post, I did not change anything in the code. I was simply running the verify script after compilation.shooltz wrote:The exception info you've posted contains the complete path to jnilib (/Users/xxx.../libjsmile.jnilib). By any chance, did you modify argument of the System.loadLibary call in Wrapper.java before building jSMILE?etf wrote:Didn't work... any other ideas?
Any ideas why it doesn't link?
I have been trying these steps. The current code seems not to require the changes (and the linenumbers do not match anymore).
I get the following error and am unsure on how to proceed:
jochem-liems-macbook-pro:jsmile_src jliem$ ./build
/System/Library/Frameworks/JavaVM.framework/Headers/
compiling java source
compiling JNI wrapper
Undefined symbols:
"_FID_ptrNative", referenced from:
_FID_ptrNative$non_lazy_ptr in cc5YjraS.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
ls: *.so: No such file or directory
-rw-r--r-- 1 jliem staff 32000 Sep 11 23:28 smile.jar
Any idea how this can be resolved?
I get the following error and am unsure on how to proceed:
jochem-liems-macbook-pro:jsmile_src jliem$ ./build
/System/Library/Frameworks/JavaVM.framework/Headers/
compiling java source
compiling JNI wrapper
Undefined symbols:
"_FID_ptrNative", referenced from:
_FID_ptrNative$non_lazy_ptr in cc5YjraS.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
ls: *.so: No such file or directory
-rw-r--r-- 1 jliem staff 32000 Sep 11 23:28 smile.jar
Any idea how this can be resolved?
-
- Site Admin
- Posts: 1457
- Joined: Mon Nov 26, 2007 5:51 pm