Error memset was not declared in this scope

I am trying to compile my C program in Ubuntu 9.10 (gcc 4.4.1). I am getting this error: Rect.cpp:344: error: ‘memset’ was not declared in this scope But the problem is I have already included i...

I am trying to compile my C program in Ubuntu 9.10 (gcc 4.4.1).

I am getting this error:

Rect.cpp:344: error: ‘memset’ was not declared in this scope

But the problem is I have already included in my cpp file:

#include <stdio.h>
#include <stdlib.h>

And the same program compiles fine under Ubuntu 8.04 (gcc 4.2.4).

Please tell me what am I missing.

Paul R's user avatar

Paul R

206k35 gold badges381 silver badges549 bronze badges

asked Mar 24, 2010 at 4:38

michael's user avatar

3

You should include <string.h> (or its C++ equivalent, <cstring>).

answered Mar 24, 2010 at 4:40

sth's user avatar

sthsth

218k53 gold badges277 silver badges364 bronze badges

Whevever you get a problem like this just go to the man page for the function in question and it will tell you what header you are missing, e.g.

$ man memset

MEMSET(3)                BSD Library Functions Manual                MEMSET(3)

NAME
     memset -- fill a byte string with a byte value

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <string.h>

     void *
     memset(void *b, int c, size_t len);

Note that for C++ it’s generally preferable to use the proper equivalent C++ headers, <cstring>/<cstdio>/<cstdlib>/etc, rather than C’s <string.h>/<stdio.h>/<stdlib.h>/etc.

answered Mar 24, 2010 at 7:40

Paul R's user avatar

Paul RPaul R

206k35 gold badges381 silver badges549 bronze badges

0

I am trying to compile the complete example 8 provided at the end of this page: http://www.physics.wisc.edu/~craigm/idl/cmpfit.html

but I am getting this error: error: ‘memset’ was not declared in this scope

I have been looking how to solve this error and I saw that some people solved it by adding #include <string.h> to the head of the code. I tried it but I am still getting the same error.

I am using gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) on Ubuntu 12.04 LTS

I am trying to compile with:

g++ -o example example.cpp -lmpfit -lm

Mat's user avatar

Mat

200k40 gold badges389 silver badges404 bronze badges

asked Nov 9, 2014 at 20:02

Ángel Piñeiro's user avatar

7

If you use C you should include string.h

Otherwise, if you use C++ you should use cstring

C: #include <string.h>

C++: #include <cstring>

answered Nov 9, 2014 at 20:08

Efstathios Chatzikyriakidis's user avatar

5

I updated gcc to gcc-4.9 and I could compile just adding «#include » to the head of the code. Then I tried with gcc-4.8 and gcc-4.7, and again I was able to compile the code with no problem. Perhaps my previous compiler (gcc-4.6) was not correctly installed?¿. I will keep working with the last version of gcc. Thank you all for your help.

answered Nov 11, 2014 at 16:14

Ángel Piñeiro's user avatar

Ángel PiñeiroÁngel Piñeiro

511 gold badge1 silver badge4 bronze badges

I tried to compile version 2.2.1 on Arch Linux and during the make command, I ran into these errors:

g++ -c -pipe -std=c++11 -O2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -std=gnu++11 -Wall -W -fPIC -DLIBKEYFINDER_LIBRARY -I. -isystem /usr/local/include -I/usr/lib/qt/mkspecs/linux-g++ -o fftadapter.o fftadapter.cpp
fftadapter.cpp: In constructor ‘KeyFinder::FftAdapter::FftAdapter(unsigned int)’:
fftadapter.cpp:43:5: error: ‘memset’ was not declared in this scope
     memset(priv->outputComplex, 0, sizeof(fftw_complex) * frameSize);
     ^~~~~~
fftadapter.cpp:43:5: note: suggested alternative: ‘wmemset’
     memset(priv->outputComplex, 0, sizeof(fftw_complex) * frameSize);
     ^~~~~~
     wmemset
make: *** [Makefile:546: fftadapter.o] Error 1

I tried changing the variables with /usr/local/ at the beginning of the Makefile to /usr/ and I encountered error finding math.h:

g++ -c -pipe -std=c++11 -O2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -std=gnu++11 -Wall -W -fPIC -DLIBKEYFINDER_LIBRARY -I. -isystem /usr/include -I/usr/lib/qt/mkspecs/linux-g++ -o fftadapter.o fftadapter.cpp
In file included from constants.h:25:0,
                 from fftadapter.h:25,
                 from fftadapter.cpp:22:
/usr/include/c++/7.2.1/cmath:45:15: fatal error: math.h: No such file or directory
 #include_next <math.h>
               ^~~~~~~~
compilation terminated.
make: *** [Makefile:546: fftadapter.o] Error 1

Technical Problem Cluster First Answered On
June 5, 2020

Popularity
8/10

Helpfulness
8/10

Contents

