It seems not possible to call Julia from a C-main program under Windows 7. 

I am aware of issues #11419 
<https://github.com/JuliaLang/julia/issues/11419>, #15194 
<https://github.com/JuliaLang/julia/issues/15194>. I have the following 
C-Program testc.c to perform a minimal test. testc.c is stored under <julia 
directory>\bin:


#include "julia.h"
int main(int argc, char *argv[])
{
    jl_init(NULL);  
    jl_eval_string("display(2.0)");
    jl_atexit_hook(0);
    return 0;
}


All the following is performed under Windows 7 with MSYS2 and MINGW as 
adviced in https://github.com/JuliaLang/julia/blob/master/README.windows.md.
In all experiments, I start with a fresh MSYS2 shell and execute the 
following commands:


JULIA_DIR=<location of JULIA directory>
JULIA_HOME=$JULIA_DIR/bin
export PATH=$JULIA_DIR/bin:$PATH
export PATH=<location of MINGW installed by 
JULIA>/usr/x86_64-w64-mingw32/sys-root/mingw/bin:$PATH
cd $JULIA_DIR/bin


Executing the following command with a standard Julia 0.4.5 Windows 64 bit 
installation


gcc -I$JULIA_DIR/include/julia -L$JULIA_DIR/bin -L$JULIA_DIR/lib -ljulia 
-lopenlibm testc.c -o testc


is successful. Executing the generated testc.exe gives the following error:


Please submit a bug report with steps to reproduce this fault, and any error 
messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x0 -- unknown function (ip: 
0000000000000000)
unknown function (ip: 0000000000000000)


Running Julia 0.5.0-dev:


Julia Version 0.5.0-dev+4536
Commit 44d778a (2016-06-05 01:30 UTC)
Platform Info:
  System: NT (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-4800MQ CPU @
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)


again with


gcc -I$JULIA_DIR/include/julia -L$JULIA_DIR/bin -L$JULIA_DIR/lib -ljulia 
-lopenlibm testc.c -o testc


is successful. Executing the generated testc.exe gives the following error:


LLVM ERROR: Program used external function 'rint' which could not be resolved!


>From #11419 <https://github.com/JuliaLang/julia/issues/11419>, libopenlibm 
should be statically linked (especially since rint is a symbol in 
libopenlibm). Trying to generate a libopenlibm.dll.a stub library for this:


dlltool -z libopenlibm.dll.def --export-all-symbol libopenlibm.dll
dlltool -d libopenlibm.dll.def -l libopenlibm.dll.a
gcc -I$JULIA_DIR/include/julia -L$JULIA_DIR/bin -L$JULIA_DIR/lib -ljulia 
-lopenlibm testc.c -o testc


gives error messages due to multiple defintiions of


atexit, _encode_pointer, __mingw_init_ehandler, _gnu_exception_handler


Removed these symbols in libopenlibm.dll.def and running again:


dlltool -d libopenlibm.dll.def -l libopenlibm.dll.a
gcc -I$JULIA_DIR/include/julia -L$JULIA_DIR/bin -L$JULIA_DIR/lib -ljulia 
-lopenlibm testc.c -o testc


This is successful. Running the generated testc.exe gives the following 
error:


testc.exe: error while loading shared libraries:
(null): cannot open shared object file: No such file or directory
 

Either I make a mistake or Julia has a bug and it is currently not possible 
to call Julia (standard Windows distribution) from a C-program. Advice is 
appreciated

Reply via email to