I have a strange problem. I have those files:
lib.h:
#ifndef _LIB_H_
#define _LIB_H_
double fun(int a);
#endif
lib.c:
#include "lib.h"
#include <stdio.h>
#if !defined(MY_FUN) && ((defined(__MINGW32__) || defined(__MINGW64__)) && defined(_X86_))
#define MY_FUN
double fun(int a)
{
printf("%d\n", a);
}
#endif
main.cpp:
#include "lib.h"
int main(int argc, char **argv)
{
fun(2);
return 0;
}
When I run such code on Windows, I have an error: undefined reference to fun
. On Linux (Ubuntu) its ok, compiling without errors. When I put everything in one file (on Windows) its ok as well. But I need to have it in separete files. How to make it right? On Windows Im using MinGW with Code::Blocks.