Code Examples

  • error: ‘memset’ was not declared in this scope in cpp
  • Compiler error: memset was not declared in this scope
  • Related Problems

  • error: ‘memset’ was not declared in this scope
  • was not declared in this scope
  • TPC Matrix View Full Screen

    error: ‘memset’ was not declared in this scope in cpp


    Popularity

    8/10 Helpfulness
    8/10
    Language
    cpp

    Fragile Fish

    Contributed on Jun 05 2020

    Fragile Fish

    50 Answers  Avg Quality 7/10


    Compiler error: memset was not declared in this scope


    Popularity

    5/10 Helpfulness
    1/10
    Language
    cpp

    Eduardo Larrubia


    Я пытаюсь скомпилировать свою программу C в Ubuntu 9.10 (gcc 4.4.1).

    Я получаю эту ошибку:

    Rect.cpp:344: error: ‘memset’ was not declared in this scope
    

    Но проблема в том, что я уже включил в свой файл cpp:

    #include <stdio.h>
    #include <stdlib.h>
    

    И та же программа отлично компилируется под Ubuntu 8.04 (gcc 4.2.4).

    Скажите, пожалуйста, что мне не хватает.

    2 ответы

    Вы должны включить <string.h> (или его эквивалент на C ++, <cstring>).

    ответ дан 24 мар ’10, в 04:03

    Если у вас возникнет такая проблема, просто перейдите к страница руководства для функции в вопросе, и он скажет вам, какой заголовок вам не хватает, например

    $ man memset
    
    MEMSET(3)                BSD Library Functions Manual                MEMSET(3)
    
    NAME
         memset -- fill a byte string with a byte value
    
    LIBRARY
         Standard C Library (libc, -lc)
    
    SYNOPSIS
         #include <string.h>
    
         void *
         memset(void *b, int c, size_t len);
    

    Обратите внимание, что для C ++ обычно предпочтительнее использовать соответствующие эквивалентные заголовки C ++, <cstring>/<cstdio>/<cstdlib>/ etc, а не C <string.h>/<stdio.h>/<stdlib.h>/так далее.

    ответ дан 16 окт ’15, 13:10

    Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками

    c++
    gcc

    or задайте свой вопрос.

    1. error: ‘memset’ in not declared in this scope

      ‘memset’ is not declared in this scope.

      anyone knows why is this error??

      thanks


    2. Re: error: ‘memset’ in not declared in this scope

      a little information on what youre doing when you get that error would probably help.


    3. Re: error: ‘memset’ in not declared in this scope

      i’m doing the «make». it is a c/s application using multicast DNS


    4. Re: error: ‘memset’ in not declared in this scope

      if you can post the code and the entire error message i can look at it for you.


    5. Re: error: ‘memset’ in not declared in this scope

      her is the error:

      void mDNSObserver::run() {
      int nbytes,addrlen;
      char msgbuf[MSGBUFSIZE];
      cout << «mDNSObserver: running» << endl;
      memset(msgbuf,0,sizeof(msgbuf));
      // Now just enter a read-print loop.
      while (this->keepRunning) {

      i get 2 more and the codes are similar:

      mDNSObserver::mDNSObserver(mNameServer* c): client(c), keepRunning(true) {
      struct ip_mreq mreq;
      u_int yes=1;
      // Set up multicast group destination address for receiving.
      if ((fd4Receiving=socket(AF_INET,SOCK_DGRAM,0)) < 0) {
      cerr << «Problems creating receiving multicast socket» << endl;
      exit(1);
      }
      // Trick just to allow multiple sockets to use the same PORT number: Only to try several processes in the same machine.
      if (setsockopt(fd4Receiving,SOL_SOCKET,SO_REUSEADDR,& yes,sizeof(yes)) < 0) {
      cerr << «Problems: Reusing ADDR failed» << endl;
      exit(1);
      }
      // Set up destination address.
      memset(&addr,0,sizeof(addr));
      addr.sin_family=AF_INET;
      addr.sin_addr.s_addr=htonl(INADDR_ANY); /* N.B.: differs from sender */
      addr.sin_port=htons(MDNS_PORT);
      ….

      and the last

      mDNSQueryWrapper::mDNSQueryWrapper(mNameServer* c): client(c) {
      // Setup the mDNSClient multicast socket. Something similar to an UDP standard socket.
      // Once configured, you only need to call queryWrapper->send(string str) method.
      if ((fd4Sending=socket(AF_INET,SOCK_DGRAM,0)) < 0) {
      cerr << «Problems creating sending multicast socket» << endl;
      exit(1);
      }
      // Set up multicast group destination address for sending. (It’s the same than UDP datagram sending, with an special destination address.)
      memset(&addr,0,sizeof(addr));
      addr.sin_family=AF_INET;
      addr.sin_addr.s_addr=inet_addr(MDNS_GROUP);
      addr.sin_port=htons(MDNS_PORT);
      }


    6. Re: error: ‘memset’ in not declared in this scope

      use code tags.
      and where are the error messages?


    7. Re: error: ‘memset’ in not declared in this scope

      Ok.solved. thanks, but sorry for wasting your time because it was string.h missing lib hehe

      it doens’t hours… hehe

      thxs


    Posted By: Anonymous

    I am trying to compile my C program in Ubuntu 9.10 (gcc 4.4.1).

    I am getting this error:

    Rect.cpp:344: error: ‘memset’ was not declared in this scope
    

    But the problem is I have already included in my cpp file:

    #include <stdio.h>
    #include <stdlib.h>
    

    And the same program compiles fine under Ubuntu 8.04 (gcc 4.2.4).

    Please tell me what am I missing.

    Solution

    You should include <string.h> (or its C++ equivalent, <cstring>).

    Answered By: Anonymous

    Related Articles

    • Ubuntu apt-get unable to fetch packages
    • Maven2: Missing artifact but jars are in place
    • How do you convert CString and std::string std::wstring to…
    • Clang vs GCC — which produces faster binaries?
    • What are the nuances of scope prototypal / prototypical…
    • Specifying java version in maven — differences between…
    • error LNK2005: ✘✘✘ already defined in…
    • Why does C++ code for testing the Collatz conjecture run…
    • Pygame enemy not staying at the intended position on the map
    • Accessing an SQLite Database in Swift

    Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

    Понравилась статья? Поделить с друзьями:
  • Error memory corruption kontakt
  • Error memory configured incorrectly please enter setup for memory information details system halted
  • Error memory cannot be read
  • Error memory access violation scp
  • Error memcpy was not declared in this scope