【问题标题】:Using IGRAPH object oriented programming使用 IGRAPH 面向对象编程
【发布时间】:2015-03-20 15:00:46
【问题描述】:

我的库 igraph 完美地适用于 C 中的代码。

但是,当我尝试用 C++ 编译代码时,我遇到了未定义的引用问题。有些功能有效,有些则无效。根据我的研究,我相信缺少的是包含“ igraph.hpp”。虽然,我不知道如何安装这些文件。

我正在尝试编译以下示例程序:

#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;

}

我正在使用以下命令编译程序:

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

但是,会发生此错误:

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

谁能帮帮我?

【问题讨论】:

  • 库是C,因此你需要做一个extern "C"块并在其中插入#include

标签: c++ c igraph


【解决方案1】:

就这样做

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

c++ 编译器会破坏函数名称,因此在库中搜索该函数时将找不到该函数,如果您这样做,则在 igraph.h 中声明的每个函数都将具有 c 链接以防止名称破坏。

【讨论】:

    猜你喜欢
    • 2010-09-18
    • 1970-01-01
    • 2016-07-29
    • 2011-07-09
    • 1970-01-01
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多