[Q]function name and variable name conflict.

C

chunmok

When compile using g++, following error messages appears.

/usr/include/sys/sysinfo.h:101: `struct sysinfo_t sysinfo' redeclared
as differe
nt kind of symbol
/usr/include/sys/systeminfo.h:77: previous declaration of `int
sysinfo(int, char
*, long int)'
....
szh.cpp:899: no match for call to `(sysinfo_t) (int, char[256], long
int)'
make: *** [szh.o] Error 1

It seems that g++ could not distinguish sysinfo(2) system call from
sysinfo structure variable.
How can I solve this provblem...? Hope advice.

Chun-Mok Chung.
 
J

Jack Klein

When compile using g++, following error messages appears.

/usr/include/sys/sysinfo.h:101: `struct sysinfo_t sysinfo' redeclared
as differe
nt kind of symbol
/usr/include/sys/systeminfo.h:77: previous declaration of `int
sysinfo(int, char
*, long int)'
...
szh.cpp:899: no match for call to `(sysinfo_t) (int, char[256], long
int)'
make: *** [szh.o] Error 1

It seems that g++ could not distinguish sysinfo(2) system call from
sysinfo structure variable.
How can I solve this provblem...? Hope advice.

Chun-Mok Chung.

Rename one or the other. You can't use the same name as both a
function and an object in the same namespace.

Alternatively ask in a gcc or a Linux (or your particular *NIX flavor)
group. Note that neither of these headers is part of standard C++,
they are platform specific extensions.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
L

llewelly

When compile using g++, following error messages appears.

/usr/include/sys/sysinfo.h:101: `struct sysinfo_t sysinfo' redeclared
as differe
nt kind of symbol
/usr/include/sys/systeminfo.h:77: previous declaration of `int
sysinfo(int, char
*, long int)'
...
szh.cpp:899: no match for call to `(sysinfo_t) (int, char[256], long
int)'
make: *** [szh.o] Error 1

It seems that g++ could not distinguish sysinfo(2) system call from
sysinfo structure variable.
How can I solve this provblem...? Hope advice.

Wrap one of them.

--- sysinfo_wrapper.h ---

#ifdef SYSINFO_WRAPPER_H
#define SYSINFO_WRAPPER_H
int sysinfo_wrapper(int, char* long int);
#endif
//SYSINFO_WRAPPER_H

___ sysinfo_wrapper.cc --

#include "sysinfo_wrapper.h"
#include <sys/sysinfo.h>

int sysinfo_wrapper(int i, char* c, long int l)
{
sysinfo(i,c,l);
}

Then, never #include sys/sysinfo.h anwhere - always include
sysinfo_wrapper.h instead, and call sysinfo_wrapper.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top