4 Replies - 553 Views - Last Post: 23 February 2013 - 09:08 AM Rate Topic: -----

#1 fyr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-January 13

IDE error: can't resolve msgget identifier

Posted 22 February 2013 - 08:39 AM

Hi. The function msgget from sys/msg.h is not being recognized by Netbeans 7.2.1. Have I missed anything?
OS: OpenSUSE 12.2 "Mantis"

#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>


extern void exit();
extern void perror();

int main(void) {

    key_t key;
    int msgflg, msqid;
    fprintf(stdout, "All numeric input is expected to follow C conventions:\n");
    fprintf(stdout, "\t0... is interpreted as hexadecimal,\n");
    fprintf(stdout, "\totherwise, decimal.\n");
    fprintf(stdout, "IPC_PRIVATE == %#x\n", IPC_PRIVATE);

    fprintf(stdout, "Enter key: ");
    scanf("%d", &key);


    fprintf(stdout, "\nExpected flags for msgflg argument are:\n");
    (void) fprintf(stdout, "\tIPC_EXCL =\t%#8.8o\n", IPC_EXCL);
    (void) fprintf(stdout, "\tIPC_CREAT =\t%#8.8o\n", IPC_CREAT);
    (void) fprintf(stdout, "\towner read =\t%#8.8o\n", 0400);
    (void) fprintf(stdout, "\towner write =\t%#8.8o\n", 0200);
    (void) fprintf(stdout, "\tgroup read =\t%#8.8o\n", 040);
    (void) fprintf(stdout, "\tgroup write =\t%#8.8o\n", 020);
    (void) fprintf(stdout, "\tother read =\t%#8.8o\n", 04);
    (void) fprintf(stdout, "\tother write =\t%#8.8o\n", 02);

    (void) fprintf(stdout, "Enter msgflg value: ");
    scanf("%d", &msgflg);

    fprintf(stdout, "\nmsgget: Calling msgget(%#x, %#o)\n", key, msgflg);

    if((msqid = msgget(key, msgflg)) == -1)
    {
       perror("msgget");
       exit(1);
    }    
    else {
      fprintf(stdout, "Msgget succeeded. msqid = %d\n", msqid);   
    }
    exit(1);
}



Is This A Good Question/Topic? 0
  • +

Replies To: IDE error: can't resolve msgget identifier

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4062
  • View blog
  • Posts: 12,540
  • Joined: 25-December 09

Re: IDE error: can't resolve msgget identifier

Posted 22 February 2013 - 08:56 AM

The only errors/warnings I get when I compile your code are:

Quote

/usr/include/i386-linux-gnu/sys/ipc.h|25|warning: #warning "Files using this header must be compiled with _SVID_SOURCE or _XOPEN_SOURCE" [-Wcpp]|
main.c|10|warning: redundant redeclaration of ‘perror’ [-Wredundant-decls]|
/usr/include/stdio.h|843|note: previous declaration of ‘perror’ was here|
||=== Build finished: 1 errors, 2 warnings ===|


How are you compiling with the first warning?

You shouldn't redefine standard C functions, like perror() and exit() just include the proper header files, stdio.h and stdlib.h.


Jim
Was This Post Helpful? 1
  • +
  • -

#3 fyr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-January 13

Re: IDE error: can't resolve msgget identifier

Posted 22 February 2013 - 09:31 AM

Hi Jim. I fixed the include but the problem: "Unable to resolve identifier msgget" highlighted by the IDE (without compilation) persists. However, I compiled the src with -Wall without any errors or warnings. There are some others sources I need to analyse within this project so I will post again if something go wrong. Thank you for your help.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 4062
  • View blog
  • Posts: 12,540
  • Joined: 25-December 09

Re: IDE error: can't resolve msgget identifier

Posted 22 February 2013 - 10:20 AM

If the program compiles and links properly I wouldn't worry about the IDE warning.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 fyr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-January 13

Re: IDE error: can't resolve msgget identifier

Posted 23 February 2013 - 09:08 AM

yep... I was able to compile successfully thanks Jim. About the other topic I just opened, it was another problem I was trying to solve with msgctl.c and not msget anymore. But I kind solved it. :)/> I'm glad you closed since, as far I know, there isn't a remove topic button right?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1