iOS - making a cross-platform debugging variable macro - android

I got a macro I am using for debugging/logging, simply:
MY_DEBUG_INFO(msg...)
this works fine on say android:
#ifdef ANDROID
#define MY_DEBUG_INFO(msg...) __android_log(ANDROID_INFO,"TEST",msg...) (roughly)
However, how do I make the same macro apply to iOS logging? With the new data types and all
#ifdef IOS
#define MY_DEBUG_INFO(msg...) NSLog(????)

#define MY_DEBUG_INFO(...) NSLog(#__VA_ARGS__)

Related

Why is this c++ namespace giving me grief?

First off, my app has a file named Android.hpp. This is part of the tmxlite library. Compiling tmxlite on windows works fine. However, when I move the code to android studio and compile it (with the NDK), I get an error.
Android.hpp:
/*********************************************************************
Matt Marchant 2016
http://trederia.blogspot.com
tmxlite - Zlib license.
This software is provided 'as-is', without any express or
implied warranty. In no event will the authors be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but
is not required.
2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any
source distribution.
*********************************************************************/
#ifndef ANDROID_INC_HPP_
#define ANDROID_INC_HPP_
#ifdef __ANDROID__
#include <string>
#include <sstream>
#include <cstdlib>
namespace std
{
template <typename T>
std::string to_string(T value)
{
std::ostringstream os;
os << value;
return os.str();
}
}
#define STOI(str) std::strtol(str.c_str(), 0, 10)
#else
#define STOI(str) std::stoi(str)
#endif // __ANDROID__
#endif // ANDROID_INC_HPP_
The error:
In file included from E:\max\android_libs\tmxliteOG\tmxlite\src\FreeFuncs.cpp:28:
In file included from E:\max\android_libs\tmxliteOG\tmxlite\include\tmxlite\FreeFuncs.hpp:54:
E:\max\android_libs\tmxliteOG\tmxlite\include\tmxlite\detail\Android.hpp:37:11: error: expected '{'
Why is this happening? I was under the impression that this was how namespaces were supposed to be declared and I don't see what is wrong with it. I mean, I didn't even write the code :-).
help is greatly appreciated.

Ifdef in C using crossplatform Android/iOS doesn´t work propertly

I have a piece of code to change calls between different platforms. But I have detected a problem using iphone and ipad, TARGET_OS_IPHONE definition only works with iphone, but no ipad, I don´t want to try using else to think is ipad because maybe in the future this will be a source of problems.
I have lost 2 days looking for a problem with colors in opencv matrix caused by this.....
My question, exist a proper solution official to execute a piece of code in iOS S.O (Iphone AND Ipad)?
As reference, I look always in this link.
An example to select code:
#ifdef __linux__
// All linux arch
#elif _WIN32
// Windows 32 and 64
#elif __APPLE__
#ifdef TARGET_OS_IPHONE
// iOS, no work with iPAD
#elif TARGET_IPHONE_SIMULATOR
// iOS Simulator
#elif TARGET_OS_MAC
// Other kinds of Mac OS
#else
// Unsupported platform
#endif
#elif __ANDROID__
// Android all versions
#else
// Unsupported architecture
#endif
Try including "TargetConditionals.h" file in case of '__APPLE__'.
This file includes all the macros refered to the Apple devices.
Any way, using your example, the correct way should be:
#ifdef __linux__
// All linux arch
#elif _WIN32
// Windows 32 and 64
#elif __APPLE__
#include "TargetConditionals.h" // <--- Include this
#ifdef TARGET_OS_IOS // <--- Change this with a proper definition
// iOS, including iPhone and iPad
#elif TARGET_IPHONE_SIMULATOR
// iOS Simulator
#elif TARGET_OS_MAC
// Other kinds of Mac OS
#else
// Unsupported platform
#endif
#elif __ANDROID__
// Android all versions
#else
// Unsupported architecture
#endif
Also, you can let 'TARGET_OS_IPHONE' definition there, but 'TARGET_OS_IOS' is more appropiate.
You can include this file directly, or you can find it in your disk following the path: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/TargetConditionals.h'.

How does Android source building #ifdefs work in compilation

I'm familiar with Android kernel programming but I'm a newbie at building the Android source. I'm wondering how to enable the #ifdefs in android source building. Are there any defconfig file in android source like in android kernel to choose what we want to compile in the compilation?.. How can i enable the codings defined with #ifdef to get compile during the Android source compilation?
Ex:
#ifdef USE_ION
int alloc_map_ion_memory(OMX_U32 buffer_size,
OMX_U32 alignment, struct ion_allocation_data *alloc_data,
struct ion_fd_data *fd_data,int flag);
void free_ion_memory(struct vdec_ion *buf_ion_info);
#else
bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
OMX_U32 alignment);
#endif
I want to make sure the ion part is being compiled not the pmem part.
Try add the line:
#error "USE_ION"
after #ifdef USE_ION
Build again, if the build failed, USE_ION is defined.

enable arm neon for bullet physics engine demo on android

I'm building a demo with bullet physics engine library for android phone(NDK).
From 2.81 version, Bullet physics engine supports arm neon optimization, but only for apple devices.
My question is how to enable arm neon for android?
The flag for arm neon is defined in btScalar.h file, code is as below:
#if (defined (__APPLE__) && (!defined (BT_USE_DOUBLE_PRECISION)))
#if defined (__i386__) || defined (__x86_64__)
#define BT_USE_SSE
#define BT_USE_SSE_IN_AP
#elif defined( __armv7__ )
#ifdef __clang__
#define BT_USE_NEON 1
#if defined BT_USE_NEON && defined (__clang__)
#include <arm_neon.h>
……
As we can see in the code, flag BT_USE_NEON is defined in the condition of it is compiled for apple device, if I drop this code and define this flag by myself, some error occurs when compiling, something like bad alignment--vld1.f32 {d26},[r4:128].
What should I do for my demo to enable arm neon?
I had the same issues few days ago:)
The problem was assembly code defined in btVector3 (vld1q_f32_aligned_postincrement). As far as I know, syntax such as [r3, :128] is used in GAS - I guess it is used in iOS environment, but not sure. Modifying it to [%1, #128] may remove those errors.
By the way, from my experience, it is usually slow than plain implementation. I think the bullet neon intrinsics are not optimized for android, as you can see an assembly code(probably optimized) on the other side(defined as APPLE).

Androids NDK does not have SUN_LEN macro

today I faced trouble - android's ndk does not have SUN_LEN macro (sys/un.h || linux/un.h ), I don't want to patch android's headers, what is better to do?
Don't patch the headers, define it in your own file.
#ifndef SUN_LEN //In case they fix it down the road
#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen((ptr)->sun_path))
#endif
SUN_LEN macro is a non-portable (aka not a part of POSIX standard) extension.
It is completely safe to use sizeof(struct sockaddr_un) instead.

Categories

Resources