upgrading glib

Hi,

I’ve downloaded latest 64-bit SUSE and started some development using g++ in Eclipse CDT Kepler. I’m porting some code relying on quite a few standard libs. One of them is iconv.
I found out that SUSE comes with an old version of GNU Libc (i.e. pre C++11) and I can’t compile some code because getc is missing.
So I’m not exactly sure I can upgrade my standard headers as this might mess up the existing install.
How should I deal with this, if I need the latest version of glibc? thanks!

On 2013-12-17, suse noob13 <suse_noob13@no-mx.forums.opensuse.org> wrote:
>
> Hi,
>
> I’ve downloaded latest 64-bit SUSE and started some development using
> g++ in Eclipse CDT Kepler. I’m porting some code relying on quite a few
> standard libs. One of them is iconv.
> I found out that SUSE comes with an old version of GNU Libc (i.e. pre
> C++11) and I can’t compile some code because getc is missing.

Okay I’m confused. Do you mean C rather than C++? If so, why is C++11 relevant? Isn’t getc in stdio.h which is a C, not
C++ header?

If you mean C++, I have no idea how to compile in Eclipse CDT Kepler, but…


sh-4.2$ g++ -std=c++11 a.cpp

…compiles perfectly in openSUSE 13.1 in accordance to C++11 standards.

But I really don’t know you mean. Can you provide some sample code which doesn’t compile?

libc has absolutely nothing to do with c++, it is as the name implies a
c library. Do you mean libstdc++6?
openSUSE 13.1 has g++ 4.8 which implements most C++11
http://gcc.gnu.org/gcc-4.8/cxx0x_status.html


PC: oS 13.1 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.11 | GTX 650 Ti
ThinkPad E320: oS 13.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.11 | HD 3000
HTPC: oS 13.1 x86_64 | Celeron@1.8GHz | 2GB | Gnome 3.10 | HD 2500

???
openSUSE 13.1 comes with glibc 2.18, which is the latest version according to their homepage:
http://www.gnu.org/software/libc/

and I can’t compile some code because getc is missing.

getc is not missing. And I don’t understand what this should have to do with C++11, since getc was added loooong before C++11, and long before C++ was even dreamt of… :wink:

Maybe you just don’t include the necessary header files in your code?
From “man getc”:

GETS(3)                    Linux Programmer's Manual                   GETS(3)





NAME
       fgetc,  fgets,  getc,  getchar,  gets, ungetc - input of characters and
       strings


SYNOPSIS
       #include <stdio.h>


       int fgetc(FILE *stream);


       char *fgets(char *s, int size, FILE *stream);


       int getc(FILE *stream);


       int getchar(void);


       char *gets(char *s);


       int ungetc(int c, FILE *stream);


DESCRIPTION
       fgetc() reads the next character from  stream  and  returns  it  as  an
       unsigned char cast to an int, or EOF on end of file or error.


       getc()  is equivalent to fgetc() except that it may be implemented as a
       macro which evaluates stream more than once.


       getchar() is equivalent to getc(stdin).



So you need to include <stdio.h> if you want to use getc.
And you can also use fgetc instead.

Or am I misunderstanding you?

I consider this as a very inprecise message. Is this SUSE or openSUSE? Better tell what level then some vaguery as “latest”. When people find this thread later, this wll realy not help them to value the discussion in it. You are asking for help. Then please do not leave the guessing and calculating to the potential helpers where you can provide the information directly with ease.

Thanks for your responses.
First of all, my system is openSUSE 13.1 (Bottle, i586), Kernel is 3.11.6-4-desktop)

> Do you mean C rather than C++? If so, why is C++11 relevant?

Ok, I’m using g++ and including some ilbc headers for certain operations. Hence C++ is relevant.

> Isn’t getc in stdio.h which is a C, not C++ header?
> getc is not missing

