-2

As you see in the following image, when I comment one of the include "gui.cpp" or include <gui.cpp>, I have a red cross error in the right side of using namespace GUI. but when I include both of them, the error removed. Does anyone have any idea?

enter image description here

Ebrahim Ghasemi
  • 5,850
  • 10
  • 52
  • 113
  • 1
    1) This is not C. 2)People are not including `cpp` files, usually.3) Nothing weird here if we assume that `cpp` is referencing some function or type, that is prototyped after that reference. – Eugene Sh. Jun 12 '15 at 19:35
  • Also, the use of "" as opposed to <> may cause the compiler to use a different lookup path, so the .cpp files might be in different directories. – Lee Daniel Crocker Jun 12 '15 at 19:37
  • Your compiler might be sensitive about leading spaces before a `#`. I notice you are also inconsistent about a space between `#include` and `"target"` or `` and although legal, your colour syntax highlights don't like it. Please be consistent in your source formatting - such attention to detail has a good knock-on effect. – Weather Vane Jun 12 '15 at 19:41
  • Usually `cpp` files are not included but compiled as separate translation units then linked together. Does the Keil compiler require everything in a single CPP file? – Thomas Matthews Jun 12 '15 at 19:42
  • @EugeneSh. The problem is that I need to include both of them! why? Is not it weird?! – Ebrahim Ghasemi Jun 12 '15 at 19:46
  • Down-voters please leave a comment please! – Ebrahim Ghasemi Jun 12 '15 at 19:47
  • @Abraham Have you read my comment fully? Or just the numbers? – Eugene Sh. Jun 12 '15 at 19:47
  • @EugeneSh. I think I didn't understand point 3. Did you mean that the file `"gui.cpp"` is different from `? - about point 1: Okay. - about point 2 : as you said it is not illegal anyway – Ebrahim Ghasemi Jun 12 '15 at 19:50
  • Anyway, why do you bother understanding the behaviour of some GUI confused with some use-cases it is not built for? Why not to focus on the important things? – Eugene Sh. Jun 12 '15 at 19:54
  • @EugeneSh. I don't know! I'm not the programmer, someone sent me this question. – Ebrahim Ghasemi Jun 12 '15 at 19:56
  • @Abraham Are you somehow responsible for the Keil GUI? If not, just forward him my last comment :) – Eugene Sh. Jun 12 '15 at 19:58
  • Quick refresher on what `#include` does. It takes whatever file is being included and pastes its contents in at the top of the including file unless blocked by an include guard or some other preventative macro. So when you `#include ` in main.cpp, you duplicate everything in file.cpp in main.cpp. Usually this leads to variables and functions being declared twice, once when you link file.cpp and the other in main.cpp. Chaos ensues and linker error messages abound. – user4581301 Jun 12 '15 at 20:02

1 Answers1

1

Don't include .cpp files, or any source files. You should only include header files. Let the linker deal with source files.

You should create a gui.h and include that instead.

twentylemon
  • 1,248
  • 9
  • 11