在通过自制软件安装的OSX上使用igraph

时间:2017-10-21 07:16:20

标签: macos cmake homebrew igraph clion

我是C编程的新手,想要使用igraph库。

我是通过自制软件安装的。

brew install igraph

之后我从main.cpp中的igraph c教程复制第一个例子,并将include igraph更改为

#include "igraph/igraph.h"

Clion提出了igraph函数和类型。

尝试构建此错误消息:

/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build 
/Users/username/development/graph_clustring/cmake-build-debug --target 
graph_clustring -- -j 4
[ 50%] Linking CXX executable graph_clustring
Undefined symbols for architecture x86_64:
  "_igraph_destroy", referenced from:
   _main in main.cpp.o
  "_igraph_diameter", referenced from:
   _main in main.cpp.o
  "_igraph_erdos_renyi_game", referenced from:
   _main in main.cpp.o
  "_igraph_rng_default", referenced from:
   _main in main.cpp.o
  "_igraph_rng_seed", referenced from:
   _main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see 
invocation)
make[3]: *** [graph_clustring] Error 1
make[2]: *** [CMakeFiles/graph_clustring.dir/all] Error 2
make[1]: *** [CMakeFiles/graph_clustring.dir/rule] Error 2
make: *** [graph_clustring] Error 2e

我认为我应该修复我的CMake文件,并帮助CMake通过自制软件找到lib isntal。

CMake文件:

cmake_minimum_required(VERSION 3.8)
project(graph_clustring)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)

add_executable(graph_clustring ${SOURCE_FILES})

1 个答案:

答案 0 :(得分:0)

我能够通过向CMake添加target_link_libraries命令来解决该问题。看起来应该像这样

make_minimum_required(VERSION 3.8) 
enter code here

project(graph_clustring)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)

add_executable(graph_clustring ${SOURCE_FILES})
target_link_libraries(graph_clustring, igraph.a)