error: ‘memset’ was not declared in this scope

Ángel Piñeiro picture Ángel Piñeiro · Nov 9, 2014 · Viewed 17.3k times · Source

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

Answer

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>