Example code, but essentially what the C library that I am wrapping returns:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 128
struct C {
int a;
double b;
char c[BUFSIZE];
};
struct C returns_struct() {
struct C retval;
retval.a = 1;
retval.b = 2.2;
strncpy(retval.c, "hi there", BUFSIZE);
return retval;
}
int main(int argc, char *argv) {
struct C thing = returns_struct();
printf("thing.a = %d\n", thing.a);
printf("thing.b = %f\n", thing.b);
printf("thing.c = %s\n", thing.c);
return EXIT_SUCCESS;
}
Although it has a main function (for testing), I compile it with gcc -fPIC -shared stuff.c -o libstuff.so
. In Julia I try to wrap it with:
struct C
a::Cint
b::Cdouble
c::Cstring # <-- the problem appears to be this
end
stuff = @ccall "./libstuff.so".returns_struct()::C
If I remove the string from the struct, things seem to work well … any idea what I am missing?