Error: ‘memcmp’ was not declared in this scope!

Here is a problem that I occasionally come across while compiling. Since it is so common for me to see this, I would like to re-iterate an earlier post I made about this problem. Before I only mentioned it in brief, and here I would like to break it down just a little bit more. I thought I had previously gone over this in detail, but I couldn’t find it in my posts, so I decided to talk about it here.

There are ways that this problem can manifest himself, but the overall problem is that the header file “strings.h” was not included in the build. It may be something that was supposed to be declared elsewhere, or added in later, but in either event, it is not present and cannot perform the actions required. Let’s take a look at the error itself:

[CODE]
device/samsung/jf-common/gps/utils/loc_target.cpp: In function ‘unsigned int loc_get_target()’:
device/samsung/jf-common/gps/utils/loc_target.cpp:208:53: error: ‘memcmp’ was not declared in this scope
if( !memcmp(baseband, STR_AUTO, LENGTH(STR_AUTO)) )
^
device/samsung/jf-common/gps/utils/loc_target.cpp:214:51: error: ‘memcmp’ was not declared in this scope
if( !memcmp(baseband, STR_APQ, LENGTH(STR_APQ)) ){
^
make: *** [/home/alaskalinuxuser/Documents/projects/phones/compile/aokp6/out/target/product/jfltetmo/obj/SHARED_LIBRARIES/libgps.utils_intermediates/loc_target.o] Error 1
make: *** Waiting for unfinished jobs….
make: Leaving directory `/home/alaskalinuxuser/Documents/projects/phones/compile/aokp6′

#### make failed to build some targets (28:01 (mm:ss)) ####
[/CODE]

What memcmp is supposed to do is compare memory areas. So the code is asking the compiler to make a memory comparison, and the compiler says it doesn’t know how! To fix this problem, you need to add this line to device/samsung/jf-common/gps/utils/loc_target.cpp:

[CODE]
#include <string.h>
[/CODE]

And then put the file string.h in the device/samsung/jf-common/gps/utils/ directory. Simple, you say, but where do I get the string.h file? That part is actually pretty simple. You can download it here: http://linux.die.net/include/string.h and save it where you need it to be. This file will also solve errors about:

strerror, strerror_r – return string describing error number
strlen – calculate the length of a string
strcpy, strncpy – copy a string
strcmp, strncmp – compare two strings
and others!

The main takeaway from this is that any “not declared in this scope” errors should be run through the http://www.die.net/search/ website to see what code pieces are missing. It will show you what header files are needed to perform that function, which is really handy!

Linux – keep it simple.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s