3
votes

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
2
you need to add <string.h> header - if you haven't done so already? Also, do this g++ -g -Wall example.cpp -o example.o -lmpfit -lm. Please show us how you are doing memset with the actual printout of the message.ha9u63ar
Yes, I have already added <string.h>. I still see the same error. By adding -g -Wall in the compilation order I additionally got this error: example.cpp:59:10: warning: unused variable ‘pactual’ [-Wunused-variable]Ángel Piñeiro
That code snippet will not compile by itself. You need to insert it as a part of a function - "example 8" shows a pretty complete program which should compile out-of-the-box.Daniel Kamil Kozar
You should use std::memset();.Galik
The code I am currently trying to compile is exactly that of the example 8 in the web site. I only added the line #include <string.h> to the head. The error message I got is: example.cpp: In function ‘int main(int, char**)’: example.cpp:66:34: error: ‘memset’ was not declared in this scopeÁngel Piñeiro

2 Answers

8
votes

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>
1
votes

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.