I have a question concerning igraph integrations. I am student at the university of Ljubljana and i am currently working on my diploma thesis. The topic is about integration of C++ implementation of algorithm SICS.
I have currently isuess with linking static library in R environment to test the package. I have installed the library through the command line, and now i want to link the actual program. For linker i am using following makevars script:
CXX = g++
CXX_FLAGS = -std=c++17 -O3 -march=native -DNDEBUG
PKG_CPPFLAGS="-IC:\Sics\sics\include\igraph"
PKG_LIBS="-LC:\Sics\sics\include\igraph\lib\libigraph.a" -lm -lstdc++ -lgomp -lpthread
When i run the program i would get the following message.
* installing to library 'C:/Users/MyName/Documents/R/win-library/4.1'
* installing *source* package 'Sics' ...
** using staged installation
** libs
/mingw64/bin/g++ -std=gnu++17 -shared -s -static-libgcc -o Sics.dll tmp.def Subgraph_isomorphism.o beam.o interface.o main.o -LC:\Sics\sics\include\igraph\lib\libigraph.a -lm -lstdc++ -lgomp -lpthread -LC:/PROGRA~1/R/R-41~1.0/bin/x64 -lR
C:/RBUILD~1/4.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Subgraph_isomorphism.o:Subgraph_isomorphism.cpp:(.text+0x12b): undefined reference to `igraph_vector_init'
collect2.exe: error: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'Sics'
* removing 'C:/Users/MyName/Documents/R/win-library/4.1/Sics'
* restoring previous 'C:/Users/MyName/Documents/R/win-library/4.1/Sics'
Exited with status 1.
I would be really pleased if you could give me any advice. Actually i would be really happy if there’s anyone who would be ready to give me some help about how does actual package works. Thinks like that: how do you add your new function to the existing package et cetera.
The best way would be if i can personaly contact anyone who would be ready to help and meet him through the zoom meting.
When linking a static library, just specify the path to the library, without the -L
flag.
The -L
flag has a different purpose: the adds to the search path for libraries. Its argument must be a directory, not a library.
To learn how to add new functions to the igraph C library (not the R library, but C for now), go through the following steps in order:
In order to add a new function, programmed in C, to R/igraph, you need to first add it to C/igraph. R/igraph is currently based on an outdated C/igraph 0.8. Once we update R/igraph to use C/igraph 0.9.x, adding new functions to R will become easier.
Information about how R/igraph uses C/igraph is here: What is the best way to edit igraph C functions and call them into R? However, this might change somewhat in the future. I do not recommend that you try to work with the outdated C/igraph 0.8 anymore.
I’m afraid that this is asking for more than what we have resources for at the moment. Let us please keep all communication on this forum. This way whoever has time at this moment may respond.
2 Likes
- Thank you for your help, i understand that you have limited resources.
I think that pure linking problem is now solved, as the program compiles and there is no error squirggles in the file. However when i try to Rcpp::Source my file i will get error which seems not to be contected to compilation, looks more like a comflict.
Program i am running:
#include "include/include/igraph/igraph.h"
int Subgraph_isomorphism(
double *train_inputs_ptr,
double *train_label_ptr,
double *test_input_ptr,
int *n_observations,
int *n_features,
int *max_neighbours,
int output
){
igraph_t g1, g2;
igraph_vector_t v1, v2;
igraph_vector_init(&v1,6);
VECTOR(v1)[0] = 0;
VECTOR(v1)[1] = 1;
VECTOR(v1)[2] = 1;
output += 1;
return 0;
}
Output:
I have added the image below, thanks much for your help!
Why are you using Rcpp? Do you want to mix Rcpp and igraph code?
One problem you seem to have is using Rcpp for igraph’s C (not C++) code. I’m not sure if this is the right way to go.
Did you use
?
Iam using Rcpp::sourceCpp() to source my code, so probably you are right. I understand how does the code work beneath but i need to include this library. If i do this it is not a problem in VS code as such i expect that there should be a solution so i could link and use library in R package. If i rethink - complete R side is wrapped around this library and it is included in source files, so it would be really good if someone could propose a simple solution to this big problem of mine. How can i use Rcpp for C++ code instead of C?
I disabled rcpp but now the code will not compile explaining me that, there is no “package called Rcpp”.
I would be really appreciating a quick fix, without changing anything.
Now i have tried:
#include <Rcpp.h>
#include "include/include/igraph/igraph.h"
using namespace Rcpp;
// [[Rcpp::export]]
int Subgraph_isomorphism(
double train_inputs_ptr,
double train_label_ptr,
double test_input_ptr,
int n_observations,
int n_features,
int max_neighbours,
int output
){
igraph_t g1, g2;
igraph_vector_t v1, v2;
igraph_vector_init(&v1,6);
VECTOR(v1)[0] = 0;
VECTOR(v1)[1] = 1;
VECTOR(v1)[2] = 1;
output += 1;
return 0;
}
and underneath:
/mingw64/bin/g++ -std=gnu++17 -shared -s -static-libgcc -o sourceCpp_7.dll tmp.def Subgraph_isomorphism.o -LC:/PROGRA~1/R/R-41~1.0/bin/x64 -lR
C:/RBUILD~1/4.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Subgraph_isomorphism.o:Subgraph_isomorphism.cpp:(.text+0x17f): undefined reference to `igraph_vector_init'
C:/RBUILD~1/4.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Subgraph_isomorphism.o:Subgraph_isomorphism.cpp:(.text+0x298): undefined reference to `igraph_vector_init'
collect2.exe: error: ld returned 1 exit status
Error in Rcpp::sourceCpp("src/Subgraph_isomorphism.cpp") :
Error occurred building shared library.
I have no further idea what to do. I do not know even if i have libraries llinked correctly. If i dident make it clear enought maybe:
I have isuess linking static library in the R enviroment through the makevars file, and the problem is that i am not completely sure what to do because i have different kind of isuess every time i do something new. At first i had isuess linking library and latter i had isuess with Rcpp as someone explained the errors, any good further sugggestions would be appreciated .Thank you!!