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

2012-05-09 Thread Zalan Szakolci
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 > treeMap;
  multimap >::iterator it_tM;
  int l =LENGTH(membership);
  //Rprintf("beleptunk");
  int p = 0;
  map 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;jsecond.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 > bootstraps = vector
>(boots,vector(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 significantVec = vector(Nnode);
  findConfCore(treeMap,bootstraps,significantVec,confnew,R);
  vector > 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::iterator iter = degrees.begin();
  for(multimap >::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 >::iterator it = mergers.begin(); it !=
mergers.end(); it++)
outfile << it->first+1 << ">" << it->second+1 << endl;
  outfile << "*Nodes " << Nnode << endl;
  k = 1;
  for(multimap >::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,greater >::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:

* installing *source* package ‘DyA’ ...
** libs
** arch -
g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3 -funroll-loops
-pipe -c conf-infomap.cpp -o conf-infomap.o
g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3 -funroll-loops
-pipe -c GreedyBase.cpp -o GreedyBase.o
g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3 -funroll-loops
-pipe -c Greedy.cpp -o Greedy.o
g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3 -funroll-loops
-pipe -c Node.cc -o Node.o
g++ conf-infomap.o GreedyBase.o Greedy.o Node.o mersenne.cpp stoc1.cpp
userintf.cpp -lm -o conf-infomap
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/crt1.o: In
function `_start':
(.text+0x20): undefined reference to `main'
conf-infomap.o: In function `findConfCoreWrapper':
conf-infomap.cpp:(.text+0xfd47): undefined reference to `LENGTH'
conf-infomap.cpp:(.text+0xf

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

2012-05-09 Thread Dirk Eddelbuettel

On 9 May 2012 at 00:35, Zalan Szakolci wrote:
| 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:

[...]
 
| Now when I run R CMD check, in file 00install.out I am getting the
| following linking errors:
| 
| * installing *source* package �DyA� ...
| ** libs
| ** arch -
| g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3 -funroll-loops
| -pipe -c conf-infomap.cpp -o conf-infomap.o
| g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3 -funroll-loops
| -pipe -c GreedyBase.cpp -o GreedyBase.o
| g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3 -funroll-loops
| -pipe -c Greedy.cpp -o Greedy.o
| g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3 -funroll-loops
| -pipe -c Node.cc -o Node.o
| g++ conf-infomap.o GreedyBase.o Greedy.o Node.o mersenne.cpp stoc1.cpp
| userintf.cpp -lm -o conf-infomap

What is your src/Makevars file?  

This looks very wrong as you are obviously not linking against R itself.

I would recommend a good long look at both the 'Writing R Extensions' manual
as well as some of the existing CRAN packages uses C++ sources.

You can (and should) also try

R CMD COMPILE ...

R CMD SHLIB ...

R CMD INSTALL ...

etc as 'R CMD check' is really only the final bit.

Dirk

-- 
R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
See agenda, registration details and more at http://www.RinFinance.com

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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

2012-05-09 Thread Zalan Szakolci
Hi,

Thanks for the suggestions. I've forgotten to  point out, that

R CMD COMPILE and
R CMD SHLIB

works fine, the dll file was indeed created. I get these undefined
references when I'm trying to run R CMD INSTALL.

I've read through the "Writing R extensions" and the archives, but I really
don't know what am I doing wrong.

More suprising, when I run the same package in windows with R CMD check,
the dll for src-i386 was created, but not the 64 -bit, i'm getting: sorry,
64 bit compilation not supported (or someting similar)

If anyone have an idea, comments welcome.

Thanks,

Zalan

On 9 May 2012 14:11, Dirk Eddelbuettel  wrote:

>
> On 9 May 2012 at 00:35, Zalan Szakolci wrote:
> | 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:
>
> [...]
>
> | Now when I run R CMD check, in file 00install.out I am getting the
> | following linking errors:
> |
> | * installing *source* package ‘DyA’ ...
> | ** libs
> | ** arch -
> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
> -funroll-loops
> | -pipe -c conf-infomap.cpp -o conf-infomap.o
> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
> -funroll-loops
> | -pipe -c GreedyBase.cpp -o GreedyBase.o
> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
> -funroll-loops
> | -pipe -c Greedy.cpp -o Greedy.o
> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
> -funroll-loops
> | -pipe -c Node.cc -o Node.o
> | g++ conf-infomap.o GreedyBase.o Greedy.o Node.o mersenne.cpp stoc1.cpp
> | userintf.cpp -lm -o conf-infomap
>
> What is your src/Makevars file?
>
> This looks very wrong as you are obviously not linking against R itself.
>
> I would recommend a good long look at both the 'Writing R Extensions'
> manual
> as well as some of the existing CRAN packages uses C++ sources.
>
> You can (and should) also try
>
>R CMD COMPILE ...
>
>R CMD SHLIB ...
>
>R CMD INSTALL ...
>
> etc as 'R CMD check' is really only the final bit.
>
> Dirk
>
> --
> R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
> See agenda, registration details and more at http://www.RinFinance.com
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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

2012-05-09 Thread Simon Urbanek

On May 9, 2012, at 9:10 AM, Zalan Szakolci wrote:

> Hi,
> 
> Thanks for the suggestions. I've forgotten to  point out, that
> 
> R CMD COMPILE and
> R CMD SHLIB
> 
> works fine, the dll file was indeed created. I get these undefined
> references when I'm trying to run R CMD INSTALL.
> 

... which means you are probably doing something silly in Makevars or Makefile 
(ideally, you should not have either) -- and that's why Dirk was asking you.


> I've read through the "Writing R extensions" and the archives, but I really
> don't know what am I doing wrong.
> 
> More suprising, when I run the same package in windows with R CMD check,
> the dll for src-i386 was created, but not the 64 -bit, i'm getting: sorry,
> 64 bit compilation not supported (or someting similar)
> 

You have the wrong toolchain on your PATH (see recent question here).

Cheers,
Simon



> If anyone have an idea, comments welcome.
> 
> Thanks,
> 
> Zalan
> 
> On 9 May 2012 14:11, Dirk Eddelbuettel  wrote:
> 
>> 
>> On 9 May 2012 at 00:35, Zalan Szakolci wrote:
>> | 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:
>> 
>> [...]
>> 
>> | Now when I run R CMD check, in file 00install.out I am getting the
>> | following linking errors:
>> |
>> | * installing *source* package ŒDyA‚ ...
>> | ** libs
>> | ** arch -
>> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
>> -funroll-loops
>> | -pipe -c conf-infomap.cpp -o conf-infomap.o
>> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
>> -funroll-loops
>> | -pipe -c GreedyBase.cpp -o GreedyBase.o
>> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
>> -funroll-loops
>> | -pipe -c Greedy.cpp -o Greedy.o
>> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
>> -funroll-loops
>> | -pipe -c Node.cc -o Node.o
>> | g++ conf-infomap.o GreedyBase.o Greedy.o Node.o mersenne.cpp stoc1.cpp
>> | userintf.cpp -lm -o conf-infomap
>> 
>> What is your src/Makevars file?
>> 
>> This looks very wrong as you are obviously not linking against R itself.
>> 
>> I would recommend a good long look at both the 'Writing R Extensions'
>> manual
>> as well as some of the existing CRAN packages uses C++ sources.
>> 
>> You can (and should) also try
>> 
>>   R CMD COMPILE ...
>> 
>>   R CMD SHLIB ...
>> 
>>   R CMD INSTALL ...
>> 
>> etc as 'R CMD check' is really only the final bit.
>> 
>> Dirk
>> 
>> --
>> R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
>> See agenda, registration details and more at http://www.RinFinance.com
>> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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

2012-05-09 Thread Zalan Szakolci
Yes, you were right guys, I've deleted my Makefile from the directory, and
everything goes fine.

Many thanks.

On 9 May 2012 15:16, Simon Urbanek  wrote:

>
> On May 9, 2012, at 9:10 AM, Zalan Szakolci wrote:
>
> > Hi,
> >
> > Thanks for the suggestions. I've forgotten to  point out, that
> >
> > R CMD COMPILE and
> > R CMD SHLIB
> >
> > works fine, the dll file was indeed created. I get these undefined
> > references when I'm trying to run R CMD INSTALL.
> >
>
> ... which means you are probably doing something silly in Makevars or
> Makefile (ideally, you should not have either) -- and that's why Dirk was
> asking you.
>
>
> > I've read through the "Writing R extensions" and the archives, but I
> really
> > don't know what am I doing wrong.
> >
> > More suprising, when I run the same package in windows with R CMD check,
> > the dll for src-i386 was created, but not the 64 -bit, i'm getting:
> sorry,
> > 64 bit compilation not supported (or someting similar)
> >
>
> You have the wrong toolchain on your PATH (see recent question here).
>
> Cheers,
> Simon
>
>
>
> > If anyone have an idea, comments welcome.
> >
> > Thanks,
> >
> > Zalan
> >
> > On 9 May 2012 14:11, Dirk Eddelbuettel  wrote:
> >
> >>
> >> On 9 May 2012 at 00:35, Zalan Szakolci wrote:
> >> | 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:
> >>
> >> [...]
> >>
> >> | Now when I run R CMD check, in file 00install.out I am getting the
> >> | following linking errors:
> >> |
> >> | * installing *source* package ŒDyA‚ ...
> >> | ** libs
> >> | ** arch -
> >> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
> >> -funroll-loops
> >> | -pipe -c conf-infomap.cpp -o conf-infomap.o
> >> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
> >> -funroll-loops
> >> | -pipe -c GreedyBase.cpp -o GreedyBase.o
> >> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
> >> -funroll-loops
> >> | -pipe -c Greedy.cpp -o Greedy.o
> >> | g++ -I/usr/share/R/include -DNDEBUG  -fpic  -I -Wall -O3
> >> -funroll-loops
> >> | -pipe -c Node.cc -o Node.o
> >> | g++ conf-infomap.o GreedyBase.o Greedy.o Node.o mersenne.cpp stoc1.cpp
> >> | userintf.cpp -lm -o conf-infomap
> >>
> >> What is your src/Makevars file?
> >>
> >> This looks very wrong as you are obviously not linking against R itself.
> >>
> >> I would recommend a good long look at both the 'Writing R Extensions'
> >> manual
> >> as well as some of the existing CRAN packages uses C++ sources.
> >>
> >> You can (and should) also try
> >>
> >>   R CMD COMPILE ...
> >>
> >>   R CMD SHLIB ...
> >>
> >>   R CMD INSTALL ...
> >>
> >> etc as 'R CMD check' is really only the final bit.
> >>
> >> Dirk
> >>
> >> --
> >> R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
> >> See agenda, registration details and more at http://www.RinFinance.com
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] R Installation Manual - ATLAS BLAS guidance that is not in the current version

2012-05-09 Thread Adler, Avraham
Good afternoon.

I am trying to compile a version of Rblas.dll based on ATLAS for the Corei7. I 
had remembered that there was mention of which file to adjust and that "xerbla" 
needed to be removed from one of the outputs from the last time I tried a few 
years ago. The most recent version of the R Installation manual does not say 
anything about this. An older version (2.10 I believe) has the following text:

  Optionally, you can install a version of ATLAS
  (`math-atlas.sourceforge.net'
  (http://math-atlas.sourceforge.net/)) tuned to your system for
  fast linear algebra routines. Pre-built `Rblas.dll' for various
  Pentium and AthlonXP chips are available in the
  `windows/contrib/ATLAS' area on CRAN.  If you are building R from
  source, there are macros `USE_ATLAS' and `ATLAS_PATH' in the file
  `MkRules'.  Set `USE_ATLAS = YES' and `ATLAS_PATH' to where the
  ATLAS libraries are located.  You will need to make the libraries
  yourself(1): none of the binaries we have seen are compiled for
  the correct compiler.  Since R has its own `xerbla' it is best to
  delete that in ATLAS by
 
   ar d /path/to/libf77blas.a xerbla.o

Would it be possible to restore the above information to the next version of 
the manual for future reference, please?
 
Thank you,

Avraham Adler
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel