问题标签 [c-header]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
291 浏览

c - 生成 C 标头时隐藏 Rust 库的私有字段

我正在制作一个包含以下代码的 Rust 库:

我想使用 Objective-C 中的那个库。所以我使用cbindgen来生成一个 C 头文件。在我的 Objective-C 项目中,我只需要访问 MyPublicClass 的公共字段。但是生成的 C 标头包含我的公共结构的所有字段,包括私有字段。

这是生成的 C 头文件的样子:

在这种特殊情况下,HashMap 类型没有直接的 C 等效项,所以我不能使用这个 C 标头。

我只需要在我的 Rust 库中使用这个 HashMap。我不需要从 Objective-C 中使用它。

如何生成一个不暴露它的 C 头文件,而不破坏任何东西?

0 投票
1 回答
85 浏览

c - 根据编译器常量用子目录编译 C

我想制作一个程序,其中除了主目录之外还包括子目录中的源文件和头文件。子目录的名称和部分文件名本身需要使用编译器常量来选择。这是一个示例文件树。

每个编译都涉及 main 和 anotherfile,它们引用 X_file1 和 X_file2,其中“X”在构建时选择或使用常量。所以项目既可以用 A 文件构建,也可以用 B 文件构建。

那么如何(以及“最佳”方法)如何实现这一点?可以在#include 语句中引用编译器常量吗?(类似于#include X+"/"+"x+"_file1.h)或者还有其他方法吗?

我对 C 构建系统和预处理器非常陌生,如果这是一个糟糕的问题,我深表歉意。搜索引擎并没有太大帮助。

0 投票
2 回答
314 浏览

c - gcc“未定义的引用”

我无法找到我的程序无法编译的原因。我不太擅长 C,所以我希望有人能发现我的错误。有人告诉我这可能是一个标题问题,这就是我从这个开始的原因。这是消息:

这是我的文件,但为简洁起见,我将只包括提到的函数声明。

所以这里是设置:

生成文件

测试.c

多项式.h

多项式.c

矩阵.h

矩阵.c

0 投票
2 回答
440 浏览

c++ - 使用 g++ 编译 olcPixelGameEngine 时出错

我正在尝试使用OneLoneCoderolcPixelGameEngine,但是当我尝试编译我的文件(g++ -o YourProgName YourSource.cpp -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17)时,我得到了错误:

fatal error: dwmapi.h: No such file or directory

我将 g++ 9.2 与 MinGW 一起使用。我在哪里可以找到dwmapi.h

0 投票
1 回答
66 浏览

c - 如何在 C 中包含头文件

我不知道如何在我的源文件中包含我自己的头文件。

我在我的头文件(myhead.h)中声明了添加:

在源文件中我定义它(myhead.c):

在第三个源文件中,我包含了头文件并使用了添加(processSimulator.c):

它给了我这个错误

0 投票
0 回答
120 浏览

ubuntu - 错误:我们找到了 libevent 的库,但找不到 C 头文件

我正在尝试安装需要 libevent 开发包的旧 Tor 版本。

我已经正确下载了一个开发包,但是当我运行时./configure --with-libevent-dir=/libevent/lib/x86_64-linux-gnu/,我得到了这个输出:

这是 libevent 文件夹的树

我该如何解决这个问题?

0 投票
1 回答
110 浏览

c - 如何在没有头文件的情况下调用像 time() 这样的 C 函数?

根据我检查的文档,在头文件time_t time(time_t *seconds)下声明。<time.h>然而,当我运行这段代码时:

不包括在内<time.h>,它可以正常工作,或者至少可以工作。这是怎么发生的?

0 投票
1 回答
126 浏览

c - Use typedef struct in another file in C

Hello, I'm new to C.

I want to "export" and use a typedef struct in other files but it seems that it doesn't works a lot.

I have those kind of errors

Here are my files:

main.h

can.h

can.c

Of course I also want to use this CAN_RxMessage filled with data in my main.c (to send it with the usart to my computer).

I tried to use extern, extern struct, struct and manualy defined CAN_frame in my can.c and can.h(but I think it will only overload or redefine CAN_frame in my main.c so it seems useless).

0 投票
1 回答
144 浏览

c - C header declaration for generics (macro)

I am unsure about where to write the declaration and the call of a macro that replaces the code with a function. I do not really know if I should write the macro to the .h or .c file. Before reading some stuff on the best ways to create libraries, I was just putting all the code in a header file and including it on my main, i.e.

Some other functions use these defined functions so I had to call the macro to the .h file.

0 投票
1 回答
30 浏览

python - python解释器能告诉我它的头文件在哪里吗?

在 debian/CentOS 系统中,python 的可执行文件、头文件和库文件的组织方式如下:

但在 Windows 上,文件夹结构有点不同

sys 模块可以告诉我可执行sys.executable文件在哪里以及所有 python 文件安装在的通用文件夹中sys.base_prefix,它或其他模块可以告诉我头文件在哪里吗?