包含共享库时出错

发布于 2024-08-22 11:54:44 字数 2084 浏览 9 评论 0原文

我是 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。下面是源代码:

Makefile

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

请建议我提供哪些可能是错误的或其他信息。谢谢。

汤姆

I am new to g++ and Makefile. I am trying to link this BeBOP SMC library, which is in my lib directory. Under the lib directory are bebop_util and sparse_matrix_converter, both of which have already been built without errors. I see libbebop_util.a, libbebop_util.so under bebop_util and libsparse_matrix_converter.a, libsparse_matrix_converter.so under sparse_matrix_converter. Below is the source:

Makefile

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;
}

As a safeguard, I also have the LD_LIBRARY_PATH set:

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

Output

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

Please suggest what may be wrong or additional info for me to provide. Thanks.

Tom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弃爱 2024-08-29 11:54:44

您确定 LD_LIBRARY_PATH 中提到了 libbebop_util.so 所在的目录吗?根据您的构建线,以下内容应该有效:

env LD_LIBRARY_PATH=./lib:${LD_LIBRARY_PATH} ./test_out

Are you sure the directory that libbebop_util.so is in is mentioned in your LD_LIBRARY_PATH? Based on your build line, the following should work:

env LD_LIBRARY_PATH=./lib:${LD_LIBRARY_PATH} ./test_out
烟柳画桥 2024-08-29 11:54:44

看来您的链接没有问题。相反,问题是您构建的可执行文件对 libbebop_util.so 的引用无效。

尝试运行 ldd test.out 来查看它在哪里寻找共享库。

It looks like you're not having problems with linking. Instead, the problem is that your built executable has a reference to libbebop_util.so that is invalid.

Try running ldd test.out to see where it's looking for the shared libraries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文