IOS porting from C to Objective-C, iosobjective-c

Source: Internet
Author: User

IOS porting from C to Objective-C, iosobjective-c

1. Create a project
IOS | Framework & Library
Cocoa Touch Static Library

Create a Library

1. M. h header file

#ifndef M_h#define M_h#include <stdio.h>
void testSleep(int t);void testPthread(int n);#endif /* M_h */

2. M. c implementation file

#include "M.h"#include <stdio.h>#include <pthread.h>#include <unistd.h>#include <stdlib.h>void testSleep(int t){   printf("testSleep:\n");   int i;   for (i=0; i<10; i++)   {       printf("sleep...\n");       usleep(t*1000);       printf("return...\n");   }}void *thrFun(void *p){   int t = (int)p;   int i;   for (i = 0; i<5; i++)   {       printf("thrFun  %d\n", t);       sleep(1);   }   return NULL;}void testPthread(int n){   void *retval;   pthread_t *tid = (pthread_t *)malloc(sizeof(pthread_t)*n);   int i;   for (i=0; i<n; i++)       pthread_create(&tid[i], NULL, thrFun, (void *)i);   for (i=0; i<n; i++)       pthread_join(tid[i], &retval);}

Cmd + B compilation. At this time, only the Simulator version is compiled. You can connect to the mobile phone to compile the static library file of the real machine version. After the compilation is successful, the related. a static library file will be generated on the computer;

Directory of the libM. a file

/Users/xx/Library/Developer/Xcode/DerivedData/M-xxx/Build/Products/Debug-iphonesimulator/Users/xx/Library/Developer/Xcode/DerivedData/M-xxx/Build/Products/Debug-iphoneos

The two paths are the output directory of the simulator and real machine version respectively.

Copy the libM. a library file and the M. h header file to an external project to use the functions in the static library.

 

2. view the Platform Supported by. a file

Use the lipo command to view

lipo -info xxLibrary.a

Output result:

Architectures in the fat file: xxLibrary.a are: armv7 armv7s i386 x86_64 arm64 

The mobile phones corresponding to the above platforms

  • Armv7 is a device instruction set architecture before iPhone 5;
  • Armv7s is the instruction set architecture of iphone 5 and iphone 5s;
  • Arm64 is the instruction set architecture of iphone 6 and iphone 6 plus;
  • I386 and x86_64 are MAC instruction set architectures;

If. file a only supports one platform. However, when our applications are released, they all need to support the libraries of all platforms. Therefore, an error is reported during the build process. file a is merged.

lipo -create XXXX_V7.a XXXX_V7s.a -output XXXX_all.a

3. View platforms supported by. framework files

lipo -info ./****.framework/****

Output result:

Architectures in the fat file: ./****.framework/**** are: i386 armv7 armv7s 

In this way, you can check whether the static library in your project supports 64-bit.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.