Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling Haskell from Java with C in between
    primarykey
    data
    text
    <p>This probably sounds like a nightmare, but I'd really like to get this working. I am using this example for the most part: <a href="http://www.haskell.org/haskellwiki/Calling_Haskell_from_C">Calling C from Haskell</a> and am trying to get this working on ubuntu.</p> <p>I am running this in java:</p> <pre><code>package test; public class JniTest { public native int fib(int x); } </code></pre> <p>this in c after creating the .h file with javah: (test_JniTest.c)</p> <pre><code>#include "test_JniTest.h" #include "Safe_stub.h" JNIEXPORT jint JNICALL Java_test_JniTest_fib(JNIEnv * e, jobject o, jint f) { return fibonacci_hs(f); } </code></pre> <p>and then for reference in haskell (before stub): (Safe.hs)</p> <pre><code>module Safe where import Foreign.C.Types fibonacci :: Int -&gt; Int fibonacci n = fibs !! n where fibs = 0 : 1 : zipWith (+) fibs (tail fibs) fibonacci_hs :: CInt -&gt; CInt fibonacci_hs = fromIntegral . fibonacci . fromIntegral foreign export ccall fibonacci_hs :: CInt -&gt; CInt </code></pre> <p>and this is what i'm trying to compile it with:</p> <blockquote> <p>ghc -c -O Safe.hs</p> </blockquote> <p>followed by:</p> <blockquote> <p>ghc -shared -o libTest.jnilib -optc-O test_JniTest.c -I/usr/lib/jvm/java-6-sun-1.6.0.26/include -I/usr/lib/jvm/java-6-sun-1.6.0.26/include/linux</p> </blockquote> <p>and I am getting this error: </p> <blockquote> <p>/usr/bin/ld: test_JniTest.o: relocation R_X86_64_PC32 against undefined symbol `fibonacci_hs' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value collect2: ld returned 1 exit status</p> </blockquote> <p>I am not a c expert by any means and have no idea what to do about this. I tried compiling various ways with -fPIC, but I kept on getting the same error. Any idea what I might be doing wrong?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload