我是g ++和Makefile的新手。我正在尝试链接这个BeBOP SMC库,它位于我的lib目录中。在lib目录下有bebop_util和sparse_matrix_converter,这两个目录都已经构建没有错误。我在sparse_matrix_converter下的bebop_util和libsparse_matrix_converter.a,libsparse_matrix_converter.so下看到了libbebop_util.a,libbebop_util.so。以下是来源:
生成文件
CC=g++
CFLAGS=-c
# CFLAGS=-c -Wall
INCLUDE_DIRS=-Ilib/bebop_util/include -Ilib/sparse_matrix_converter/include
LIB_DIRS=-Llib/bebop_util -Llib/sparse_matrix_converter
LIBS=-lbebop_util -lsparse_matrix_converter
test.out: test.o
$(CC) -o test.out $(LIB_DIRS) $(LIBS) test.o
test.o: test.cpp
$(CC) $(CFLAGS) $(INCLUDE_DIRS) test.cpp
clean:
rm -f test.o test.out
TEST.CPP
extern "C" {
#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_i
nput");
destroy_sparse_matrix(A);
return 0;
}
作为安全措施,我还设置了LD_LIBRARY_PATH:
login4% setenv | grep LD_LIBRARY_PATH
LD_LIBRARY_PATH=/share/apps/teragrid/globus-4.0.8-r1/myproxy-3.4/lib:/share/apps/teragrid/globus-4.0.8-r1/lib:/share/apps/teragrid/srb-client-3.4.1-r1/lib:/opt/apps/pgi7_2/mvapich/1.0.1/lib:/opt/apps/pgi7_2/mvapich/1.0.1/lib/shared:/opt/apps/pgi/7.2-5/linux86-64/7.2-5/libso:/opt/gsi-openssh-4.3/lib:/opt/apps/binutils-amd/070220/lib64:/share/home/01355/tomwang/cs380p_assn3/lib:/share/home/01355/tomwang/cs380p_assn3/lib/bebob_util:/share/home/01355/tomwang/cs380p_assn3/lib/sparse_matrix_converter
输出
login3% make
g++ -c -Ilib/bebop_util/include -Ilib/sparse_matrix_converter/include test.cpp
g++ -o test.out -Llib/bebop_util -Llib/sparse_matrix_converter -lbebop_util -lsparse_matrix_converter test.o
login3% ./test.out
./test.out: error while loading shared libraries: libbebop_util.so: cannot open shared object file: No such file or directory
请告知我可能提供的错误或其他信息。感谢。
汤姆
答案 0 :(得分:1)
您确定LD_LIBRARY_PATH中提到了libbebop_util.so
所在的目录吗?根据您的构建行,以下内容应该有效:
env LD_LIBRARY_PATH=./lib:${LD_LIBRARY_PATH} ./test_out
答案 1 :(得分:1)
看起来你没有链接问题。相反,问题是您构建的可执行文件对libbebop_util.so的引用无效。
尝试运行ldd test.out
以查看它在哪里寻找共享库。