0

I am trying to write a relativity big code. The main problem, for awhile, is that there is a problem occurring when I define a dictionary.

I have a .hh file named Electric.hh. This is what is inside of it:

#ifndef Electric_h
#define Electric_h 1

namespace Ele{
    static constexpr double zfield = 80;
}

#endif

I have defined the Ele namespace, and the zfield variable, so that I can use it in another folder.

Now, the problem is: I have a file called Tracker.cc which uses this variable:

#include "Electric.hh"
...
auto hx = Ele::zfield;
std::ofstream cFile (std::to_string(hx)+".txt", std::ofstream::app);
...

Now, when I do make at the terminal so that the program runs, the first time it runs well, that is, it creates a file named 80.txt. The problem is, now suppose I change the content inside of Electric.hh, so that instead of:

static constexpr double zfield = 80;

I use:

static constexpr double zfield = 40;

When I do make again (after do cmake ) on the terminal, and try to run the program again, it seems that the file Tracker.cc has stored the value 80, that is, it does not create any file named 40.txt, but creates another file named 80.txt. I am extremely confused why. Shouldn't it forget the value 80 after I do make? What is wrong with my code?

1 Answer 1

1

You forgot to tell in the Makefile that Tracker.cc depends on Electric.hh. So on the second make call nothing gets recompiled.

With gcc/clang you can create those dependencies on included files automatically, which is well worth it.

Sign up to request clarification or add additional context in comments.

4 Comments

OOps. I forgot to tell, i do cmake. before write make. Shouldn't it change?
Same problem though. The default will check Tracker.o vs. Tracker.cc and recompile if the source is newer. You have to tell it bout the include.
I see. I fear that i have no idea how to edit the Makefile so as to include it :( Any tips? link recomendations?
no idea. read the cmake documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.