Search code examples
log4cxx

How to fix 'memmove' not declared error in log4cxx


I am trying to cross-compile log4cxx for ARM from a x86_64 machine. During compilation, there is an error saying 'memmove' was not declared in this scope.

I am using a Linaro GCC cross-compiler version 4.9.4. In order to prevent a different issue with the cross-compilation, I am giving CPPFLAGS=-DAPR_IOVEC_DEFINED to the configure command. This is version 0.10.0 of the log4cxx source, as downloaded from the Apache Logging Services website.

The full error message is below:

inputstreamreader.cpp:66:64: error: 'memmove' was not declared in this scope
              memmove(buf.data(), buf.current(), buf.remaining());

I know that the "not declared" error usually indicates that the file with the declaration was not included, but it seems unlikely that this would be an issue in the released code.


Solution

  • This error is due to missing include paths in the file, although commit messages in the log4cxx Git repository suggest that the error only occurs with certain versions of the GCC compiler.

    To fix the error, add the following includes to src/main/cpp/inputstreamreader.cpp:

    #include <cstdio>
    #include <cstring>
    

    These includes are present in the most recent version of the file, found on the log4cxx Github repo. The addition of those includes is the only non-formatting change to the file since version 0.10.0. In the commit history of the file, there are mentions of issues with GCC 4.3 and 4.4 due to those missing includes.

    I also experienced other not declared errors from other files in log4cxx. They can be fixed in the same fashion and have been fixed in the Github repo.