Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Re: dunix/cxx/mknod
       [not found] ` <35E27DA1.A926226E@zko.dec.com>
@ 1998-08-25  4:00   ` Jason Mancini
  1998-08-25  4:00     ` dunix/cxx/mknod Stefan Schwarzer
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Mancini @ 1998-08-25  4:00 UTC (permalink / raw)


Dave Butenhof wrote:
> 
> Jason Mancini wrote:
> 
> > Accoring to the man page (2), mknod is in libc.a,
> > and defined in <sys/stat.h>.  However, I can't
> > seem to get my program to compile without an
> > explicit prototype, and if I do provide the mknod
> > prototype, it won't link.  Is there a special
> > -l<library> switch needed?
> >
> > Trying to use mknod to create interprocess pipes.
> >
> > In stat.h:
> >
> > #ifdef _XOPEN_SOURCE_EXTENDED
> > extern int      mknod __((const char *, mode_t, dev_t ));
> > #endif
> >
> > Why the _XOPEN_SOURCE_EXTENDED...

> First, this question really isn't appropriate for
> comp.programming.threads. This newsgroup deals with MULTITHREADED
> programming issues. Since you're apparently concerned with Digital UNIX,
> and interested in using news as a programming resource, you should be
> reading the comp.unix.osf.osf1 newsgroup -- which specifically deals
> with Digital UNIX.

The program consists of multiple threads and multiple processes, sorry
for the confusion.  I have seen much more useless posts, I thought
there might be a quick answer for a quick question.  I monitor the ng
mentioned, don't see many programming Q's there.  But I'll give it a
try... 
Back to the issue.

<snip>

> In this case, though, there is no magic involved, so I can't imagine why
> you'd have trouble linking with an "appropriate" prototype of your own.
> Since you didn't show the code or your compile/link command, there's no
> way to guess what you may have done wrong. Because the cc and cxx
> commands (if you allow them to link) will always link against libc, and
> that's where mknod() lives, there should be no problem. If you're using
> ld rather than cc or cxx to link, then there are several additional
> things you need to worry about, which I won't detail here except to say
> that "-lc" is only one of them.

I tried every library that is installed on my machine that I could
find, hence my confusion.  "-lc" was attempted.

> As for _XOPEN_SOURCE_EXTENDED... despite the inaccurate "standards" text
> in the man page, mknod() is NOT a POSIX.1 function. It was, in fact,
> deliberately excluded from that standard. (Instead, you should use
> either mkfifo() or mkdir().) The Single UNIX Specification, however,
> (XPG4, or UNIX95) includes mknod(), and requires that the prototype be
> in <sys/stat.h>. That's fine, except that, because the function is NOT
> specified by POSIX.1, the name must not intrude on the user's (your)
> namespace when compiling POSIX conforming code. If you want it, you must
> explicitly request the UNIX95 namespace when you compile.

<snip>

> (Finally, and parenthetically, if you want to follow up on this please
> do so by posting to comp.unix.osf.osf1, or, since you're at .dec.com, to
> the Digital UNIX notes conference, rather than replying here.)

Thanks for the lead!

> 
> /---------------------------[ Dave Butenhof ]--------------------------\
> | Compaq Computer Corporation                     butenhof@zko.dec.com |
> | 110 Spit Brook Rd ZKO2-3/Q18       http://members.aol.com/drbutenhof |
> | Nashua NH 03062-2698  http://www.awl.com/cseng/titles/0-201-63392-2/ |
> \-----------------[ Better Living Through Concurrency ]----------------/


Let me try again.

blah.cpp/blah.c:
#include <sys/stat.h>
void main()
{mknod("foo", S_IFIFO | 0666, 0);}

> cxx blah.cpp
cxx: Error: blah.cpp, line 7: In this statement, "mknod" is not
declared.
  mknod("foo", S_IFIFO | 0666, 0);
--^

> cc blah.c
>           (works)

> c89 blah.c
>           (works)

blah.cpp/blah.c:
#include <sys/stat.h>
int mknod(const char *path, int mode, dev_t device);
void main()
{mknod("foo", S_IFIFO | 0666, 0);}

> cxx blah.cpp
ld:
Unresolved:
mknod(const char*, int, int)

> cc blah.c
>           (works)

> c89 blah.c
cc: Warning: blah.c, line 3: In this declaration, parameter 2 has a
different type than specified in an earlier declaration of this
function. ...
...

So what gives with cxx?  (Same thing happens with usleep.)

Thanks
/Jason



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: dunix/cxx/mknod
  1998-08-25  4:00   ` dunix/cxx/mknod Jason Mancini
