C代码编译之后,无法加载到Julia


#1
// mean.c中代码如下:
double vectorMean(int *arr, int n)
{
    int i, sum=0;
    double mean;
    for (i=0; i<n; i=i+1)
        sum = sum + arr[i];
    mean = sum / (double)n;
    return mean;
}

之后采用gcc编译:gcc -Wall -shared -fPIC mean.c -o mean.so

相同路径,打开Julia:

using Libdl
l = Libdl.dlopen("mean")
# ERROR: could not load library "mean"
# mean.so: cannot open shared object file: No such file or directory

l = Libdl.dlopen("mean.so")
ERROR: could not load library "mean.so"
mean.so: cannot open shared object file: No such file or directory
# Stacktrace:
# [1] #dlopen#3(::Bool, ::typeof(dlopen), ::String, ::UInt32) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/Libdl/src/Libdl.jl:109
# [2] dlopen at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/Libdl/src/Libdl.jl:109 [inlined] (repeats 2 times)
# [3] top-level scope at REPL[7]:1

versioninfo()
Julia Version 1.2.0
Commit c6da87ff4b (2019-08-20 00:03 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel® Xeon® CPU E5-4610 v4 @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, broadwell)


#2

看上去还是路径的问题。
julia 打开后 pwd() 看一下路径,或者写完整路径


#3

找到原因了,路径需要写成这样:./mean.so