On Tue, Feb 2, 2016 at 11:29 PM, Chris Rackauckas <[email protected]> wrote:
> Hey, sorry if this is a really noob question, but how does one use ccall on
> your own C function? Since the binding to the Monte Carlo VEGAS integration
> libraries in GSL.jl currently need work (if anyone wants to fix that up /
> guide me on how to fix it up, I'll give you 10 cookies!), I was looking to
> implement C code to call the GSL functions directly. Specifically, I am
> first trying to get this example to work. I saved it into
> monteCarloExample.c and then can compile it as
>
> gcc -I/usr/include/gsl -lgsl -lgslcblas -lm -fpic monteCarloExample.c -o
> monteCarloExample.o
>
>
> this compiles, runs, and gives the right result. However, when I try
>
> ccall((:main,"/path/to/monteCarloExample.o"),Int32,())
>
>
> I get an error
> error compiling anonymous: could not load library
> "path/to/monteCarloExample.o"
>
> If I add the -shared flag, it segfaults. Thanks in advance.

You need to compile it to a library and not a program or a object file
and it's not a good idea to name your entry function main.

It's expected that it doesn't work without the -shared flag. you can
run it in gdb to figure out where it segfaults.

Reply via email to