gcore is implemented in C and the source is available, so it's obviously possible to replicate what it does. However, looking at the source reveals that it makes use of the semi-private libproc library, whose coredump generating code is fairly convoluted.
It seems the best option to simply invoke gcore using system(3) or some of its variants:
int gcore(pid_t pid)
{
char *cmd[256];
snprintf(cmd, sizeof cmd, "gcore %ld", (long) pid);
// returns 0 on success, -1 on system failure (errno set), or >0 on
// gcore failure (in which case use the W* macros defined in
// <sys/wait.h> to extract additional information from value).
return system(cmd);
}
(Link to <sys/wait.h> docs.)