C++11 officially declared **getc **deprecated and quite a few libraries started throwing an error when this function is referenced. When the function is defined, it messes up some #**ifdefs **and compilation fails in the end.
When I get the latest **glibc **(http://ftp.heanet.ie/mirrors/gnu/libc/glibc-2.18.tar.gz), **getc **is NOT present in stdio.h. The only entry of **getc **is:

extern int __getc_unlocked(FILE* __fp);

So I don’t know which version I got with my SUSE, even though gnu_get_libc_version() tells me “2.18” :confused:

BTW In terms of not being up to date, e.g. I came across usr/include/iconv.h (which is what I got with my openSUSE by default):

extern size_t iconv (iconv_t __cd, char **__restrict __inbuf,
size_t *__restrict __inbytesleft,
char **__restrict __outbuf,
size_t *__restrict __outbytesleft);

but the latest one is (http://www.gnu.org/savannah-checkouts/gnu/libiconv/documentation/libiconv-1.13/iconv.3.html):**

size_t iconv (iconv_t** cd**, const char* *** inbuf**, size_t *** inbytesleft**, char* *** outbuf**, size_t *** outbytesleft**);

**Note “const”.

> Do you mean libstdc++6?

No I don’t refer to STD, I’m talking about certain subset of standard libc functions that I can still use in C++

I am confused, if you use c++ and want to use the subset of C standard
headers which is conform with C++ then you do not include <stdio.h> but
<cstdio>, stdio.h may work, but probably just by accident.


PC: oS 13.1 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.11 | GTX 650 Ti
ThinkPad E320: oS 13.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.11 | HD 3000
HTPC: oS 13.1 x86_64 | Celeron@1.8GHz | 2GB | Gnome 3.10 | HD 2500

On 2013-12-18, suse noob13 <suse_noob13@no-mx.forums.opensuse.org> wrote:
>
> Thanks for your responses.
> First of all, my system is openSUSE 13.1 (Bottle, i586), Kernel is
> 3.11.6-4-desktop)

Thank you. This would mean your gcc is up to date.

> Ok, I’m using g++ and including some ilbc headers for certain
> operations. Hence C++ is relevant.

So you are using the standard C header libc for a C++ compile? Generally, mixing code is a bad idea. If you want call C
functions from C++ compilers, it’s much safer to pre-compile the C code and link to the compiled binaries to call it
from C++. You shouldn’t include stdio.h in any C++ code and use the C++ equivalent (i.e. iostream.h).

> C++11 officially declared *getc *deprecated and quite a few libraries
> started throwing an error when this function is referenced. When the
> function is defined, it messes up some #*ifdefs *and compilation fails
> in the end.

I suspect that gcc has more than one version of getc() - see below.

> When I get the latest *glibc
> *(http://ftp.heanet.ie/mirrors/gnu/libc/glibc-2.18.tar.gz), *getc *is
> NOT present in stdio.h. The only entry of *getc is:
>
> extern int __getc_unlocked(FILE
__fp);
>
> So I don’t know which version I got with my SUSE, even though
> gnu_get_libc_version() tells me “2.18” :confused:

Consider the trivial code (called `a.c’):


# include <stdio.h>

int main(int argc, char* argv]) {
int c;
int count;
FILE *stri = fopen("a.c", "r");
while( c != EOF )  {
c = getc(stri);
if (c == 'A') count++;
}
fclose(stri);
printf ("File contains %dA.
", count);
return 0;
}

This compiles and runs fine:


sh-4.2$ gcc a.c
sh-4.2$ ./a.out
File contains 2A.
sh-4.2$

If I delete or comment out the # include <stdio.h> line, the result is:


sh-4.2$ gcc a.c
a.c: In function ‘main’:
a.c:6:2: error: unknown type name ‘FILE’
FILE *stri = fopen("a.c", "r");
^
a.c:6:15: warning: initialization makes pointer from integer without a cast [enabled by default]
FILE *stri = fopen("a.c", "r");
^
a.c:7:14: error: ‘EOF’ undeclared (first use in this function)
while( c != EOF )  {
^
a.c:7:14: note: each undeclared identifier is reported only once for each function it appears in
a.c:12:2: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
printf ("File contains %dA.
", count);
^
sh-4.2$

So clearly the variable type FILE requires stdio.h inclusion yet the function getc() requires type FILE* as an input
argument. Perhaps the standard C library implements getc() both as a function as well as macro depending on whether you
include stdio.h, since the variable type of macro input arguments are not explicitly predefined.

But this is a digression. Surely if you want to compile C++ you should write your code in C++? It’s not difficult to
replace getc() with the ifstream equivalent. For example…


# include <iostream>
# include <fstream>

using namespace std;

int main(int argc, char* argv]) {
int c;
int count;
ifstream infile ("a.cpp");
while (!infile.eof()) {
c = infile.get();
if (c == 'A') count++;
};
infile.close();
cout << "File contains " << count << "A" << endl;
return 0;
}

… does exactly the same thing as the straight C code above without having to fuss about getc().