problem compiling static library


N

nvangogh

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
 
Ad

Advertisements

N

nvangogh

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

#include <cstring>
using std::memset;
 
J

Jens Thoms Toerring

nvangogh said:
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
 
J

Jorgen Grahn

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
 
N

nvangogh

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
 
N

nvangogh

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

Advertisements

V

Victor Bazarov

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 said:
[..]
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
 
Ad

Advertisements

B

Barry Schwarz

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))
===|

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.
 

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

Top