Mac OS X 上的自定义 igraph igraph_get_shortest_paths_dijkstra 函数

custom igraph igraph_get_shortest_paths_dijkstra function on Mac OS X

为了制作函数的自定义版本 igraph_get_shortest_paths_dijkstra 我从文件 structural_properties.c 复制了它。我已将其抽出并放入我的本地 .c 文件中,对我的 Makefile 的修改之一如下,但出现错误:

gcc  -I/usr/local/include/igraph -I/Users/saguinag/ToolSet/igraph-0.7.1/src -I/Users/saguinag/ToolSet/igraph-0.7.1   -o mycc comp_catpath.o -L/usr/local/lib -ligraph
Undefined symbols for architecture x86_64:
  "_saguinag_get_shortest_path", referenced from:
  _main in comp_catpath.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: *** [mycc] Error 1

我的 Makefile 开头为:

## Author: Sal Aguinaga (c) 2015
CC=gcc
INCLUDES=-I/usr/local/include/igraph \
    -I/Users/saguinag/ToolSet/igraph-0.7.1/src \
    -I/Users/saguinag/ToolSet/igraph-0.7.1
LFLAGS=-L/usr/local/lib
LIBS=-ligraph
OUT=comp_catpath
OBJS=comp_catpath.o 

# define the C source files
SRCS = comp_catpath.c

OBJS = $(SRCS:.c=.o)

# define the executable file 
MAIN = mycc


.PHONY: depend clean

all:    $(MAIN)
    @echo  Simple compiler named mycc has been compiled

$(MAIN): $(OBJS) 
    $(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)

# this is a suffix replacement rule for building .o's from .c's
# # it uses automatic variables $<: the name of the prerequisite of
# # the rule(a .c file) and $@: the name of the target of the rule (a .o file) 
# # (see the gnu make manual section about automatic variables)
.c.o:
    $(CC) $(CFLAGS) $(INCLUDES) -c $<  -o $@
#
clean:
    $(RM) *.o *~ $(MAIN)
#
depend: $(SRCS)
    makedepend $(INCLUDES) $^
#
# DO NOT DELETE THIS LINE -- make depend needs it

我需要指定架构吗?我的机器是 MacBook Pro。当我输入 make -v 时,我得到它是 GNU Make 3.81,最后一行写着 "This program built for i386-apple-darwin11.3.0" 有更好的方法吗?

您正在编译和链接单个源文件,comp_catpath.c。在此文件中,您定义了函数 main,并在 main 中尝试调用函数 saguinag_get_shortest_path。但是,您还没有在 comp_catpath.c 中定义函数 saguinag_get_shortest_path,它也没有在 igraph 库或 C 标准库中定义。

如果您已经将 saguinag_get_shortest_path 的定义放入另一个 .c 文件中,则需要在 Makefile 中的 SRCS 定义中包含该文件的名称。如果您没有在任何地方定义 saguinag_get_shortest_path,则需要在 comp_catpath.c 或新文件(然后添加到 SRCS)中为其编写定义。