I have code that was using strnlen in a .mm file
The compiler when using Xcode 4.2 will work just fine to build.
Xcode 3.2.5 however cannot find strnlen()...
I have tried the solutions posted for strlen
#include <cstring> // doesn't work
using std::strlen; // doesn't work
#include <string> // doesn't work
Is there a way to use strnlen on iOS 4.2.1?
For now i'm just converting to NSString object and using length.
Is there something wrong with using strlen, which is a standard C function? I looked up strnlen and it seems to be a GNU extension.
Related
Swift 4.2 has a special condition canImport that helps developers to check whether a module can be imported in project. It was introduced in Swift 4.1.
Now I am working on iOS project written in Objective-C. I use modules, and for each target these modules are different. That's why I want to use something like that:
#if canImport(SomeModule)
#import SomeModule;
#endif
How can I solve this problem? Now I use different "Other C Flags" for each target, but I want to find more flexible solution.
This is a little late as an answer, but i came across this issue while working on a similar case.
I used the __has_include(<SomeModule/SomeModule.h>)
Importing your framework:
#if __has_include(<SomeModule/SomeModule.h>)
#import <SomeModule/SomeModule.h>
#define __HAS_SOME_MODULE_FRAMEWORK__
#endif
Later in your code :
- (void)doSomething {
#ifdef __HAS_SOME_MODULE_FRAMEWORK__
// with SomeModule framework
#else
// without SomeModule framework
#endif
}
The code was working well before the upgrade to Xcode 7.3 from 7.1 and swift 2.2. I have also seen answers using the typedef NS_ENUM(NSUInteger, MyStatus)... but if possible, I prefer not to change the existing obj-c code.
Defined in obj-c header file:
typedef enum {
StatusPending,
StatusTimeout,
StatusSuccess,
StatusFail
} MyStatus;
Statement in Swift file:
/* some code to retrieve the status */
switch (status) {
case .StatusSuccess:
/* do something */
/* other test cases omitted here */
default:
}
I've tried using .rawValue, .value, etc, but I still get an error:
Enum case 'StatusSuccess' not found in type 'MyStatus'
All was working fine before the upgrade and have tried uninstalling/reinstalling Xcode 7.3, Product->Clean, Product->Clean Build Folder.. but without success :-(
You can't declare "typedef NS_ENUM (NSUInteger, EnumName){}" within #interface and #end, the parsing of xcode 7.2 is different from xcode 7.3. So, just move your enum declarations outside #interface #end block and it should work fine, otherwise its considered a private declaration
I'm working with the Vuforia library for iOS (augmented reality). The library framework is only compiled for armv7 and v7s arch - thus it won't run in the simulator (i386 arch). In order to test the rest of my app in the simulator I've wrapped parts of my code that reference the vuforia functions in compiler macros as such:
#if TARGET_IPHONE_SIMULATOR
//do simulator stuff
#else
//do vuforia stuff
#endif
This has taken my error count down to just one left - which I can't seem to get rid of:
Undefined symbols for architecture i386:
"QCAR::Renderer::getInstance()", referenced from:
SampleMath::projectScreenPointToPlane...
I have found SampleMath.cpp and have found the one and only call to reference to renderer.getInstance and have wrapped that in the macros. I've tried wrapping the entire .h and .cpp file in the macros; I've searched my entire xcode project for other places where the code might be referenced. Still after multiple cleans, and a OS X + xcode restart; still getting the same compiler error. Any Ideas? If so - many thanks.
It seems that Xcode doesn't define automatically TARGET_IPHONE_SIMULATOR in .cpp files.
The solution is to insert at the begining of your .cpp file :
#include "TargetConditionals.h"
Then all tests on TARGET_IPHONE_SIMULATOR will work.
I tried using the Glew Library for shading and was trying to compile a simple program using the NSOpenGLView Class in Xcode 5. The program fails at the following code in glew.h
#if defined(__gltypes_h_)
#error gltypes.h included before glew.h
#endif
It says that Gltypes.h is included before glew.h.
My implementation file for OpenGLView has headers included in following fashion:
#include <glew.h>
#import "OpenGLView.h" // Includes Cocoa.h
#include "LoadShaders.h" // Includes <OpenGL/gl.h>
So, if glew.h is included in the beginning, why is the error coming here. None of the other headers are included before the inclusion of glew.h, so tests for them(like gl.h) are passing in glew.h. I am not able to find out here as to who is including Gltypes.h in this file.
Hope anyone has a clue to it here.
The precompiled header file (.pch) pulls Cocoa in. Edit it to include glew.h before Cocoa.h and you are good to go.
I have some Objective-C code that I'd like to convert to Objective-C++. To changed the extension of the source files from .m to .mm, and I set the filetype as Objective-C++ Source. However, now my project fails to build. Its giving an error on lines that I call vm_deallocate.
Here is the line:
vm_deallocate(mach_task_self(), (vm_address_t)prevInfo, prevInfo);
And the exact error is:
Use of undeclared identifier vm_deallocate
Is vm_deallocate restricted to Objective-C? Is there an equivalent Objective-C++ function?
No, since it's c.
This is more a header problem.
Make sure you have include in the right file
#include <mach/mach_init.h>
#include <mach/vm_map.h>
And it should compile without complain.