Hello Forum, I'm calling C function from R.It is a small sample trial program. The C function will accept a string and a integer and print them. It is giving error segmentation fault. Below are the C function, Wrapper code ,R code and R output. Please help me in this issue Thank you in advance
Error: *** caught segfault *** address 0x68, cause 'memory not mapped' Traceback: 1: .C("checkstr_R_wrapper", n = as.character(n), m = as.integer(m), NAOK = TRUE, DUP = TRUE, result = integer(1)) 2: checkstr("hi", 2) Possible actions: 1: abort (with core dump, if enabled) 2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace Selection: 1 aborting ... Segmentation fault C FUNCTION (Name : checkstr.c) #include<stdio.h> #include<string.h> int n_char(char n[10],int m) { int result; result = 3; result = strlen(n); printf("the string is %s\n",n); printf("the silly number is %d\n",m); return result; } WRAPPER CODE (wrapcheckstr.c) #include <stdio.h> #include<string.h> int n_char(char,int); void checkstr_R_wrapper(char **n,int *m, int *result) { *result = n_char(**n,*m); } [prod...@venus myrpackages]$ R CODE(checkstr.R) source('checkstr.R') checkstr <- function(n,m) { if (!is.loaded(symbol.C('checkstr_R_wrapper'))) { dyn.load('checkstr.so') } returned_data = .C('checkstr_R_wrapper', n=as.character(n),m=as.integer(m), result=integer(1)) return(returned_data$result) } Thanks and Regards Naresh P Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.