0

I have a simple log macro, this is the .h file :

#ifndef __LOGGER_H
#define __LOGGER_H

#define LOG_ERROR(errorMsg) logError(__FILE__, __LINE__, errorMsg)

#endif

...and this is the .c file :

#include <stdio.h>
#include "Logger.h"

void logError(const char* filename, int line, const char*   errorMsg)
{
    printf("[File : %s] - [Line: %d} - [Error Message : %s]\n", filename, line, errorMsg);
}

When I use the macro in a .c file :

#include <Common/Logger.h>

void func(int index, int value)
{
    if (IsIndexOutOfRange(index, NUMBER_OF_PARAMS))
    {
        LOG_ERROR("Index out of range!");
        return;
    }
    .
    .
    .
}

...and build (vs2013) I get : warning C4013: 'logError' undefined; assuming extern returning int

Warning C4013 usually means that you forgot to include the correct library or need to use extern. I suspect I need extern somehow, but do not know how to fix this with a macro.

How do I solve this?

Lasse
  • 51
  • 4
  • http://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration – fukanchik Jan 08 '16 at 21:40
  • 3
    prototype of `logError` put on your header. – BLUEPIXY Jan 08 '16 at 21:45
  • _Warning C4013 usually means that you forgot to include the correct library or need to use extern._ - No. It means you're using a function which, while compiling _this_ source file, the compiler has not seen already so it cannot be sure what the function (parameters and return value) looks like. If you prototype the function in `` then the compiler will see the prototype before you actually make use of it in your sources that include that header. – mah Jan 08 '16 at 21:56
  • Thanks @BLUEPIXY that solved it. – Lasse Jan 08 '16 at 21:57

0 Answers0