共享对象创建:使用Make悬挂的符号链接

发布于 2025-02-13 05:54:06 字数 1140 浏览 0 评论 0原文

我正在尝试使用GCCmake创建共享库。我在makefile中有以下部分来编译共享库对象:

# The library build step.
lib : $(DHLLOBJS)
    $(CC) $(XCFLAGS) $(SCFLAGS)$(SLIB).1 $(INCFLAGS) -o $(LIB_DIR)/$(SLIB).1.0 \
    $(DLOPATHS) $(LNKFLAGS)
    ln -sf $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB).1
    ln -sf $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB)

以上没有列出任何汇编错误或文件系统错误,但符号链接被描述为 悬挂 强> ,如chmod命令:

$ sudo chmod 0755 ../lib/*
chmod: cannot operate on dangling symlink '../lib/libdhlim.so'
chmod: cannot operate on dangling symlink '../lib/libdhlim.so.1'

ls命令输出下面的命令5和6中的第5行:

$ ls -la lib/
total 29
drwxrwxrwx 1 root root   376 Jul  5 21:13 .
drwxrwxrwx 1 root root  4096 Jul  5 21:13 ..
lrwxrwxrwx 1 root root    21 Jul  5 21:13 libdhlim.so -> ./lib/libdhlim.so.1.0
lrwxrwxrwx 1 root root    21 Jul  5 21:13 libdhlim.so.1 -> ./lib/libdhlim.so.1.0
-rwxrwxrwx 1 root root 23792 Jul  5 21:13 libdhlim.so.1.0

当我运行相同的命令集时, 第5和6行他们手动工作 美好的。我在这里做错了吗?

I am trying to create a shared library using gcc and make. I have the following section in the Makefile to compile the shared library object:

# The library build step.
lib : $(DHLLOBJS)
    $(CC) $(XCFLAGS) $(SCFLAGS)$(SLIB).1 $(INCFLAGS) -o $(LIB_DIR)/$(SLIB).1.0 \
    $(DLOPATHS) $(LNKFLAGS)
    ln -sf $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB).1
    ln -sf $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB)

The above doesn't throw any compilation errors or file system errors but the symlinks are described as dangling as shown by a chmod command:

$ sudo chmod 0755 ../lib/*
chmod: cannot operate on dangling symlink '../lib/libdhlim.so'
chmod: cannot operate on dangling symlink '../lib/libdhlim.so.1'

and the ls command output below shows the lines 5 and 6 in red:

$ ls -la lib/
total 29
drwxrwxrwx 1 root root   376 Jul  5 21:13 .
drwxrwxrwx 1 root root  4096 Jul  5 21:13 ..
lrwxrwxrwx 1 root root    21 Jul  5 21:13 libdhlim.so -> ./lib/libdhlim.so.1.0
lrwxrwxrwx 1 root root    21 Jul  5 21:13 libdhlim.so.1 -> ./lib/libdhlim.so.1.0
-rwxrwxrwx 1 root root 23792 Jul  5 21:13 libdhlim.so.1.0

When I run the same set of commands manually, they work fine. Is there something I am doing wrong here?

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

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

发布评论

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

评论(1

情痴 2025-02-20 05:54:07

问题是您使用相对路径,但不要使用ln选项-r创建链接。

尝试这些作为最后两行:

        ln -sfr $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB).1
        ln -sfr $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB)
  • -r, - 叠加
    使用-s,创建链接相对于链接位置

The problem is that you use relative paths but don't create the links with the ln option -r.

Try these as the last two lines:

        ln -sfr $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB).1
        ln -sfr $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB)
  • -r, --relative
    with -s, create links relative to link location
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文