I'm developing a game that stores data on server in cocos2d-x 3.2 in eclipse c++ for android.
In .h file I include network file #include "network/HttpClient.h".
In .cpp file I wrote following code.
HttpRequest *request = new network::HttpRequest();
request->setUrl("My Url");
request->setResponseCallback(CC_CALLBACK_2(HelloWorld::onHttpRequestCompleted, this));
cocos2d::network::HttpClient::getInstance()->send(request);
But on cocos2d::network::HttpClient::getInstance()->send(request); generate undefined reference to 'cocos2d::network::HttpClient::send(cocos2d::network::HttpRequest*)' this error.
I search it on cocos forum too but i don't get solution of my error.
Thanx in advance.
Not sure if you're still interested in this but all you need to do is add the libnetwork.tbd to your project. For me I used XCode so I just goto Target and then to the Build Phases and add libnetwork.tbd in the "Link Binary with Libraries" section. Then I am able to import "network/HttpClient.h" and using namespace cocos2d::network.
Related
I have an Android native library (C++ code base) called:
libserverapp.so
And I cannot get the Android build to find it:
"DllNotFoundException: serverapp"
I am using an internal build system, but when I parse the output of the build process, I can see many calls of the form:
android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-g++.exe -march=armv7-a
After building my Android app, I inspect the resulting APK (renaming to .zip and extracting), and can see my library file here:
lib/armeabi-v7a/libserverapp.so
I can confirm that "ARMv7" is the target architecture in the Android Player settings, and I access the library, in C#, via:
[DllImport("serverapp", CallingConvention = CallingConvention.Cdecl)]
private static extern void run_sim(StringBuilder matchInput, StringBuilder results, int randomSeed);
I have built a Windows DLL of the C++ code, to use in the Editor, and everything works great. However, when I move to Android, the .so cannot be found. The import settings for libserverapp.so are:
Platform: Android; CPU: ARMv7; Path: Assets/Plugins/Android/libserverapp.so; Type: Native
Given that the final APK includes the .so where I expect it to be (lib/armeabi-v7a/), I assume my Unity settings are correct? Also, I am not using IL2CPP for the Android build.
Finally, when I do an object dump of the library file (using arm-linux-androideabi-objdump.exe), the file format of the library file is "elf32-littlearm".
I feel that the issue here is simply finding the .so, not the functionality within it. Any ideas on what's going on here?
Thanks!
I ended up solving the problem. I mentioned that was using an internal build system. Well, there seems to be a bug in it. I ported things over to official Android NDK makefiles, and then it "just worked". So in this case, the library could be found, but its contents weren't valid.
I m trying to build old c code with android standalone tool chain and it keeps failing on
following error :
fatal error: ftw.h: No such file or directory
Not sure how to include these headers from android.
Thanks,
ftw.h is included in android-21 platform (ndk 10c):
MBA-Anton:android-ndk-r10c asmirnov$ find /softdev/android-ndk-r10c -name "ftw.h"
/softdev/android-ndk-r10c/platforms/android-21/arch-arm/usr/include/ftw.h
/softdev/android-ndk-r10c/platforms/android-21/arch-arm64/usr/include/ftw.h
/softdev/android-ndk-r10c/platforms/android-21/arch-mips/usr/include/ftw.h
/softdev/android-ndk-r10c/platforms/android-21/arch-mips64/usr/include/ftw.h
/softdev/android-ndk-r10c/platforms/android-21/arch-x86/usr/include/ftw.h
/softdev/android-ndk-r10c/platforms/android-21/arch-x86_64/usr/include/ftw.h
This was an old message, but as I am on a similar ftw-hunt today: as of my writing this, ftw.h does not exist in contemporary android ndk include dirs.
Here are external links to source code for ftw* which may be useful:
http://www.opensource.apple.com/source/ksh/ksh-4/ksh/src/lib/libast/comp/ftw.c
http://www.opensource.apple.com/source/ksh/ksh-4/ksh/src/lib/libast/comp/ftw.h
Also, ftwalk.c is located as above but libast/misc/ftwalk.c (stackoverflow will not let me post a third link cause I'm a newb).
I'm trying to build cocos2d-x hello world project using build_native.sh, it shows me some compile errors. it seems that NDK can't find cocos2d-x sources.first it says:
NDK_ROOT = /cygdrive/c/Android-NDK-r4/android-ndk-r4-crystax
COCOS2DX_ROOT = /cygdrive/c/cocos2d-x/cocos2d-cocos2d-x-6e84662/firstapp/proj.android/../..
APP_ROOT = /cygdrive/c/cocos2d-x/cocos2d-cocos2d-x-6e84662/firstapp/proj.android/..
APP_ANDROID_ROOT = /cygdrive/c/cocos2d-x/cocos2d-cocos2d-x-6e84662/firstapp/proj.android
then:
Compile++ thumb: game_shared <= /cygdrive/c/cocos2d-x/cocos2d-cocos2d-x-6e84662/firstapp/proj.android/jni/hellocpp/main.cpp
In file included from /cygdrive/c/cocos2d-x/cocos2d-cocos2d-x-6e84662/firstapp/proj.android/jni/hellocpp/main.cpp:1:
/cygdrive/c/cocos2d-x/cocos2d-cocos2d-x-6e84662/firstapp/proj.android/jni/../../Classes/AppDelegate.h:4:27: error: CCApplication.h: No such file or directory
/cygdrive/c/cocos2d-x/cocos2d-cocos2d-x-6e84662/firstapp/proj.android/jni/hellocpp/main.cpp:2:44: error: platform/android/jni/JniHelper.h: No such file or directory
In file included from /cygdrive/c/cocos2d-x/cocos2d-cocos2d-x-6e84662/firstapp/proj.android/jni/hellocpp/main.cpp:6:
/cygdrive/c/cocos2d-x/cocos2d-cocos2d-x-6e84662/firstapp/proj.android/jni/../../Classes/HelloWorldScene.h:4:21: error: cocos2d.h: No such file or directory
and many more compile errors.
I used cocos2dx website tutorial, I'm using API 10(android 2.3.3) and windows 7 .
can anyone help me?
Try including <Cocos2d-x Root Folder>\cocos2dx\platform\ under Right Click->Properties->C\C++ general->path and symbols-> source folder -> Link Folder It is not able to find CCApplication.h file which could be found under <Cocos2d-x Root Folder>\cocos2dx\platform\android . Hope this helps.
COCOS2DX_ROOT = /cygdrive/c/cocos2d-x/cocos2d-cocos2d-x-6e84662/firstapp/proj.android/../.. make sure that cocos2dx files are available at that location.
Try including Cocos2dx folder in your Android.mk file, the error is telling that it cannot find the source file CCApplication.h which is in the cocos2dx folder.
first import the library of cocos2d-x in the eclicips
path of lib D:\cocos2d-x-2.2\cocos2dx\platform\android
then
Add the library of cocos2d-x in your project.
In buid_native.sh file, around line 55, there is $COCOS2DX_ROOT defined with default path like '../../../', which means it will search COCOS2D_ROOT just relative to its current directory. So have a look at that first.
Even a simple code like this gives the error
string test= "hello";
string part = test.substr(2, 3);
Invalid arguments Candidates are: stlpmtx_std::basic_string,stlpmtx_std::allocator> substr(?, ?)
Even casting to size_t did not not help
string part = test.substr((size_t)2, (size_t)3);
But both pieces of code working when running it as a console application using gcc 4.6 on Linux.
But when using Androind NDK it gives me the error.
If I close the file in the editor and close Eclipse, and then open Eclipse and build the project it compiles. But if I have the file open it throws up the error.
I am using APP_STL:= stlport_static in the Application.mk make file
Yes I did include <string>
Edit: I just looked at the times of .so file, it seems to be compiling even though Eclipse is showing the errors.
I found the solution I need to have to have stlport system include folder in the Paths and Symbols section of project properties -> C/C++ General
path_To_NDK/sources/cxx-stl/system/include
I only had the
path_To_NDK/sources/cxx-stl/stlport/stlport
I am trying to port libtiff on Android. The source version I am using is tiff 4.0.1.
I am building this source inside u1 android OS.
I am getting the below error when I run mmm external/tiff 4.0.1/
In file included from external/tiff-4.0.1/libtiff/tiffiop.h:33,
from external/tiff-4.0.1/libtiff/tif_dirread.c:42:
external/tiff-4.0.1/libtiff/tif_config.h:93:1: warning: "HAVE_MALLOC_H" redefined
In file included from <command-line>:0:
./system/core/include/arch/linux-arm/AndroidConfig.h:221:1: warning: this is the location of the previous definition
In file included from external/tiff-4.0.1/libtiff/tif_dirread.c:42:
external/tiff-4.0.1/libtiff/tiffiop.h:54:21: error: search.h: No such file or directory
I tries searching a lot on internet but could not get the issue.
Can any one provide me just an approx idea what could be wrong or which package is missing.
I resolved this issue finally. I hope this will help someone who is doing this work in future. We just need to remove the lines from libtiff/tiffiop.h where header file is being referenced.That worked for me.
Depending on your libtiff version, you can also just undefine HAVE_SEARCH_H in the config file tif_config.h which will then no longer include <search.h>:
In tif_config.h:
#ifndef ANDROID
/* Define to 1 if you have the <search.h> header file. */
#define HAVE_SEARCH_H 1
#endif