- 我已经构建了 ZeroMQ 解决方案,即 libzmq 和 czmq,我使用 cmake-3.13 来配置和生成,而 vs 2015 为我的 Windows 10 系统构建解决方案。
- 我能够成功运行 czmq_selftest.exe,但当我尝试运行示例代码时,出现以下错误 -
这是我的目录结构-
C:\Program Files\czmq\examples\security\hello.c C:\Program Files\czmq\include
你好.c
#include <czmq.h>
int main (void) {
zsock_t *publisher = zsock_new (ZMQ_PUB);
zsock_set_curve_server (publisher, true);
puts ("Hello, Curve!");
zsock_destroy(&publisher);
return 0;
}
我使用“MinGW64”来编译上述代码-
最初上面的代码给了我
$ gcc hello.c -o hello hello.c:5:10: fatal error: czmq.h: No such file or directory
当我尝试手动给出头文件路径时,我得到了-
gcc hello.c -o hello -I "C:\Program Files\czmq\include"
C:\Ruby25-x64\msys64\tmp\ccF5oCT1.o:hello.c:(.text+0x22): undefined reference to `__imp_zsock_new_checked'
C:\Ruby25-x64\msys64\tmp\ccF5oCT1.o:hello.c:(.text+0x3b): undefined reference to `__imp_zsock_set_curve_server'
C:\Ruby25-x64\msys64\tmp\ccF5oCT1.o:hello.c:(.text+0x64): undefined reference to `__imp_zsock_destroy_checked'
collect2.exe: error: ld returned 1 exit status
我找不到任何可以帮助我解决此错误的信息。
最佳答案
您应该像这样更改第一行:
#include "path/czmq.h"
这是告诉 C 包含文件位于不同目录中的方法
如果包含文件位于同一目录中,则该行将变为
#include "czmq.h"
第二个错误恕我直言,意味着您在包含文件中没有正确的定义
关于c - 编译 C 代码时出现异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54200230/