problem compiling static library

Discussion in 'C++' started by nvangogh, May 27, 2014.

  1. nvangogh

    nvangogh Guest

    I am trying to build a static library. I am having a problem when I try
    to compile it. I am getting two errors. The first is at line 82 and the
    second is at line 120. Both errors seem to be related to the same thing,
    namely 'memset was not declared in this scope'

    It is a very long file so I have posted only the section of the file up
    to the first error as the second error further down seems to be similar.
    ------------------------------------------------------------------

    // This is a X Window/Posix implementation of the playpen interface.
    //
    // Author: Jean-Marc Bourguet
    //
    // This file shares part of the implementation with the MS Windows one by
    // copying the code. A better way would be to separate platform-specific
    // and platform-independent code into different translation units.
    // However, this would complicate the build steps and considering the code
    // is intended to be used (if not understood) by novices, this has not been
    // done.

    // Implemented interface

    #include "keyboard.h"
    #include "mouse.h"
    #include "playpen.h"

    // C++ standard headers

    #include <assert.h>
    #include <map>
    #include <stdexcept>
    #include <stdlib.h>
    #include <streambuf>

    // Posix headers

    #include <pthread.h>
    #include <sys/time.h>
    #include <sys/types.h>
    #include <termios.h>
    #include <unistd.h>

    // X Window headers

    #include <X11/Xlib.h>
    #include <X11/Xutil.h>
    #include <X11/keysym.h>

    namespace
    {

    using namespace studentgraphics;

    int const key_unknown = 0xFE;

    //
    ======================================================================
    // Platform-independant utility classes
    //
    ======================================================================

    //
    **********************************************************************
    // Inherit privately from this class to disable copy constructor and
    // assignment operator

    class CopyDisabler
    {
    public:
    CopyDisabler();

    private:
    CopyDisabler(CopyDisabler const&);
    CopyDisabler& operator=(CopyDisabler const&);
    };

    inline
    CopyDisabler::CopyDisabler()
    {
    }

    //
    **********************************************************************
    // The mapping between hue and RGB value

    struct HueRGB256
    {
    HueRGB rgbs[colours];

    HueRGB256();
    };

    HueRGB256::HueRGB256()
    {
    memset(rgbs, 0, sizeof(HueRGB) * colours);
    -----------------------------

    The compiler errors are as follows:

    ||=== Build: Release in fgw (compiler: GNU GCC Compiler) ===|
    /home/n/tutorial/source/playpen_unix1.cpp||In constructor
    ‘{anonymous}::HueRGB256::HueRGB256()’:|
    /home/n/tutorial/source/playpen_unix1.cpp|82|error: ‘memset’ was not
    declared in this scope|
    /home/n/tutorial/source/playpen_unix1.cpp||In member function ‘void
    {anonymous}::pixels::Clear(studentgraphics::hue)’:|
    /home/n/tutorial/source/playpen_unix1.cpp|120|error: ‘memset’ was not
    declared in this scope|
    /home/n/tutorial/source/playpen_unix1.cpp||In member function ‘void*
    {anonymous}::SingletonWindowImpl::WorkerThread()’:|
    /home/n/tutorial/source/playpen_unix1.cpp|685|warning: suggest
    parentheses around comparison in operand of ‘&’ [-Wparentheses]|
    /home/n/tutorial/source/playpen_unix1.cpp|330|warning:
    ‘{anonymous}::SingletonWindowImpl::instance_’ defined but not used
    [-Wunused-variable]|
    ||=== Build failed: 2 error(s), 2 warning(s) (0 minute(s), 11 second(s))
    ===|
    --------------------------------

    So both errors relate to 'memset' not being declared. Can anyone see how
    I can correct this?

    Thanks
     
    nvangogh, May 27, 2014
    #1
    1. Advertisements

  2. nvangogh

    nvangogh Guest

    It's ok guys - I found the answer in an old usenet post:

    #include <cstring>
    using std::memset;

    -------
    Needs to be added to the file for the build to work.
     
    nvangogh, May 27, 2014
    #2
    1. Advertisements

  3. nvangogh <> wrote:
    > I am trying to build a static library. I am having a problem when I try
    > to compile it. I am getting two errors. The first is at line 82 and the
    > second is at line 120. Both errors seem to be related to the same thing,
    > namely 'memset was not declared in this scope'


    memset() is, if I'm not completely mistaken. declared in <cstring>,
    so if you add it to your include files the compiler should be happy.

    Regards, Jens
    --
    \ Jens Thoms Toerring ___
    \__________________________ http://toerring.de
     
    Jens Thoms Toerring, May 27, 2014
    #3
  4. nvangogh

    Jorgen Grahn Guest

    On Tue, 2014-05-27, nvangogh wrote:
    > I am trying to build a static library. I am having a problem when I try
    > to compile it. I am getting two errors. The first is at line 82 and the
    > second is at line 120. Both errors seem to be related to the same thing,
    > namely 'memset was not declared in this scope'
    >
    > It is a very long file so I have posted only the section of the file up
    > to the first error as the second error further down seems to be similar.

    ....

    > // The mapping between hue and RGB value
    >
    > struct HueRGB256
    > {
    > HueRGB rgbs[colours];
    >
    > HueRGB256();
    > };
    >
    > HueRGB256::HueRGB256()
    > {
    > memset(rgbs, 0, sizeof(HueRGB) * colours);
    > -----------------------------
    >
    > The compiler errors are as follows:
    >
    > ||=== Build: Release in fgw (compiler: GNU GCC Compiler) ===|
    > /home/n/tutorial/source/playpen_unix1.cpp||In constructor
    > ?{anonymous}::HueRGB256::HueRGB256()?:|
    > /home/n/tutorial/source/playpen_unix1.cpp|82|error: ?memset? was not
    > declared in this scope|

    ....
    > So both errors relate to 'memset' not being declared. Can anyone see how
    > I can correct this?


    memset comes, according to my C language man pages, from <string.h>,
    so #include <cstring> and call it std::memset and you should be fine.

    But note that it's a slightly bad idea to do what the author does here:
    initializing an array of HueRGB objects by paving it over with 0 bytes.

    Give HueRGB a default constructor and you don't have to do anything
    here. Or, use std::fill() as a "type-aware memset".

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
     
    Jorgen Grahn, May 27, 2014
    #4
  5. nvangogh

    nvangogh Guest

    On 27/05/14 17:48, Jens Thoms Toerring wrote:
    > nvangogh <> wrote:
    >> I am trying to build a static library. I am having a problem when I try
    >> to compile it. I am getting two errors. The first is at line 82 and the
    >> second is at line 120. Both errors seem to be related to the same thing,
    >> namely 'memset was not declared in this scope'

    >
    > memset() is, if I'm not completely mistaken. declared in <cstring>,
    > so if you add it to your include files the compiler should be happy.
    >
    > Regards, Jens
    >

    Thanks
     
    nvangogh, May 27, 2014
    #5
  6. nvangogh

    nvangogh Guest

    On 27/05/14 17:50, Jorgen Grahn wrote:
    > On Tue, 2014-05-27, nvangogh wrote:
    >> I am trying to build a static library. I am having a problem when I try
    >> to compile it. I am getting two errors. The first is at line 82 and the
    >> second is at line 120. Both errors seem to be related to the same thing,
    >> namely 'memset was not declared in this scope'
    >>
    >> It is a very long file so I have posted only the section of the file up
    >> to the first error as the second error further down seems to be similar.

    > ...
    >
    >> // The mapping between hue and RGB value
    >>
    >> struct HueRGB256
    >> {
    >> HueRGB rgbs[colours];
    >>
    >> HueRGB256();
    >> };
    >>
    >> HueRGB256::HueRGB256()
    >> {
    >> memset(rgbs, 0, sizeof(HueRGB) * colours);
    >> -----------------------------
    >>
    >> The compiler errors are as follows:
    >>
    >> ||=== Build: Release in fgw (compiler: GNU GCC Compiler) ===|
    >> /home/n/tutorial/source/playpen_unix1.cpp||In constructor
    >> ?{anonymous}::HueRGB256::HueRGB256()?:|
    >> /home/n/tutorial/source/playpen_unix1.cpp|82|error: ?memset? was not
    >> declared in this scope|

    > ...
    >> So both errors relate to 'memset' not being declared. Can anyone see how
    >> I can correct this?

    >
    > memset comes, according to my C language man pages, from <string.h>,
    > so #include <cstring> and call it std::memset and you should be fine.
    >
    > But note that it's a slightly bad idea to do what the author does here:
    > initializing an array of HueRGB objects by paving it over with 0 bytes.
    >
    > Give HueRGB a default constructor and you don't have to do anything
    > here. Or, use std::fill() as a "type-aware memset".
    >
    > /Jorgen
    >

    Thanks - for the moment I will leave it as it is because I don't
    understand this code. I got the library compiled now.
     
    nvangogh, May 27, 2014
    #6
  7. On 5/27/2014 12:35 PM, nvangogh wrote:
    > I am trying to build a static library. I am having a problem when I try
    > to compile it. I am getting two errors. The first is at line 82 and the
    > second is at line 120. Both errors seem to be related to the same thing,
    > namely 'memset was not declared in this scope'
    >
    >[..]
    > #include <assert.h>
    > #include <map>
    > #include <stdexcept>
    > #include <stdlib.h>
    > #include <streambuf>



    Add

    #include <cstring>

    >[..]
    > So both errors relate to 'memset' not being declared. Can anyone see how
    > I can correct this?


    Try including the header that has the declaration of it.

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, May 27, 2014
    #7
  8. On Tue, 27 May 2014 17:35:46 +0100, nvangogh <>
    wrote:

    >I am trying to build a static library. I am having a problem when I try
    >to compile it. I am getting two errors. The first is at line 82 and the
    >second is at line 120. Both errors seem to be related to the same thing,
    >namely 'memset was not declared in this scope'


    snip

    > namespace
    > {
    >
    > using namespace studentgraphics;
    >
    > int const key_unknown = 0xFE;
    >
    > //
    >======================================================================
    > // Platform-independant utility classes
    > //
    >======================================================================
    >
    > //
    >**********************************************************************
    > // Inherit privately from this class to disable copy constructor and
    > // assignment operator
    >
    > class CopyDisabler
    > {
    > public:
    > CopyDisabler();
    >
    > private:
    > CopyDisabler(CopyDisabler const&);
    > CopyDisabler& operator=(CopyDisabler const&);
    > };
    >
    > inline
    > CopyDisabler::CopyDisabler()
    > {
    > }
    >
    > //
    >**********************************************************************
    > // The mapping between hue and RGB value
    >
    > struct HueRGB256
    > {
    > HueRGB rgbs[colours];
    >
    > HueRGB256();
    > };
    >
    > HueRGB256::HueRGB256()
    > {
    > memset(rgbs, 0, sizeof(HueRGB) * colours);
    >-----------------------------
    >
    >The compiler errors are as follows:
    >
    >||=== Build: Release in fgw (compiler: GNU GCC Compiler) ===|
    >/home/n/tutorial/source/playpen_unix1.cpp||In constructor
    >‘{anonymous}::HueRGB256::HueRGB256()’:|
    >/home/n/tutorial/source/playpen_unix1.cpp|82|error: ‘memset’ was not
    >declared in this scope|
    >/home/n/tutorial/source/playpen_unix1.cpp||In member function ‘void
    >{anonymous}::pixels::Clear(studentgraphics::hue)’:|
    >/home/n/tutorial/source/playpen_unix1.cpp|120|error: ‘memset’ was not
    >declared in this scope|
    >/home/n/tutorial/source/playpen_unix1.cpp||In member function ‘void*
    >{anonymous}::SingletonWindowImpl::WorkerThread()’:|
    >/home/n/tutorial/source/playpen_unix1.cpp|685|warning: suggest
    >parentheses around comparison in operand of ‘&’ [-Wparentheses]|
    >/home/n/tutorial/source/playpen_unix1.cpp|330|warning:
    >‘{anonymous}::SingletonWindowImpl::instance_’ defined but not used
    >[-Wunused-variable]|
    >||=== Build failed: 2 error(s), 2 warning(s) (0 minute(s), 11 second(s))
    >===|
    >--------------------------------
    >
    >So both errors relate to 'memset' not being declared. Can anyone see how
    >I can correct this?


    Could it be because memset is in the std namespace and you are not?
    Would std::memset(..) work?

    Recommend including the C++ headers cassert and cstdlib instead of the
    C headers as coded.

    --
    Remove del for email
     
    Barry Schwarz, May 27, 2014
    #8
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    1,254
    red floyd
    May 10, 2005
  2. Replies:
    2
    Views:
    7,272
    Maett
    May 16, 2005
  3. iceColdFire

    Static library Vs. Dynamic library

    iceColdFire, May 17, 2005, in forum: C++
    Replies:
    3
    Views:
    17,376
  4. Even

    static library and dynamic library

    Even, Oct 18, 2007, in forum: C Programming
    Replies:
    6
    Views:
    894
    Mark McIntyre
    Oct 20, 2007
  5. £ukasz Z±bik
    Replies:
    1
    Views:
    384
    tragomaskhalos
    Jan 21, 2008
  6. Torsten Mohr
    Replies:
    5
    Views:
    417
    Torsten Mohr
    Feb 25, 2004
  7. DJ Stunks
    Replies:
    0
    Views:
    522
    DJ Stunks
    Feb 10, 2007
  8. Jonatan Magnusson
    Replies:
    0
    Views:
    208
    Jonatan Magnusson
    Feb 11, 2013
Loading...