@ 1998-08-25  4:00     ` Stefan Schwarzer
  1998-08-25  4:00       ` dunix/cxx/mknod Jason Mancini
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Schwarzer @ 1998-08-25  4:00 UTC (permalink / raw)


Jason Mancini <jmancini@pa.dec.com> wrote:
> Dave Butenhof wrote:
>> 

> blah.cpp/blah.c:
> #include <sys/stat.h>
> int mknod(const char *path, int mode, dev_t device);
> void main()
> {mknod("foo", S_IFIFO | 0666, 0);}

>> cxx blah.cpp
> ld:
> Unresolved:
> mknod(const char*, int, int)

> cc: Warning: blah.c, line 3: In this declaration, parameter 2 has a
> different type than specified in an earlier declaration of this


You are hiding the c-library function by your repeated declaration of 
mknod before the main. At least you should use an extern "C" {} if you 
require such a hack for some reason. The c++ compiler will then not 
mangle the types into the function name and give the linker a chance to 
find the function name in the c-library... 
btw: the c compiler warns because the signature is not ok, the second argument is mode_t which is a typedef from unsigned int. 

The following works fine for me:

23:43 margay_sts:~> cat mknod.cc
#include <sys/stat.h>
int main(){
  mknod("foo", S_IFIFO |0666, 0);
}
23:43 margay_sts:~> cxx -D_XOPEN_SOURCE_EXTENDED mknod.cc
23:44 margay_sts:~> a.out
23:44 margay_sts:~> ls -l foo
prw-r--r--   1 sts      cron           0 Aug 25 23:44 foo|

-- 
Stefan Schwarzer                office:  +49-(0)711-685-7606   fax: x-3658 
70569 Stuttgart, Germany             http://www.ica1.uni-stuttgart.de/~sts



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: dunix/cxx/mknod
  1998-08-25  4:00     ` dunix/cxx/mknod Stefan Schwarzer
@ 1998-08-25  4:00       ` Jason Mancini
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Mancini @ 1998-08-25  4:00 UTC (permalink / raw)


Stefan Schwarzer wrote:
(snip)
 > You are hiding the c-library function by your repeated declaration of
 > mknod before the main. At least you should use an extern "C" {} if
you
 > require such a hack for some reason. The c++ compiler will then not
 > mangle the types into the function name and give the linker a chance
to
 > find the function name in the c-library...
 > btw: the c compiler warns because the signature is not ok,
 > the second argument is mode_t which is a typedef from unsigned int.
 > 
 > The following works fine for me:
 > 
 > 23:43 margay_sts:~> cat mknod.cc
 > #include <sys/stat.h>
 > int main(){
 >   mknod("foo", S_IFIFO |0666, 0);
 > }
 > 23:43 margay_sts:~> cxx -D_XOPEN_SOURCE_EXTENDED mknod.cc
 > 23:44 margay_sts:~> a.out
 > 23:44 margay_sts:~> ls -l foo
 > prw-r--r--   1 sts      cron           0 Aug 25 23:44 foo|
 > 
 > --
 > Stefan Schwarzer                office:  +49-(0)711-685-7606   fax:
x-3658
 > 70569 Stuttgart, Germany            
http://www.ica1.uni-stuttgart.de/~sts

(I could swear that I tried that combo...)
Thanks, I got it working in minutes!
I see my error now.  Thanks again,
/Jason



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-08-25  4:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <35E2007A.A7767FA1@pa.dec.com>
     [not found] ` <35E27DA1.A926226E@zko.dec.com>
1998-08-25  4:00   ` dunix/cxx/mknod Jason Mancini
1998-08-25  4:00     ` dunix/cxx/mknod Stefan Schwarzer
1998-08-25  4:00       ` dunix/cxx/mknod Jason Mancini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox