简体   繁体   English

铛:错误:链接器命令失败,退出代码为1(使用-v查看调用)MINIX3

[英]clang: error: linker command failed with exit code 1 (use -v to see invocation) MINIX3

I am trying to run a C/C++ application on MINIX3 which is supposed to send a messages between two processes using msgsnd() and msgget() using msg.h. 我正在尝试在MINIX3上运行C / C ++应用程序,该应用程序应该使用msgsnd()和msgget()使用msg.h在两个进程之间发送消息。

This is the error I am getting: 这是我得到的错误:

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)

I am using clang++ to compile the code: 我正在使用clang ++编译代码:

clang++ send.cpp -o send.out

This is the send.cpp code: 这是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 = %d\n", msqid);


    /*
    * We'll send message type 1
    */

    sbuf.mtype = 1;

    (void)fprintf(stderr, "msgget: msgget succeeded: msqid = %d\n", msqid);

    (void)strcpy(sbuf.mtext, "Hello other process 2.");

    (void)fprintf(stderr, "msgget: msgget succeeded: msqid = %d\n", msqid);

    buf_length = strlen(sbuf.mtext) + 1;



    /*
    * Send a message.
    */
    if (msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) < 0) {
        printf("%d, %li, %s, %lu\n", msqid, sbuf.mtype, sbuf.mtext, buf_length);
        perror("msgsnd");
        exit(1);
    }

    else
        printf("Message: \"%s\" Sent\n", sbuf.mtext);

    exit(0);
}

You aren't linking with the library that contains the msgsnd and msgget functions, so your linker step fails. 您没有链接到包含msgsndmsgget函数的库,因此链接器步骤失败。 I'm not familiar with Minix so I'm not sure where the library is stored or what it is called. 我对Minix不熟悉,因此不确定该库存储在哪里或被称为什么。 Basically, you need to a -l<msg> flag to your linking step. 基本上,您需要在链接步骤中添加-l<msg>标志。 Where <msg> is the name of the library that contains the implementation. 其中<msg>是包含实现的库的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)控制台应用程序 - clang: error: linker command failed with exit code 1 (use -v to see invocation) console app 铛:错误:链接器命令失败,退出代码为1(使用-v查看调用)-Qt Creator 3.3 - clang: error: linker command failed with exit code 1 (use -v to see invocation) - Qt Creator 3.3 如何修复 clang:错误:linker 命令失败,退出代码为 1(使用 -v 查看调用) - How do I fix a clang: error: linker command failed with exit code 1 (use -v to see invocation) clang:错误:在cmake中链接库时,链接器命令失败,退出代码为1(使用-v查看调用) - clang: error: linker command failed with exit code 1 (use -v to see invocation) when linking library in cmake 铛:错误:链接器命令失败,退出代码为1(使用-v查看调用)*关于全局变量 - clang: error: linker command failed with exit code 1 (use -v to see invocation) *about global variables VSCode:clang:错误:linker 命令失败,退出代码为 1(使用 -v 查看调用) - VSCode: clang: error: linker command failed with exit code 1 (use -v to see invocation) 编译我的 C++ 程序:clang: error: linker command failed with exit code 1(使用 -v 查看调用) - Compiling my c++ program: clang: error: linker command failed with exit code 1 (use -v to see invocation) Cocos2d-x-铛:错误:链接器命令失败,退出代码为1(使用-v查看调用) - Cocos2d-x - clang: error: linker command failed with exit code 1 (use -v to see invocation) clang++:错误:linker 命令在带有 ffmpeg 的 cpp 中失败,退出代码为 1(使用 -v 查看调用) - clang++: error: linker command failed with exit code 1 (use -v to see invocation) in cpp with ffmpeg 获取错误clang:错误:从终端编译C ++文件时,链接器命令失败,退出代码为1(使用-v查看调用) - Getting error clang: error: linker command failed with exit code 1 (use -v to see invocation) while compile C++ file from terminal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM