Rodrigo Francisquini
Rodrigo Francisquini

Reputation: 73

Using IGRAPH object oriented programming

I have the library igraph perfectly working for codes in C.

However, when I try to compile a code in C ++, I have undefined reference problems. Some functions work, and some doesn't. I believe that what is missing is to include " igraph.hpp", based on my research. Although, I don't know how to install these files.

I'm trying compile the following example program:

#include <iostream>
#include <igraph.h>

using namespace std;

int main() {

  igraph_t g;
  FILE *ifile;
  int i;
  igraph_sparsemat_t temp;

  ifile=fopen("karate.gml", "r");
  if (ifile==0) printf("erro");

  igraph_read_graph_gml(&g, ifile);
  fclose(ifile);

  i=igraph_get_sparsemat(&g, &temp);

  return 0;

}

I'm compiling the program using the command:

g++ teste.cc -I/usr/local/include/igraph -L/usr/local/lib -ligraph -o teste

But, this error occurs:

teste.cc:(.text+0x77): referência indefinida para `igraph_get_sparsemat(igraph_s const*, igraph_sparsemat_t*)'
collect2: error: ld returned 1 exit status

Can anyone help me?

Upvotes: 3

Views: 210

Answers (1)

Iharob Al Asimi
Iharob Al Asimi

Reputation: 53006

Just do this

extern "C" {
   #include <igraph.h>
}

c++ compiler mangles function names so when searching the library for that function it will not be found, if you do this, then every function declared in igraph.h will have c linkage preventing name mangling.

Upvotes: 4

Related Questions