How to compile class.cpp and class.hpp to one .o file? If I can, please tell me how. If I can't, please tell me what should I do if I want to do something similar. These are the latest version of my classes(they're not completed yet.): OptionParser.cpp, OptionParser.hpp.
Asked
Active
Viewed 606 times
-5
-
2`cpp -c mycpp.cpp`. This is all documented. – user207421 Feb 18 '20 at 05:06
-
2Please don't post code behind links. Post it directly in the question instead. See [ask]. Please also produce a [repro] for your issue and explain what exactly doesn't work. Compiling a `.hpp` usually doesn't make any sense, so it is not clear what your problem is. – walnut Feb 18 '20 at 05:11
-
1I recommend adding what development tools are you using. The exact build instructions change from [toolchain](https://en.wikipedia.org/wiki/Toolchain) to toolchain, but any of the common tools that produces a .o file will all be very similar to what my fellow anonymous user suggested. – user4581301 Feb 18 '20 at 05:32
-
Side note: If your destructor does nothing, and this one doesn't and doesn't look like it needs to do anything, [the Rule of Zero](https://en.cppreference.com/w/cpp/language/rule_of_three) suggests that you leave it out or explicitly default it. The Rule of Zero and it's friends Three and Five are very important. I recommend familiarizing yourself with them. – user4581301 Feb 18 '20 at 05:36
-
Here I reply to all of you. user207421, thank you for your early reply. walnut I did so is because I might change some of the contents in the files so if you view it on github it'll always be the latest version. user4581301 thank you for your suggestion. I'm using clang on mac. But, I might change to mingw-w64 on windows in the future because I also want it usable on windows. – Chrimpyslime Feb 18 '20 at 05:48
-
2_I did so is because I might change some of the contents in the files so if you view it on github it'll always be the latest version._ That doesn't make much sense for SO. Imagine somebody answers your question but meanwhile you updated the code. Now, the answer might not match anymore and anybody in the future would be confused... ;-) – Scheff's Cat Feb 18 '20 at 07:42
-
@Chrimpyslime Questions on Stackoverflow generally should be self-contained and stable. They should be helpful for others that might be reading it in a few months or years. You can leave your links to support the question, but you should include code for a [repro] directly in the question. You can edit your question to improve it by clicking "*edit*" below it or [here](https://stackoverflow.com/posts/60274039/edit). – walnut Feb 18 '20 at 09:31
1 Answers
1
To do so you need to just include class.hpp to you class.cpp file. It can be done like
#include "class.hpp"
So you just need to have both in same folder and after that you need to add above line in class.cpp and then just compile and run the executable.

Akhil Pathania
- 542
- 2
- 5
- 19