2017-11-04 17 views
0

メッセージで少しprogrammをコンパイルしようとしています。しかし、私はコマンドgcc clinet.cを実行したとき、私はリンカーエラーを持っている:gcc clinet.c -l<namelib>、このLIBまたはLIBSの何名:QNXリンクメッセージライブラリ

`/tmp/ccVytqdg.o: In function "main": 
client.c:(.text+0x5d): undefined reference to "msgget" 
client.c:(.text+0xe8): undefined reference to "msgsnd" 
client.c:(.text+0x126): undefined reference to "msgrcv" 
collect2: ld returned 1 exit status` 

私はそれをリンクshoulことを、知っていますか?私が試した:

メッセージ

メッセージ

MSG

IPC

およびその他。リンカのlibsの名前をどこで見つけることができるか、私にアドバイスしてください!

私の簡単なコード:

#include <stdio.h> 
#include <unistd.h> 
#include <signal.h> 
#include <sys/types.h> 
#include <sys/ipc.h> 
#include <sys/msg.h> 
#include <stdlib.h> 
#include <strings.h> 
#include <string.h> 
typedef struct { 
    long type; 
    char buf[100]; 
} Message; 
int queue; 
void main(void) { 
    char keyFile[] = "key"; 
    key_t key = ftok(keyFile, 'Q'); //ключ, необходимый для создания очереди 
    if (key == -1) { 
     printf("Can`t get key for key file %s and id 'Q'\n", keyFile); 
     exit(1); 
    } 
    queue = msgget(key, 0); 
    if (queue < 0) { 
     printf("Can`t create queue\n"); 
     exit(4); 
    } 
    Message mes; 
    int res; 
    while(1) { 
     bzero(mes.buf, 100); 
     fgets(mes.buf, 100, stdin); 
     mes.buf[strlen(mes.buf - 1)] = '\0'; 
     mes.type = 1L;  
     res = msgsnd(queue, (void*)&mes, sizeof(Message), 0); 
     if (res != 0) { 
      printf("error while sending msg\n"); 
      exit(1); 
     } 
     res = msgrcv(queue, &mes, sizeof(Message), 2L, 0); 
     if (res < 0) { 
      printf("Error while recieving msg\n"); 
      exit(1); 
     } 
     printf("Server`s response: %s\n", mes.buf); 
    } 
    exit(0); 
} 

構築しようとしているのADDのIMG:

# cd georgiy/ 
# cd lab1/ 
# cd ipc_messages/ 
# ls -l 
total 12 
drwxrwxr-x 2 root root 1024 Nov 04 10:49 . 
drwxr-xr-x 5 root root 1024 Oct 28 15:21 .. 
-rw-rw-r— 1 root root 1072 Dec 14 2014 client.c 
-rw-rw-r— 1 root root 0 Dec 14 2014 key 
-rw-rw-r— 1 root root 202 Oct 28 18:08 michael_receiver.c 
-rw-rw-r— 1 root root 457 Oct 28 18:23 michael_receiver.s 
-rwxrwxrwx 1 root root 1277 Oct 28 15:26 server.c 
# gcc client.c 
/tmp/cczfofBa.o: In function `main': 
client.c:(.text+0x5d): undefined reference to `msgget' 
client.c:(.text+0xe8): undefined reference to `msgsnd' 
client.c:(.text+0x126): undefined reference to `msgrcv' 
collect2: ld returned 1 exit status 
# 
+0

*完全な*ビルドログは未編集です。 –

+0

端末からフルログを追加しました –

答えて

関連する問題