I'm trying to compile a C++ project imported from Dev-C++ to Netbeans. I'm using MinGW under Win XP x64. I didn't like Netbeans' makefile so I wrote my own.
But when I run make (either through Netbeans or the command line), I get this:
In other words, the header "log.h" is being included twice (once for angles.cpp and another one for debug.cpp). How can I prevent this from happening?
log.h will be #included in whatever files you put #include "log.h" in. If you #include in both angles.cpp and debug.cpp, then it will be included in both.
However this is not a problem. It's actually kind of the whole point of using .h files.
Anyway... your problem is not what you think it is. According to the errors, I'm deducing that _LOG is defined twice in log.h, and is defined differently each time. See how the errors point to different lines:
D:/My Documents/c/src/log/log.h:486: error: redefinition of `struct _LOG'
D:/My Documents/c/src/log/log.h:483: error: previous definition of `struct _LOG'
It's erroring on line 486, saying that _LOG was already defined on line 483. So probably one of those lines is the problem.
If you could paste all lines between 480 and 490 or so of log.h, I'd be able to help further.
Thank you for your help. Log.h is correct, I know that for sure.
However, I was mistaken about make's behaviour. I tried:
make debug.o
and got the same result, so I thought there must be something wrong with the debug stuff. I checked, and I found that I was #including log.h three times! (from different headers).
debug.h:
1 2
#include "coordlist.h"
#include <log/log.h>
coordlist.h
1 2
#include "auxiliar/angles.h"
#include <log/log.h>
angles.h
1 2
#include <cmath>
#include <log/log.h>
I fixed it by deleting the redundant #includes in debug.h and coordlist.h. But that doesn't seem like an elegant solution to me. #pragma once is supposed to prevent this stuff from happening, isn't it?
If the header has that, you can #include it a million times over and it won't matter, only the first will be used. I have no idea what #pragma once does -- I avoid #pragma like the plague.
This sounds mighty fishy to me.... but if it's working now I guess that's a good thing.