【发布时间】:2010-02-21 05:15:05
【问题描述】:
我是 g++ 和 Makefile 的新手。我正在尝试链接这个 BeBOP SMC 库,它位于我的 lib 目录中。 lib 目录下是 bebop_util 和 sparse_matrix_converter,这两个都是已经构建好的,没有错误。我在 bebop_util 下看到 libbebop_util.a、libbebop_util.so,在 sparse_matrix_converter 下看到 libsparse_matrix_converter.a、libsparse_matrix_converter.so。以下是出处:
生成文件
CC=g++
CFLAGS=-c -Wall
test.out: test.o
$(CC) -o test.out -Ilib/sparse_matrix_converter/include -Llib/bebop_util \
-Llib/sparse_matrix_converter -lbebop_util -lsparse_matrix_converter test.o
test.o: test.cpp
$(CC) $(CFLAGS) -Ilib/sparse_matrix_converter/include test.cpp
clean:
rm -f test.o test.out
test.cpp
#include <bebop/smc/sparse_matrix.h>
#include <bebop/smc/sparse_matrix_ops.h>
int main(int argc, const char* argv[])
{
struct sparse_matrix_t* A = load_sparse_matrix (MATRIX_MARKET, "sample_input");
destroy_sparse_matrix(A);
return 0;
}
输出:
login3% make
g++ -c -Wall -Ilib/sparse_matrix_converter/include test.cpp
g++ -o test.out -Ilib/sparse_matrix_converter/include -Llib/bebop_util -Llib/sparse_matrix_converter -lbebop_util -lsparse_matrix_converter test.o
test.o: In function `main':
test.cpp:(.text+0x1a): undefined reference to `load_sparse_matrix(sparse_matrix_file_format_t, char const*)'
test.cpp:(.text+0x27): undefined reference to `destroy_sparse_matrix(sparse_matrix_t*)'
collect2: ld returned 1 exit status
make: *** [test.out] Error 1
请注意,test.cpp 依赖于 sparse_matrix_converter,而后者又依赖于 bebop_util。你能告诉我我可能犯了什么错误吗?谢谢。
汤姆
【问题讨论】:
-
您正在链接 -lbebop_util -lsparse_matrix_converter,这两个名称看起来都不像是主库。你确定你链接了所有东西吗?
-
感谢您的评论。我想我已经与一切联系在一起了。 sparse_matrix_converter 是主库。该库称为 BeBOP SMC。 SMC代表稀疏矩阵转换器。