0

Files not linking in C++

So I'm taking the C++ Intermediate Course. I use Android mobile. I was taking the "Seperate Files for Classes" lesson in the course where they said about creating seperate file for the prototypes (.h) and creating a source file that uses that file(.cpp). I did it in QuickEdit and some tried some other apps, but all of them were returning error that they could not find the file. Please note before replying: • My files were in the same folder together, no different folders or subfolders. • I'm using Android Phone • The file name for linking and the file's name are exactly the same, with matching case When I run the code, I get this error: main.cpp:2:10: fatal error: 'MyClass.h' file not found #include "MyClass.h" ^~~~~~~~~~~ 1 error generated.

25th Nov 2024, 3:03 AM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
7 ответов
+ 2
I tried to simulate your situation, and it's true QuickEdit didn't get the thing done, not sure why though. But good news is - it does work in Cxxdroid app. Just a class declaration in header (with only 1 public method for testing), definition of the public method (of the class) in source, object instantiation in source (main function), and a method call, that's it :)
25th Nov 2024, 9:46 AM
Ipang
+ 1
Since it is a "file not found" error, then the problem has to be with finding the file. If your main.cpp is in a subfolder, maybe add that to the include path and see if that helps. If you are using Linux, make sure your filename is MyClass.h and not myclass.h. Make sure the filename matches and matches case.
25th Nov 2024, 4:02 AM
Jerry Hobby
Jerry Hobby - avatar
+ 1
Afnan Irtesum Chowdhury what app are you using? Folder access is very restricted on Android phones. It might be a permissions issue. If you read the lessons carefully, Sololearn assumes you are using CodeBlocks on a pc.There is even an intruction on how to set it up. That part was not meant to be run on Sololearn. You can learn the basics in your phone, but to really complie and run programs, you will need a pc or a laptop.
25th Nov 2024, 8:57 AM
Bob_Li
Bob_Li - avatar
0
If you are on Linux, you should probably add it this way..... #include "./MyClass.h"
25th Nov 2024, 6:59 AM
Jan
Jan - avatar
0
Jan Jerry Hobby I'm on Android, Phone. And the files are in the same folder together as I already said
25th Nov 2024, 7:15 AM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
0
Afnan Irtesum Chowdhury Android is based on Linux, even though it's written in Java, so you should probably still use the method I mentioned.
25th Nov 2024, 8:16 AM
Jan
Jan - avatar
0
Jan I tried your method too. Both using the same-folder path like "./MyClass.h" and also the whole storage path like "storage/emulated/..." But it doesn't work
25th Nov 2024, 8:31 AM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar