忍者ブログ
  • 2024.04
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 2024.06
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

【2024/05/05 20:00 】 |
cocos2d-x + Androidで、どのスタティックライブラリを使うべきか
実機に転送して、実行しようとした時、以下のエラーが出る

java.lang.UnsatisfiedLinkError: dlopen failed: unknown reloc type 160

調べたところ、スタティックライブラリをc++_staticにしていることが原因らしい。
cocos2d_libとc++_staticの相性の問題のようだ。困ったものだ

参考

デフォでは、gnustl_static を指定しているのだが(cocosプロジェクトが作られた時もそうなっている)、
gnustl_staticは以下のようなメソッドが使えない(コンパイルエラーになる)
std::to_string
std::stol
std::stoul
std::stoll
std::stoull
std::stof
std::stod

これはndkの怠慢じゃないかと思うのだが、ともかく
こちらを立てればあちらが立たずの状態になっている。


仕方ないので、
gnustl_staticを使用し、
std::文字列系の処理を自前で実装することにする。

実装は以下のとおり

AndroidHelper.h

#ifndef AndroidHelper_h
#define AndroidHelper_h

#include
#include
#include

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID

namespace std{

template
std::string to_string(T value)
{
std::ostringstream os;
os << value;
return os.str();
}

int stoi (const std::string& __str, size_t* __idx = 0, int __base = 10);
long stol (const std::string& __str, size_t* __idx = 0, int __base = 10);
unsigned long stoul (const std::string& __str, size_t* __idx = 0, int __base = 10);
long long stoll (const std::string& __str, size_t* __idx = 0, int __base = 10);
unsigned long long stoull(const std::string& __str, size_t* __idx = 0, int __base = 10);
float stof (const std::string& __str, size_t* __idx = 0);
double stod (const std::string& __str, size_t* __idx = 0);

}

#endif

#endif






AndroidHelper.cpp

#include
#include

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID

namespace std{

int stoi (const std::string& __str, size_t* __idx, int __base)
{
const char* p = __str.c_str();
char* end;
int x = (int)strtol(p, &end, __base); //strtoiというのはない
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

long stol (const std::string& __str, size_t* __idx, int __base)
{
const char* p = __str.c_str();
char* end;
long x = strtol(p, &end, __base);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

unsigned long stoul (const std::string& __str, size_t* __idx, int __base)
{
const char* p = __str.c_str();
char* end;
unsigned long x = strtoul(p, &end, __base);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

long long stoll (const std::string& __str, size_t* __idx, int __base)
{
const char* p = __str.c_str();
char* end;
long long x = strtoll(p, &end, __base);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

unsigned long long stoull(const std::string& __str, size_t* __idx, int __base)
{
const char* p = __str.c_str();
char* end;
unsigned long long x = strtoull(p, &end, __base);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

float stof (const std::string& __str, size_t* __idx)
{
const char* p = __str.c_str();
char* end;
float x = strtof(p, &end);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

double stod (const std::string& __str, size_t* __idx)
{
const char* p = __str.c_str();
char* end;
double x = strtod(p, &end);
if (__idx != nullptr) {
*__idx = static_cast<std::size_t>(end - p);
}
return x;
}

}

#endif
PR
【2016/02/22 17:13 】 | Android | 有り難いご意見(0)
<<ラムダ式の中でthisが書き換わる | ホーム | AndroidStudioでのgitignore>>
有り難いご意見
貴重なご意見の投稿














<<前ページ | ホーム | 次ページ>>