【发布时间】:2025-12-19 06:25:11
【问题描述】:
我正在编写一个分布在多个文件中的 C99 库,例如
// core.h
void my_private_fn();
void API_my_public_fn();
// core.c
#include "core.h"
void my_private_fn() {
do_something();
}
void API_my_public_fn() {
do_something_else();
}
// module_a.h
#include "core.h"
void API_useful_thing();
// module_a.c
#include "module_a.h"
void API_useful_thing() {
my_private_fn();
}
我只希望使用该库的程序可以看到带有API_ 前缀的函数,但我还需要在core.h 中公开my_private_fn 以便module_a.c 使用。 C 中有没有办法让my_private_fn 只在库中可见?
【问题讨论】:
-
根据您使用的平台,您可以查看this answer(请注意,该问题的已接受答案并不能解决您的问题)。
-
您可能需要查看 Windows 及其
__declspec(dllimport)和__declspec(dllexport)限定符,也许您需要查看 GNUldLinker Scripts。
标签: c visibility