clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)MINIX3
clang: error: linker command failed with exit code 1 (use -v to see invocation) MINIX3
我正在尝试在MINIX3上运行一个C/C++应用程序,该应用程序应该使用msgsnd()和msgget()在两个进程之间发送消息
这是我得到的错误:
send.cpp:(.text+0x7f): undefined reference to `msgget'
send.cpp:(.text+0x1c1): undefined reference to `msgsnd'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我正在使用clang++编译代码:
clang++ send.cpp -o send.out
这是send.cpp代码:
#include <lib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MSGSZ 128
/*
* Declare the message structure.
*/
typedef struct msgbufer {
long mtype;
char mtext[MSGSZ];
} message_buf;
int main()
{
int msqid;
int msgflg = IPC_CREAT | 0666;
key_t key;
message_buf sbuf;
size_t buf_length;
/*
* Get the message queue id for the
* "name" 1234, which was created by
* the server.
*/
key = 1234;
(void)fprintf(stderr, "nmsgget: Calling msgget(%i,
%#o)n",
key, msgflg);
if ((msqid = msgget(key, msgflg)) < 0) {
perror("msgget");
exit(1);
}
else
(void)fprintf(stderr, "msgget: msgget succeeded: msqid = %dn", msqid);
/*
* We'll send message type 1
*/
sbuf.mtype = 1;
(void)fprintf(stderr, "msgget: msgget succeeded: msqid = %dn", msqid);
(void)strcpy(sbuf.mtext, "Hello other process 2.");
(void)fprintf(stderr, "msgget: msgget succeeded: msqid = %dn", msqid);
buf_length = strlen(sbuf.mtext) + 1;
/*
* Send a message.
*/
if (msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) < 0) {
printf("%d, %li, %s, %lun", msqid, sbuf.mtype, sbuf.mtext, buf_length);
perror("msgsnd");
exit(1);
}
else
printf("Message: "%s" Sentn", sbuf.mtext);
exit(0);
}
您没有链接到包含msgsnd
和msgget
函数的库,因此链接器步骤失败。我不熟悉Minix,所以我不确定库存储在哪里,也不知道它叫什么。基本上,您需要在链接步骤中添加-l<msg>
标志。其中<msg>
是包含实现的库的名称。
相关文章:
- 没有头文件如何使用c ++调用其他模块中的函数?
- 使用 %s 调用 printf 并传递零长度的字符*是未定义的行为吗?
- 使用 "()" 调用构造函数不同于"{}"
- 使用 c++ 调用.dll的默认参数的函数
- 当我同时将 T& 和 T 作为同名函数的返回类型时,如何使用 T& 调用函数
- 使用 P/调用传递取消标志时是否需要同步
- 当被调用方法使用调用方已锁定的同一锁时,如何避免死锁
- 在QT Creator中使用C++调用Python脚本
- C++按引用传递:如何使用调用堆栈
- 如何使用调用和别名指令在 llvm 字节码中查找函数名称
- 如何使用调用和分配指令在 llvm 字节码中查找类名
- 使用C++调用带有库的powershell脚本
- c++-如何使用调用函数的对象
- 使用 C++ 调用函数,其名称两边带有括号
- 如何 使用 C++ 调用 LabVIEW 构建 的 DLL
- 使用c#调用返回struct数组的非托管dll函数
- CUDA c++:使用调用模板内核的模板函数
- 如何创建win32智能手机dll并在WinCE中使用c#调用dll
- 使用 "->" 调用函数
- 错误:使用 C++ 调用 没有匹配函数