[Rd] R CMD check linking errors, when interfacing c++

From: Zalan Szakolci <zalan.szakolci_at_gmail.com>
Date: Wed, 09 May 2012 00:35:26 +0200


Hi there,

I am trying to interface c++ code in R and make a package. With R CMD SHLIB the dll was created, but when I try R CMD check, I am getting 'undefined reference to..' linkage error messages.

The relevant c++ source from conf-infomap.cpp:

#include "conf-infomap.h"
#include "R.h" // R functions
#include "Rinternals.h"
#include "Rmath.h" // R math
#include "Rdefines.h"

using namespace std;
using std::cout;
using std::cin;
using std::endl;

[...]

extern "C" {
void RosvallDynamicSkeleton(int *seed,char** file, int *attempts, int *resamples, double *conf) {

int ret = confInfomap(seed[0],file,attempts[0],resamples[0],conf[0]);

if(ret == 0)
Rprintf("cluster map has been written to %s\n", file[0]); R_FlushConsole();
R_ProcessEvents();
return; // Return Nothing.
}
}

extern "C" {
void findConfCoreWrapper(SEXP gdiag, SEXP bootClusters, SEXP membership, SEXP conf) {

multimap<double,treeNode,greater<double> > treeMap;   multimap<double,treeNode,greater<double> >::iterator it_tM;   int l =LENGTH(membership);
  //Rprintf("beleptunk");
  int p = 0;
  map<int,int> degrees;
  for(int i=0;i < l;i++){
    SEXP members = VECTOR_ELT(membership,i);
//Rprintf("%d\n",Nmembers);

SEXP membersSXP = VECTOR_ELT(members,0); SEXP sizesxp = VECTOR_ELT(members,1);
double* sizevc = REAL(sizesxp);
 double size = sizevc[0];

    int Nmembers = LENGTH(membersSXP);
    treeNode tmp_tN;
//Rprintf("the size of the module is: %f\n",size);

    it_tM = treeMap.insert(make_pair(size,tmp_tN));

//Rprintf("%d\n",Nmembers);

for(int j=0;j<Nmembers;j++)
 {
 SEXP node = VECTOR_ELT(membersSXP,j);
SEXP nodesizesxp = VECTOR_ELT(node,0);
 SEXP nodeidsxp = VECTOR_ELT(node,1);
SEXP nodenamesxp = VECTOR_ELT(node,2);
int degree = INTEGER(VECTOR_ELT(node,3))[0];  int nodeid = INTEGER(nodeidsxp)[0];
degrees.insert(make_pair(nodeid,degree)); string nodename = string(CHAR(STRING_ELT(nodenamesxp,0)));  double nodesize = REAL(nodesizesxp)[0];
//Rprintf("nodename:%s",nodename.c_str());

it_tM->second.members.insert(make_pair(nodesize,make_pair(nodeid,nodename)));
//Rprintf("the node is: %s\n",nodename.c_str());
 //Rprintf("the size of the node is: %f\n",nodesize);
//Rprintf("the id of the node is: %d\n",nodeid);

     }
p = i;
  }
//return;

  int boots = LENGTH(bootClusters);

  SEXP memberssxp = VECTOR_ELT(bootClusters,0);   int ltemp = LENGTH(memberssxp);
   vector<vector<int > > bootstraps = vector<vector<int > >(boots,vector<int>(ltemp));
  for(int i =0 ; i< boots;++i)
  {
SEXP memberssxp = VECTOR_ELT(bootClusters,i); int l = LENGTH(memberssxp);

int* members = INTEGER(memberssxp);

//bootstraps[i] = new int[l];

for(int j = 0; j<l;++j)
 {
bootstraps[i][j] = members[j];
//Rprintf("id: %d\n",members[j]);

}
  }
  double confnew = REAL(conf)[0];
  int Nnode = LENGTH(VECTOR_ELT(bootClusters,0));   MTRand *R = new MTRand(long(443)); // Set random seed     vector<bool> significantVec = vector<bool>(Nnode);   findConfCore(treeMap,bootstraps,significantVec,confnew,R);   vector<pair<int,int> > mergers;
  findConfModules(treeMap,bootstraps,significantVec,mergers,confnew);   SEXP name = VECTOR_ELT(gdiag,0);
  SEXP links = VECTOR_ELT(gdiag,2);
  Rprintf("teve");
  int totalDegree = INTEGER(VECTOR_ELT(gdiag,4))[0]*2;    string networkName = string(CHAR(STRING_ELT(name,0)));    ofstream outfile;
  ostringstream oss;
  int nLinks = INTEGER(links)[0];
   oss.str("");
  oss << networkName << ".smap";
  outfile.open(oss.str().c_str());

  outfile << "# modules: " << l << endl;
  outfile << "# modulelinks: " << "na" << endl;
  outfile << "# nodes: " << Nnode << endl;
  outfile << "# links: " << nLinks << endl;
  outfile << "# codelength: " << "na" << endl;
  outfile << "*Undirected" << endl;
  outfile << "*Modules " << l << endl;

  int k = 0;
  map<int,int>::iterator iter = degrees.begin();   for(multimap<double,treeNode,greater<double> >::iterator it = treeMap.begin(); it != treeMap.end(); it++){

    outfile << k+1 << " \"" << it->second.members.begin()->second.second << ",...\" " << it->first << " " << (double)iter->second /(double)totalDegree<< endl;

    p++;
k++;
  }
  outfile << "*Insignificants " << mergers.size() << endl;   for(vector<pair<int,int> >::iterator it = mergers.begin(); it != mergers.end(); it++)

    outfile << it->first+1 << ">" << it->second+1 << endl;   outfile << "*Nodes " << Nnode << endl;   k = 1;
  for(multimap<double,treeNode,greater<double> >::iterator it = treeMap.begin(); it != treeMap.end(); it++){

    string s;
    s.append(to_string(k));
    printSignificantTree(s,it,&outfile,significantVec);     k++;
  }
  outfile << "*Links " << nLinks << endl;   /*
  for(multimap<double,pair<int,int>,greater<double> >::iterator it = sortedLinks.begin();it != sortedLinks.end();it++)

    outfile << it->second.first << " " << it->second.second << " " << 1.0*it->first << endl;
  */
  outfile.close();

  delete R;
  Rprintf("done");
R_FlushConsole();
R_ProcessEvents();
return; // Return Nothing.
}
}

Now when I run R CMD check, in file 00install.out I am getting the following linking errors:

Can anyone help, what am I doing wrong?

I am using R 2.15.0 on ubuntu 11.10

Many thanks,

Zalan

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 09 May 2012 - 07:30:57 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 May 2012 - 13:21:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive