在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有谁可以帮我?
发布于 2015-01-21 22:50:44
就这么做
extern "C" {
#include <igraph.h>
}c++编译器会损坏函数名,因此在搜索库以查找该函数时将找不到它,如果这样做,那么在igraph.h中声明的每个函数都将具有c链接,以防止名称损坏。
https://stackoverflow.com/questions/28078282
复制相似问题