iOS 從C移植項目到Objective-C,iosobjective-c

來源:互聯網
上載者:User

iOS 從C移植項目到Objective-C,iosobjective-c

一、建立項目
  iOS | Framework & Library
    Cocoa Touch Static Library

建立一個Library庫

1. M.h標頭檔

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

2. M.c實現檔案

#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 編譯,此時只編譯模擬器了版本,可以串連手機編譯真機版本靜態庫檔案,編譯成功後會在電腦上產生相關的.a靜態庫檔案;

libM.a檔案所在目錄

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

兩個路徑分別是模擬器,真機版本的輸出目錄。

將libM.a庫檔案和M.h標頭檔拷貝到外部項目即可使用靜態庫裡面的函數了。

 

二、查看 .a 檔案支援的平台

通過lipo命令來查看

lipo -info xxLibrary.a

輸出結果:

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

上面幾個平台分別對應的手機

  • armv7是iphone5之前的裝置指令集架構;
  • armv7s是iphone5、iphone 5s的指令集架構;
  • arm64是iphone6、iphone 6plus的指令集架構;
  • i386以及x86_64是MAC的指令集架構;

如果某個 .a 檔案只支援某一個平台,但我們的應用在發布的時候,都會需要支援所有平台的庫,所以build會報錯,此時可以把各個支援單個平台的 .a 檔案合并。

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

三、查看 .framework 檔案支援的平台

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

輸出結果:

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

如此便可查看你工程中的靜態庫是否支援64位。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.