Operating System - HP-UX
1834499 Members
2514 Online
110068 Solutions
New Discussion

aCC giving compilation errors saying getmntent_r is undefined

 
SOLVED
Go to solution
sharkvicky
Occasional Contributor

aCC giving compilation errors saying getmntent_r is undefined

Hi,

I have used the getmntent_r() function for my application in in linux. I am trying to port the same to hpux 11iv2. I confiromed the availability of "getmntent_r" by looking at man and header file "mntent.h".

When i am trying to compile this program with aCC as follows it is giving compilation errors.
can you please let me know how can get rid of these and make it working on hpux.

Program and commands used :-
-------------------------------


attempt 1:-
----------
# aCC trail2.cpp
"trail2.cpp", line 11: error #2020: identifier "getmntent_r" is undefined
getmntent_r(fp,&s,buf,4096);
^

1 error detected in the compilation of "trail2.cpp".


attempt2,3,4:-
-----------
# aCC trail2.cpp /usr/lib/libd4r.sl
"trail2.cpp", line 11: error #2020: identifier "getmntent_r" is undefined
getmntent_r(fp,&s,buf,4096);
^

1 error detected in the compilation of "trail2.cpp".
# aCC -ld4r trail2.cpp
"trail2.cpp", line 11: error #2020: identifier "getmntent_r" is undefined
getmntent_r(fp,&s,buf,4096);
^

1 error detected in the compilation of "trail2.cpp".
# aCC -L/usr/lib trail2.cpp
"trail2.cpp", line 11: error #2020: identifier "getmntent_r" is undefined
getmntent_r(fp,&s,buf,4096);
^

1 error detected in the compilation of "trail2.cpp".
# aCC -L/usr/lib -ld4r trail2.cpp
"trail2.cpp", line 11: error #2020: identifier "getmntent_r" is undefined
getmntent_r(fp,&s,buf,4096);
^

1 error detected in the compilation of "trail2.cpp".
#


Program:-(trail2.cpp)
---------------------
#include
#include

//#define _PTHREADS_DRAFT4

int main()
{
FILE *fp;
char *buf;
struct mntent s;
getmntent_r(fp,&s,buf,4096);
//getmntent_r();
printf(" %d ", sizeof(buf));

return 0;
}
4 REPLIES 4
Steven Schweda
Honored Contributor

Re: aCC giving compilation errors saying getmntent_r is undefined

I know nothing, but a quick look at
/usr/include/mntent.h shows:

[...]
#ifdef _PTHREADS_DRAFT4
extern int getmntent_r(FILE *, struct mntent *, char *, int);
[...]

So, I'd guess that you need to get
_PTHREADS_DRAFT4 defined if you expect to get
getmntent_r() declared. I assume that there
are right and wrong ways to do this.
sharkvicky
Occasional Contributor

Re: aCC giving compilation errors saying getmntent_r is undefined

Can you please let me know what are those ways.

I have tried in these ways also
(1) aCC -D_PTHREADS_DRAFT4 trail2.cpp

(2) with #define _PTHREADS_DRAFT4 in the program trail2.cpp

But none of those ways worked. Can you please let me know how differently can i try.
Steven Schweda
Honored Contributor

Re: aCC giving compilation errors saying getmntent_r is undefined

> Can you please let me know what are those
> ways.

Not really. Remember:

> I know nothing, [...]

Perhaps defining _PTHREADS_DRAFT4 is the
right way. Perhaps there's some compiler
option about which I know nothing. One sure
thing is that "#define _PTHREADS_DRAFT4"
_after_ "#include " is not likely
to do much for you.

> But none of those ways worked

"Doesn't work" is not a good problem
description. Defining _PTHREADS_DRAFT4
clears the "error #2020", but it doesn't
solve all the problems in your code. As
usual, actual error messages might be more
useful than vague descriptions.

It's a long way from useful, but you might
try starting with something like this:

td192> cat trail2a.cpp
#define _PTHREADS_DRAFT4

#include
#include
#include

int main()
{
FILE *fp;
char buf[ 4096];
struct mntent s;
int sts;

fp = setmntent(MNT_MNTTAB, "r+");
sts = getmntent_r(fp,&s,buf,4096);
printf( " sts = %d, errno = %d.\n", sts, errno);
if (sts < 0)
{
printf( " %s\n", strerror( errno));
}
else
{
printf( " %s\n", s.mnt_fsname);
}

return 0;
}

td192> aCC -o trail2a -lc_r trail2a.cpp
td192> ./trail2a
sts = -1, errno = 13.
Permission denied

On a system where I have higher status but
only GCC:

dy # g++ -o trail2a -lc_r trail2a.cpp

dy # ./trail2a
sts = 0, errno = 0.
/dev/vg00/lvol3

(Of course, calling this code C++ instead of
C is a little grandiose.)

Finding the run-time library which had
_getmntent_r in it was more trouble than it
should have been, I thought. Perhaps "man
pthread" says something useful. Also, these
tests were done on 11.11 systems. Things
could be different on 11.23, and IA64 may
be different from PA-RISC.
Dennis Handly
Acclaimed Contributor
Solution

Re: aCC giving compilation errors saying getmntent_r is undefined

>aCC giving compilation errors saying getmntent_r is undefined

The header file and man page are broken. You should NOT be using this obsolete function.

It doesn't exist on IPF, and was probably there for 10.x for libcma? It does seem to be in libd4r.sl for PA?

You should use getmntent(3) instead, since it is threadsafe.

>Steven: I'd guess that you need to get
_PTHREADS_DRAFT4 defined if you expect to get
getmntent_r() declared.

Don't even think about defining obsolete _PTHREADS_DRAFT4. This was for libcma.

>Finding the run-time library which had
_getmntent_r in it was more trouble than it
should have been

Just use:
$ nm -pxNA /usr/lib/hpux32/lib* | fgrep getmntent_r

You'll find it isn't in any libs on IPF.