Compilation problem with Posix Mes Q


 
Thread Tools Search this Thread
Top Forums Programming Compilation problem with Posix Mes Q
# 1  
Old 05-18-2010
Compilation problem with Posix Mes Q

Hi

Code:
#include "training.h"
#include <mqueue.h> // for posix mqs

int main(int argc,char *argv[])
{

    
    int opt,flag;
    mqd_t msq; // msg q type
    flag=O_RDWR|O_CREAT;

    while((opt =getopt(argc,argv,"e")) != -1)
    {
        switch(opt)
        {
            case 'e':
                flag|=O_EXCL;
                break;
        }
    }
    // option indicator should be one less than what is passed
    if(optind != argc -1)
    {
        fprintf(stderr,"usag: msqcr -e <name>\n");
        return 1;
    }
    msq =mq_open(argv[optind],flag,0666,NULL);
    mq_close(msq);


}

When i tried to compile this code

-bash-3.1$ gcc mqcreate.c
/tmp/cccJjZP4.o: In function `main':
mqcreate.cSmilie.text+0xc1): undefined reference to `mq_open'
mqcreate.cSmilie.text+0xcf): undefined reference to `mq_close'
collect2: ld returned 1 exit status
-bash-3.1$

I am having problem in linking i guess.

Please can anyone help me on this

THanks
Kumaran
# 2  
Old 05-18-2010
I'm guressing you are on Solaris -- you need
Code:
gcc myprog.c -o myprog -lrt

If you are on another platform the problem may be something else.
# 3  
Old 05-18-2010
Thanks Jim.

But i am using Linux.
# 4  
Old 05-18-2010
You need to specify the path and name of the mq shared library to link to...on linux it maybe something like...
Code:
gcc mqcreate.c -L/opt/imq/lib -lmqcrt

# 5  
Old 05-19-2010
I have checked for the library

-bash-3.1$ find . -name *mqcrt* 2>/dev/null
-bash-3.1$ pwd
/
-bash-3.1$


but i couldn't find one... is thery anyway to download and use it.
Please help me on this

---------- Post updated at 03:24 PM ---------- Previous update was at 10:08 AM ----------

I manage to find a way to compile it.

When we use message queue in Linux, it should be compiled by linking runtime library like

gcc -ltr mqcreat.c


Thanks Experts.
This User Gave Thanks to kumaran_5555 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

A weird problem with POSIX function

Hi all, Sorry for the title because I didn't find a proper name for it. My question is about POSIX functions, such as timer_create(), mq_open() and pthread_create(). void test_queue() { struct mq_attr attr; attr.mq_maxmsg = 10; attr.mq_msgsize = 64; mq_unlink("/my_test_queue");... (6 Replies)
Discussion started by: bus147
6 Replies

2. AIX

Problem in compilation.

Hi, I am executing the below mentioned code:- proc SQLCHECK=SEMANTICS iname=CDBInteractor.pc parse=none code=cpp cpp_suffix=cpp g++ -c main.cpp g++ -o pre_request_engine main.o -I/oracle/oracle/app/product/10g/precomp -L/oracle/oracle/app/product/10g/lib32 -lnsl -ldl And... (2 Replies)
Discussion started by: tushar_tus
2 Replies

3. Programming

C Compilation problem

Dear all I am new to C programming In response to the post cat get_time.c #include <stdlib.h> #include <sys/time.h> main() { struct timeval tv; struct timezone tz; struct tm *tm; gettimeofday(&tv, &tz); tm=localtime(&tv.tv_sec); printf("... (2 Replies)
Discussion started by: on9west
2 Replies

4. AIX

Compilation problem

hi, I first want to apologize for my poor english ! I'm a newbe on Unix system and I have to install NRPE on an AIX 5.3. I have downloaded the NRPE Source code and i need to compile them... the problem is, when I do a: ./configure --enable-command-args --disable-ssl it returns me :... (1 Reply)
Discussion started by: Cyr1us
1 Replies

5. AIX

Pro C Compilation problem

Hi, I have AIX 5.3 and my code is written in proc . i am getting following error during compilation Please help?////..... :-d: Compiling with RMS cc -w -q32 -qidirfirst -ISource/Header -I/usr/vacpp/include -q32 -DRMS -DDISEC -DDBG -DBIGENDIAN -DBIT32 -c -q32... (0 Replies)
Discussion started by: ajaysahoo
0 Replies

6. Programming

Problem with POSIX pthreads and virtual memory

Hi, i have this code... in order to test my problem... #include <stdio.h> #include <iostream> #include <pthread.h> static void* cliente(void *datos); int main() { pthread_attr_t tattr; int ret; size_t size = PTHREAD_STACK_MIN + 0x0100; ret =... (8 Replies)
Discussion started by: JEscola
8 Replies

7. Solaris

A compilation problem when using templates

Hello life savers, I'm having trouble compiling a specific program. The program was originally written for gcc and was compiled successfully under it. When trying to compile under Solaris 11, I get this error: "Hashtable.h", line 170: Error: Could not find a match for hash needed in... (2 Replies)
Discussion started by: yp515
2 Replies

8. Programming

Compilation problem on HP-UX

Hi, Environment : HP-UX avalon B.11.11 U 9000/800 3547052374 unlimited-user license aCC version :aCC: HP ANSI C++ B3910B A.03.37 I need to find a way out of this errors.can anyone help me . $ aCC db.cc -I$ORACLE_HOME/rdbms/public -I/disk1/oracle/product/10.2.0.2/* Error (future)... (1 Reply)
Discussion started by: varuntayur
1 Replies

9. Programming

compilation problem

i have a class name 1.c in tht i am using function n wich has his body in 2.c and declaration in 2.h now how can i compile 1.c. ex; 1.c int main() { //some data n(10); //somedata } ***** 2.c int n(int k) { //some data } int main() { some data (2 Replies)
Discussion started by: phani_sree
2 Replies

10. Solaris

compilation problem

I am compiling a software named wine When i run make then at the end following error generated. DVAPI32_ -foversion.res version.rc ld.so.1: ../../tools/wrc/wrc: fatal: relocation error: file ../../tools/wrc/wrc: symbol wine_casemap_upper: referenced symbol not found *** Signal 9 make:... (0 Replies)
Discussion started by: mansoorulhaq
0 Replies
Login or Register to Ask a Question