How to detect Apportable with preprocessor flags? - preprocessor

This is related to my other question
When I build my project with Apportable, it assumes Linux/Android platform. I think these preprocessor flags are set.
__linux
ANDROID
But, my source code (OpenGL drawing) is not ready for Android, and only for iOS. So I want to detect some preprocessor flag for Apportable (not Linux or Android), and perform some iOS specific processing.
How can I detect Apportable platform in preprocessing stage? (What is pre-defined preprocessor flag for Apportable?)

You can easily verify if a preprocessor macro is defined by using the message pragma:
// will always print, to detect cases where file wasn't actually built
#pragma message "-------------------------ALWAYS----------------------------"
// if the macros are defined, the pragma message should be logged
#ifdef __linux
#pragma message "__linux"
#endif
#ifdef ANDROID
#pragma message "ANDROID"
#endif
This will print out warning messages for macros that are defined:
/.../KTTypes.h:15:9: warning: -------------------------ALWAYS---------------------------- [-W#pragma-messages]
#pragma message "-------------------------ALWAYS----------------------------"
^
/.../KTTypes.h:17:9: warning: __linux [-W#pragma-messages]
#pragma message "__linux"
^
/.../KTTypes.h:20:9: warning: ANDROID [-W#pragma-messages]
#pragma message "ANDROID"
So yes, ANDROID and __linux are both defined when building with apportable, and not defined when building from within Xcode.

ANDROID will be defined by the build system, however since the Apportable platform has numerous features that stock Android will not. APPORTABLE is defined to signify builds by the apportable build system.
You can find additional build flags specific for Apportable builds in
~/.apportable/SDK/site_scons/android/ndk.py

Related

How to remove the warnings from libraries included from POD

I have included the RETableview manager library from POD. I need to remove the warnings currently I am getting. What are the best ways of receiving the updates
You can use surpress a lot of warning generated from clang from either build options or in your code. For instance, if you had a unused variable you didn't want to keep getting warned about, you could do this:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
let a = 1;
#pragma clang diagnostic pop
The basic idea is to edit compiler diagnostics and then restore them. When your source file is compiled it will basically ignore that line from a diagnostic perspective. You can do a lot more with the pragma marks as well, check out clang's user manual.

What is the proper way to configure GLM

Recently I enabled /W4 warnings (MSVC) to clean up a bit in my project and noticed that GLM uses non-standard compiler extension guarded by #define GLM_HAS_ANONYMOUS_UNION, that causes a very long warning spew.
There seems to be compiler feature detection mechanism, but I can't disable compiler extensions entirely because of Windows SDK dependencies and the /Za is discouraged as buggy anyway. So what is the proper way to disable that particular thing in GLM?
I could slap an #undef everywhere i use GLM but is there a "proper" place to configure these things, like a separate config file or something? I'm upgrading GLM from time to time so I wouldn't want to modify that define in the GLM's code.
I ran into the same problem as you.
GLM will try to use all capabilities of your compiler and if it detects VS it will use nonstandard extensions in order to do some fancy things.
If you want these non-standard things to go away (e.g. nameless unions/structs)
you can switch GLM into standard mode by using
#define GLM_FORCE_CXX11
just before you include any glm header.
I plugged this info from the manual at:
http://glm.g-truc.net/0.9.7/glm-0.9.7.pdf
Alternatively you can look into disabling this very specific warning via pragma warning push
#pragma warning(push)
#pragma warning(disable:4201) // suppress even more warnings about nameless structs
#include<glm/glm.hpp>
#pragma warning pop
more info at https://msdn.microsoft.com/en-us/library/aa273936(v=vs.60).aspx

(In iOS/OS X SDK's) Where are __i386__ and __x86_64__ defined?

In iOS and OS X SDK's, where are those architecture values defined?
The reason I am interested is because I used to conditionally compile code for the iOS Simulator as follows:
#ifdef __i386__
// Simulator-only code
#endif
And just noticed that I haven't updated it for the new 64-bit iOS Simulator by also checking for __x86_64__, and I'm also curious about other defines as there doesn't seem to be an official Apple documentation file for this.
Those values are defined by CLANG at compilation time depending on the target you happen to be building for, but were formalized by the GNU C spec for use in GCC.

Is anyone able to get the Address-Sanitizer (known as asan or -fsanitize=address) working on iOS?

Address-Sanitizer https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer
I have compile my own llvm (pretty straight forward compiling) because apple's llvm not support this function.
I have tested the clang for mac command line program, it works (but without showing the line the sourcecode).
for iOS, there is still some problems:
compile simulator version : report error for pre-compiled header:
In file included from /Users/fluke/Documents/projects/tmp/testAsanNoARC/testAsanNoARC/testAsanNoARC-Prefix.pch:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:9:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:53:24: error: 'UIAccelerometer' is unavailable: not available on OS X
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration NS_DEPRECATED_IOS(2_0, 5_0);
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:33:12: note: declaration has been explicitly marked unavailable here
#interface UIAccelerometer : NSObject {
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:53:71: error: 'UIAcceleration' is unavailable: not available on OS X
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration NS_DEPRECATED_IOS(2_0, 5_0);
...
compile for device version, it reports lack of libarc (but actually I don't enable ARC)
ld: file not found: /Users/fluke/Documents/tools/asan/Debug+Asserts/lib/arc/libarclite_iphoneos.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
so I try use it for a separate lib - just new a lib target and use my own clang while the main target still use apple's llvm. the program compiles ( may need to link to the asan dylib in the built llvm), but not work because I asan need to be loaded before our program entry.
who have experience with doing this?
I finally get the asan work for me with my friend's help.
move all c/c++ code to a new target (cocoa lib target) of xcode project. make the project build and run normally as it was a single app before separate c/c++ codes to a lib.
build llvm. ref http://blog.wadetregaskis.com/tot-clang-llvm-in-xcode/
add a clang option to xcode. for convenient you can use this template: http://blog.wadetregaskis.com/tot-clang-llvm-in-xcode/ . change clang path to the clang just build in the previous step.
change the lib target in the xcode to use the new clang/llvm, add a cflag -fsanitize=address. then build, if some api (such as opengl/system video function) is reported not supported, then you can put it into the app project, your clang doesn't support compiling it.
if you pass the compile, it will report linkage problem of __asan_xxx function, add a lib called "libclang_rt.asan_osx_dynamic.dylib" to the app's linkage dependency, and it's located in your llvm's
./Debug+Asserts/lib/clang/3.4/lib/darwin/ folder.
then you need to specified the out put file or else the report will goes to the stdout with color characters which will confuse you. put this lines into your main.m:
extern void __sanitizer_set_report_path(const char *path);
__sanitizer_set_report_path("/tmp/asan.txt");
then you can make your program some memory error such as use after free or heap buffer overflow. the asan will let the program crash in the first error, with /tmp/asan.txt.number report generated.
you're almost there, the report show's the error stack with the file's offset. all you need to do is one more step - resolve the address to code line. you need to find the DWARF file of your project, then use a tool called asan_symbolize.py to generate the new report with source code line. you can goole asan_symbolize.py then get and fix this script to use the DWARF file. you can find the DWARF file by right click your production app, select show in finder, then to up a level to get the iphone simulator directory, open the bundle called your.app.dSYM, then you can get the DWARF in ./Content/Resources/DWARF.
The only thing that I haven't list here is the modified asan_symbolize.py, you can modify it by your self, it has no magic, you just correct some path and it will work.
The errors listed in the original post have little to do with ASan itself. Most certainly you would've got them without the -fsanitize=address flag.
Building and running for iOS isn't supported yet, however you can build an app targeting the iOS simulator - it should work just fine.
Please don't hesitate to direct further questions to address-sanitizer#googlegroups.com

Xcode warning: ... is a GNU extension

I use a C++ library for an iOS app. With Apple LLVM 3.1 compiler configured (default), I get a lot of warnings for this C++ code, most of them saying:
... is a GNU extension
The introduction of clang's user manual says:
The Clang driver and language features are intentionally designed to be as compatible with the GNU GCC compiler as reasonably possible, easing migration from GCC to Clang. In most cases, code "just works".
So, is it save to just look for a switch to disable this warnings (btw. how to?) or should I better get this lib rid of all GNU extensions?
You can suppress the warnings using compiler flags. Clang tells you which compiler flag to use for each warning. After a build, choose View > Navigators > Show Log Navigator. Then choose the latest build log from the log navigator. Find a file with a warning and click the disclosure button at the right end of its status line. Xcode will show you the compiler command line and output for that file. Each warning should include the compiler flag that enables the warning. Example:
In my example, the warning flag is -Wpointer-arith. So the warning can be disabled by -Wno-pointer-arith. So I could add that flag to the “Other Warning Flags” build setting:

Resources