Hi,
I’ve been trying to run this code that I obtained from juliaacademy.com but I have the following error computing c_sum(a) :
ERROR: could not load library "C:\Users\myusername\AppData\Local\Temp\jl_2ZlYe4PqTE"
� �☺
and yes, there’s always some random characters like 0˘☺or Ђ�☺ at the end. I don’t understand…
a = rand(10^7)
using Libdl
C_code = """
#include <stddef.h>
double c_sum(size_t n, double *X) {
double s = 0.0;
for (size_t i = 0; i < n; ++i) {
s += X[i];
}
return s;
}
"""
const Clib = tempname() # make a temporary file
# compile to a shared library by piping C_code to gcc
open(`gcc -fPIC -O3 -msse3 -xc -shared -o $(Clib * "." * Libdl.dlext) -`, "w") do f
print(f, C_code)
end
# define a Julia function that calls the C function:
c_sum(X::Array{Float64}) = ccall(("c_sum", Clib), Float64, (Csize_t, Ptr{Float64}), length(X), X)
c_sum(a)