Avoiding absolute paths including headers

I’ve ordered a bit my structure of classes and moved the related ones to more specific folders. The problem is that now the includes I made are not being able to find the class, as right now is in another folder.

Why is it not looking automatically for the file through all the folders?

I shouldn’t have to write #include “Gameplay/TestMap.hpp”. How can I avoid this?

I’ve got this in my makefile (I don’t know if it might be related):

LOCAL_SRC_FILES := hellocpp/main.cpp \
               ../../Classes/Engine/AppDelegate.cpp \
               ../../Classes/Gameplay/TestMap.cpp \
               ../../Classes/Gameplay/Player.cpp \
			   ../../Classes/Gameplay/Camera.cpp \
               ../../Classes/Gameplay/UI/HUD.cpp \
			   ../../Classes/Gameplay/UI/Joystick.cpp 

Thanks

yeah … :smile:

thats because initially it finds all the files i.e. the .cpp and .h files are searched on the classes folder but you’ve made specific folders

So in order to search the class files there you need to set the path by hardcoding as you don’t want to do

the other way is to route to these folders by default
which can be done by opening the jni folder and android.mk file inside it

search for

LOCAL_SRC_FILES := hellocpp/main.cpp \
               ../../Classes/AppDelegate.cpp \
               ../../Classes/HelloWorldScene.cpp

and add these lines, see the changes

LOCAL_SRC_FILES := hellocpp/main.cpp \
               ../../Classes/Engine/AppDelegate.cpp \
               ../../Classes/Gameplay/all_classes_under_Gameplay_folder.cpp

Build and run the project, it should work fine by now.

I hope it helps.
Happy Coding :wink:

That change in android.mk is what I’ve got. See my makefile, is just what you are proposing. And it is not working…

LOCAL_SRC_FILES := hellocpp/main.cpp \
           ../../Classes/Engine/AppDelegate.cpp \
           ../../Classes/Gameplay/TestMap.cpp \
           ../../Classes/Gameplay/Player.cpp \
		   ../../Classes/Gameplay/Camera.cpp \
           ../../Classes/Gameplay/UI/HUD.cpp \
		   ../../Classes/Gameplay/UI/Joystick.cpp

try changing this, not sure but might work
atleast it would save your time , by the time some pro looks at your pull request.

Try this.

same process but see the file under it in same android.mk

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes

try changing it something like this

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes\
../../Other Folders

What does your LOCAL_C_INCLUDES looks like ?

It should be at least:

LOCAL_C_INCLUDES := ../../Classes/Engine \
                    ../../Classes/Gameplay \
                    ../../Classes/Gameplay/UI \

yes… i was suggesting him that…

so @Fradow your suggestion plus that change in the LOCAL_SRC_FILES

or changes in the LOCAL_C_INCLUDES only… ??

The error indicates that the compiler can’t find a header, that’s the role of LOCAL_C_INCLUDES, which tells the compiler where to search for headers, which means all *.h and *.hpp files.

From the screenshot, the LOCAL_SRC_FILES is missing GameMap.cpp, I would add this too. The LOCAL_SRC_FILES is for source files, which means all *.c and *.cpp files. The compiler is going to complain later on, during the linking phase.

1 Like

You are so right. I was not updating the LOCAL_C_FILES, just the sources… Now is working!

Is there any way to not have to be updating all the time the makefile having to add the headers/sources every time?

I’m using windows.

Really thanks!!

EDIT:

I’ve found this scripts, but they are not working for me, I don’t know if it’s because the ‘find’ of windows does not work as in unix:

CPP_FILES := $(shell find $(LOCAL_PATH)/../../Classes -name *.cpp)
LOCAL_SRC_FILES := hellocpp/main.cpp
LOCAL_SRC_FILES += $(CPP_FILES:$(LOCAL_PATH)/%=%)

HPP_FILES := $(shell find $(LOCAL_PATH)/../../Classes -name *.hpp)
LOCAL_C_INCLUDES += $(HPP_FILES:$(LOCAL_PATH)/%=%)

It says: “can’t find the .cpp/.hpp file”

no… make it yourselves
it will be developed into an habbit and lessen the chances of error in the future… :smile:

dont depend on codes. instead make it an habbit it will help you to learn and understand cocos2d-x more… :smile:

I dont see how it is going to make me understand better cocos… and to reduce the chances of errors, lol.

@pabitrapadhy is right, you need to understand what’s going on to progress.

So, you are calling “shell”, which probably means it’s going to use the native prompt (in your case windows’s command prompt).

Then it calls “find”. As you said, it doesn’t work the same on Windows. Let’s look at the documentation.
http://lmgtfy.com/?q=windows+find Second link: http://www.computerhope.com/findhlp.htm

Here is the interesting part
“Additionally, this command is used to find text within a file, not the actual file itself. If you are wanting to search or find a file with a particular name, use the dir command.

From that you should be able to change the script to work on Windows. A good test is to open the command prompt, go to LOCAL_PATH and try the command there: you can test it until it works.

1 Like

Hi there.

After getting really tired of the makefile, I decided to do it manually. But now, I tried again to generate it automatically with windows and I am still not able to do it. If I do it through the ‘cmd’ the script I wrote in the other post works perfect. It gives you a list of all the .cpp files with their path, just what I’m writing manually in the makefile. But is not working, aparently is not finding anything. I don’t really know how to debug this. I don’t know too much about promt.

I would really appreciate some help here.

Thanks

Hello,

In my previous post, I outlined that on Windows, you should be using the “dir” command.

You probably have a modified terminal that execute unix command, but then when ndk-build use the standard Windows one, it’s not working anymore.