0

I'm getting an error about my AppDelegate cannot be found.
"The error is something like: No rule to make target *.cpp needed by *.o"

My Android.mk looks like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp

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

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


I don't know what's wrong. I'm guessing it's because i'm not setting the path to the Classes right. In the package explorer my structure looks like this: screenshot of package explorer



In my real folder structure, the Classes folder is not inside proj.android. It's in a folder located outside.

Folders for Classes and MobileApp Folders for Classes and MobileApp

------------------------------------------------------------------------------------------------
Inside MobileApp Inside MobileApp

------------------------------------------------------------------------------------------------
Inside proj.android where jni is located
Inside proj.android where jni is located

I'm not really sure how i to link my .ccp class files properly. How do I add them as my local files so I can build it properly? I would appreciate all the help I could get. Thanks.

cessmestreet
  • 2,298
  • 3
  • 22
  • 42
  • `AppDelegate.o` is already existed. Clean or delete `proj.android/obj` before you build it. – GaloisPlusPlus Feb 19 '16 at 04:11
  • What if you use `$(LOCAL_PATH)/../../Classes/AppDelegate.cpp` ? – Michael Feb 19 '16 at 08:38
  • @Michael i tried this ../../../Classes/AppDelegate.cpp it worked. but the problem is i had to type my classes one by one. Is there an easier way? – cessmestreet Feb 19 '16 at 09:27
  • `$(wildcard ../../../Classes/*.cpp)` – Michael Feb 19 '16 at 09:31
  • `wildcard` cannot handle `../../../Classes//*.cpp`. In that case, you can use the [recursive wildcard](http://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make/18258352#18258352) provided by @larskholte. [Here](http://stackoverflow.com/questions/18348969/android-mk-build-all-source-file-in-a-directory/25524275#25524275) is an example used in cocos2d-x project. – GaloisPlusPlus Feb 19 '16 at 10:41
  • @GaloisPlusPlus thank you but the files are not inside LOCAL_PATH/x/x. The files are located outside in another directory. I found this from the answer: rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) SRC_PATH_CLASSES := $(call rwildcard, ../../Classes/, *.cpp) LOCAL_SRC_FILES += $(SRC_PATH_CLASSES:$(LOCAL_PATH)/%=%) Sorry I don't know much about these things. – cessmestreet Feb 22 '16 at 03:46
  • @GaloisPlusPlus does ../ means move up like go to parent directory? – cessmestreet Feb 22 '16 at 03:51
  • @cessmestreet Yes. In your case, you can replace the `SRC_PATH_CLASSES` with `SRC_PATH_CLASSES := $(call rwildcard, ../../../Classes/, *.cpp) `. – GaloisPlusPlus Feb 23 '16 at 03:24
  • @cessmestreet Another tips. If you are not sure whether `LOCAL_SRC_FILES` is correctly set or not, you can use `$(warning $(VAR))` to print related variables like `LOCAL_PATH`, `LOCAL_SRC_FILES`, etc. – GaloisPlusPlus Feb 23 '16 at 03:30

1 Answers1

-1

It's a little hard to tell from your screenshots, but it looks like the Classes and jni directories are in the same parent directory. If that's true, you only need one '../' to go back up to the parent directory. Basically, I think you want to change all your paths to Classes to '../Classes/'. It looks like the path to cocos2d should be changed the same way.

Also, you're missing the last line of a module, which would be include $(). For example, if you want to build a dynamically linked library for your C++ code, you should add this line to the end of Android.mk:

include $(BUILD_SHARED_LIBRARY)

You can see some example Android.mks here, and the relevant Android documentation here.

Francesca Nannizzi
  • 1,695
  • 13
  • 18