I've been searching for how to do this for nearly an entire day.
At first, I thought that this can be done by...
Right click the project name -> "Add files" -> choosing a .cpp file which contains the class you need and the corresponding header file
.
Then, the .cpp file and header file appeared with its original folder. After this, I wrote #include"random.h"
on the project which needed to use random.h
and its functions.
However, this produces an error, indicating that fatal error: random.h: No such file or directory
. The compiler apparently can't find the file (even though I can).
I add a picture of this.
Also, I've been looking for how to add .cpp & header files without its folder.
(In the picture above, for example, you'll see that random.cpp
inside Using_a_class_test
is included in a folder named Random
. To my shame, I haven't found how to eliminate such a folder.)
I'd appreciate if you'd offer any insight.
Unfortunately, what you did is not enough. When you try to compile
#include "random.h"
The compiler needs to know where the random.h
file is, and for that it uses the include path info, which is unrelated to the files you included in the project.
A couple of solutions:
#include "random.h"
to be #include "/path/to/random.h"
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With