Skip to content

Conversation

ustcljh
Copy link
Member

@ustcljh ustcljh commented Sep 2, 2025

No description provided.

Copy link

cloudflare-workers-and-pages bot commented Sep 2, 2025

Deploying linux201-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2376e8f
Status: ✅  Deploy successful!
Preview URL: https://b30b932f.linux201-docs.pages.dev
Branch Preview URL: https://luojh-add-library-in-dev.linux201-docs.pages.dev

View logs

@ustcljh
Copy link
Member Author

ustcljh commented Sep 2, 2025

这个 build CI failed 是正常的吧 @RTXUX

@taoky taoky force-pushed the luojh-add-library-in-dev branch from ef01039 to 8d404dd Compare September 2, 2025 14:55
- Golang: dev/language/golang.md
- 版本管理与合作: dev/git.md
- SSH 使用技巧: dev/ssh.md
- dev/index.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要修改这个文件的 indentation

- Golang: dev/language/golang.md
- 版本管理与合作: dev/git.md
- SSH 使用技巧: dev/ssh.md
- Linux 上的链接库: dev/library.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

层级需在「编程语言概览」下面,预期是在 cxx.md 里面。现在的内容量没法单列一个 page。

@@ -0,0 +1,118 @@
---
icon: simple/cplusplus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换个图标,和 C/C++ 的重复了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

material/book 或者 material/book-cog 不错,material/bookmark-box 也行

icon: simple/cplusplus
---

# 链接库
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主标题名称需与 nav 里面一致。


!!! comment "适用范围"

本文介绍 Linux 上的**静态链接库** (一般为 `.a` 文件) 和**动态链接库** (一般为 `.so` 文件)。注意:这里的链接库是指包含了可执行二进制代码的库,并不是头文件 (Header file)、Python 库等。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

括号内包含中文的情况下使用全角括号,下面其他的也一样。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header file 不需要大写,header file 就够了

header["头文件 (*.h)"] --- source
target --> linker["链接器"]
staticlib["**静态链接库** (链接步骤加入)"] --> linker
linker --> executable["可执行文件 (ELF等)"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
linker --> executable["可执行文件 (ELF等)"]
linker --> executable["可执行文件(ELF 等)"]

以便其他使用链接库的程序**知道如何使用这个函数** (即使这些程序不知道函数内部的实现)。

因为链接库不是完整的、可以独立运行的程序,因此不需要入口点 (比如 `main` 函数)。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

介绍一下 extern

header["头文件 (*.h)"] --- source
target -->|链接| executable["可执行文件 (ELF等)"]
target -->|ar rcs| staticlib["静态链接库 (*.a)"]
target -->|gcc -shared| dynamiclib["动态链接库 (*.a)"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target -->|gcc -shared| dynamiclib["动态链接库 (*.a)"]
target -->|<code>gcc -shared</code>| dynamiclib["动态链接库 (*.a)"]

上面的 ar rcs 也可以这么做。

int square(int x);
```

以便其他使用链接库的程序**知道如何使用这个函数** (即使这些程序不知道函数内部的实现)。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有必要讲一下预处理。


这里,`-L./lib` 表示要求链接器在 `./lib` 中寻找链接库,`-lsquare` 表示需要链接 `libsquare.a` 这个静态链接库文件。

编译好之后,就可以正常使用了。由于静态链接库中的代码会被直接合并到链接产生的可执行文件 `main` 中,因此运行时不需要文件 `libsquare.a`。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frankly 读到这里结束我稍微有点意外,更期待一点 in-depth 的内容……

目前这个内容量大概可以作为 101 的拓展内容……?如果介绍一些 LD_LIBRARY_PATH(例如不同 CUDA 版本等)/打包相关的也许更适合放在 201 一些。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在这个分量确实是不够的

@ustcljh
Copy link
Member Author

ustcljh commented Sep 8, 2025

目前内容确实是偏少的,也和我最近正在准备这个稿子有关系。对于201来说,这个部分可能不只写链接库,可能更偏向于一个稍微丰富一些的C构建系统的介绍?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants