Results 1 to 8 of 8

Thread: upgrading glib

  1. #1

    Default 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!

  2. #2

    Default Re: upgrading glib

    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...

    Code:
    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?

  3. #3
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    4,654

    Default Re: upgrading glib

    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

  4. #4

    Default Re: upgrading glib

    Quote Originally Posted by suse_noob13 View Post
    I found out that SUSE comes with an old version of GNU Libc (i.e. pre C++11)
    ???
    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...

    Maybe you just don't include the necessary header files in your code?
    From "man getc":
    Code:
    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?

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,775

    Default Re: upgrading glib

    Quote Originally Posted by suse_noob13 View Post
    Hi,

    I've downloaded latest 64-bit SUSE ....
    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.
    Henk van Velden

  6. #6

    Default Re: upgrading glib

    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" :/

    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-checkout...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++

  7. #7
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    4,654

    Default Re: upgrading glib

    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

  8. #8

    Default Re: upgrading glib

    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" :/


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

    Code:
    # 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.\n", count);
    return 0;
    }
    This compiles and runs fine:

    Code:
    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:

    Code:
    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.\n", 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...

    Code:
    # 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().


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •