Trouble compiling on Android

Trouble compiling on Android
0.0 0

#21

Having the same error as @anieduard after updating to 3.15. Tried to build with NDK r10c, r11c, r14b.


#22

I had the same problem when using prebuilt libraries for 3.15 today on Windows 10 in my test project. Error states exactly what is the problem - both flatc.cpp and flathash.cpp have defined main() function in them and both are compiled and added to the same library flatbuffers.a. Linker does not know which main() of the two it has to refer to from your code and fails with the error. It looks like a bug to me in cocos2d-x, so I removed flatc.cpp file from external/flatbuffers/Android.mk and external/flatbuffers/CMakeLists.txt (I am not sure if editing CMakeLists.txt is really needed) and rebuilt prebuilt library again.

Excerpt from edited external/flatbuffers/Android.mk:

LOCAL_SRC_FILES :=
#flatc.cpp
flathash.cpp \

And I could then successfully compile the prebuilt libraries and use them in my test cocos2d-x project.
I would like to point out that it might be that not flatc.cpp file should be removed from library, but flathash.cpp instead, so if you face issues, try comment out flathash.cpp. If you’d look at sources of 3.14.1, you could see that flathash.cpp is not there, so it is a new file in 3.15.
Anyone who is more familiar with the source could elaborate more whether this is really a bug.

Good luck.


How to link prebuilt Cocos2D X C++ library to Android Studio project?
#23
/Users/piotr/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/arm-linux-androideabi/bin/ld
Error:error: /Users/piotr/Documents/pierdoly/cocos2d-x-3.15/external/flatbuffers/prebuilt-mk/../../../prebuilt/android/armeabi-v7a/flatbuffers.a(flathash.o): multiple definition of 'main'
Error:error: linker command failed with exit code 1 (use -v to see invocation)

the same problem…
edit:
@inkus your fix works. App is running, yet sigh… now in 3.15 all labels disappeared.