IOS静态库重新封装

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/fantasysolo/article/details/92791256

拆分及合并静态库

拆分

参考:
https://blog.csdn.net/xiaolei251990/article/details/82852388
https://blog.csdn.net/yiyunhzy/article/details/27523251
静态库是目标文件的简单链接,使用linux的ar拆分静态库:

ar -t xx.a // 查看有哪些.o模块
ar -x xx.a // 拆分出.o

此时报错:
xxx.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
胖文件,应该是这个静态库是多个cpu架构的静态库组成的,使用lipo 查看并进行拆分:

lipo -info xx.a // 查看包含的cpu架构的库
lipo xx. a -thin armv7 -output xx_armv7.a // 拆分出armv7的库
lipo xx. a -thin armv7s -output xx_armv7s.a

拆分后,再使用ar即可获得.o文件。
mac上,使用:

otool -Vf xx.lib // 查看包含的cpu架构等信息

可以获得此二进制文件包含的cpu架构。

otool -tv xx.o // 查看汇编代码

查看反编译代码。

合并

用ar合并.o成.a

ar cru libABC.a *.o // 合并.o文件
ranlib libABC.a // 更新静态库的符号索引表,相当于ar -s?

得到各个类型的a后,用lipo合并成胖文件

lipo -create xx_armv7.a  xx_arm64.a -output xx.a // 合并静态库成胖文件
lipo -create 模拟器.a  真机.a -output 目标地址/最终.a

切换生成release/debug

xcode 10的菜单栏 - Product - Scheme - Edit Scheme,打开窗口,将Run - info - Build configuration改为release。

没有armv7s的静态库

xcode 10全部按默认设置,生成的静态库只有arm64,armv7,没有armv7s。
原因是targets的设置问题。(可以同时把project也改掉)

  1. Build Settings - Architectures 默认为: $(ARCHS_STANDARD),添加一项armv7s(似乎默认没有包含)
  2. 确定Vaild Architectures中要有armv7s(默认有)
  3. 确定Build Active Architectures Only里面,对应的release或debug为No(或者直接把这项设置为No)
展开阅读全文

如何封装静态库

08-27

#include rn#include rn#include rn#include rn#include rn#define ITEMS_NUM 10 //缓冲区的数组元素个数rnvoid Render();rnvoid GameLoop();rnHRESULT InitD3D(HWND hWnd);rnLPDIRECT3D9 g_pD3D =NULL;rnLPDIRECT3DDEVICE9 g_pD3DDevice =NULL;rnLPDIRECT3DVERTEXBUFFER9 g_pVertexBuffer =NULL;rnLPDIRECTINPUT Input=NULL;rnLPDIRECTINPUTDEVICE InputDevice= NULL;rnchar keyBuffer[256];rnvoid CleanUp();rnstruct CUETOMVERTEXrnrn FLOAT x,y,z,rhw;rn DWORD color;rn;rn#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)rnHINSTANCE hInst;rnHWND hWnd;rnDIDEVICEOBJECTDATA DeviceObjectData[ITEMS_NUM];//缓冲区数组rnrnlong MouseMoveX = 0;//鼠标X轴的总移动量rnlong MouseMoveY = 0;//鼠标Y轴的总移动量rnrnPOINT cur_point;//鼠标当前位置rnCHAR tmpText[50];rnHDC hdc;rnrnHRESULT InitD3DInput();rnHRESULT InitVertexBuffer();rnLRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);rn#define SafeRelease(pObject) if(pObject!=NULL)pObject->Release();pObject =NULL;rnint WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)rnrn hInst = hInstance;rn WNDCLASSEX wcex;rn wcex.cbSize = sizeof(WNDCLASSEX);rnrn wcex.style = CS_CLASSDC;rn wcex.lpfnWndProc = WndProc;rn wcex.cbClsExtra = 0;rn wcex.cbWndExtra = 0;rn wcex.hInstance = hInstance;rn wcex.hIcon = NULL;rn wcex.hCursor = NULL;rn wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);rn wcex.lpszMenuName = NULL;rn wcex.lpszClassName = "base";rn wcex.hIconSm = NULL;rnrn RegisterClassEx(&wcex);rn hWnd = CreateWindow("base", "DirectX", WS_OVERLAPPEDWINDOW,rn 50, 50, 500, 500, NULL, NULL, wcex.hInstance, NULL);rn if(SUCCEEDED(InitD3D(hWnd)))rn rn ShowWindow(hWnd, nCmdShow);rn UpdateWindow(hWnd);rn if(SUCCEEDED(InitD3DInput()))rn rn SetWindowPos(hWnd,0,0,0,0,0,SWP_NOSIZE);//设置应用程序窗口位置rn SetCursorPos(0,0);//设置鼠标位置rn hdc = GetDC(hWnd);rn GameLoop();rn rn rn CleanUp();rn UnregisterClass("base",wcex.hInstance);rnrn return 0;rnrnrnLRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)rnrnrn switch(message)rn rn case WM_DESTROY:rn PostQuitMessage(0);rn return 0;rn case WM_KEYUP:rn switch(wParam)rn rn case VK_ESCAPE:rn DestroyWindow(hWnd);rn break;rn rn return 0;rn rn return DefWindowProc(hWnd, message, wParam, lParam);rnrnvoid GameLoop()rnrn MSG msg;rn bool fMessage;rn PeekMessage(&msg,NULL,0,0,PM_NOREMOVE);rn while(msg.message !=WM_QUIT)rn rn fMessage = PeekMessage(&msg,NULL,0,0,PM_REMOVE);rn if(fMessage)rn rn TranslateMessage(&msg);rn DispatchMessage(&msg);rn rn elsern rn Render();rn rn rnrnvoid Render()rnrn if( g_pD3DDevice ) // Only use Device methods if we have a valid device.rn rn HRESULT hr;rn hr=InputDevice->GetDeviceState(sizeof(keyBuffer),(LPVOID)keyBuffer);rn if(hr==DIERR_INPUTLOST)rn rn InputDevice->Acquire(); //重新获取键盘的使用权rn hr=InputDevice->GetDeviceState(sizeof(keyBuffer),(LPVOID)keyBuffer);rn if(FAILED(hr))rn rn ::MessageBox(0, " DIERR_NOTACQUIRED ", 0, 0);rn return ;rn rn rn if(keyBuffer[DIK_RIGHT] & 0x80)rn MessageBox(NULL,"RIGHT_KEY_PRESSED","提示",0);rnrn if(keyBuffer[DIK_LEFT] & 0x80)rn MessageBox(NULL ,"LEFT_KEY_PRESSED ","提示",0);rnrn if((keyBuffer[DIK_A] & 0x80)&(keyBuffer[DIK_LCONTROL] & 0x80)) rn MessageBox(NULL ,"Ctrl+A_PRESSED ","提示",0);rnrn // Instruct the device to set each pixel on the back buffer black -rn // D3DCLEAR_TARGET: 0x00000000 (black) - and to set each pixel onrn // the depth buffer to a value of 1.0 - D3DCLEAR_ZBUFFER: 1.0f.rn g_pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);rnrn // Swap the back and front buffers.rn g_pD3DDevice->Present(0, 0, 0, 0);rn rn return ;rnrnHRESULT InitD3D(HWND hWnd)rnrn g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);rn if(g_pD3D==NULL)rn rn return E_FAIL;rn rn D3DDISPLAYMODE d3ddm;rn if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT ,&d3ddm)))rn rn return E_FAIL;rn rn D3DPRESENT_PARAMETERS d3dpp;rn ZeroMemory(&d3dpp,sizeof(d3dpp));rn d3dpp.Windowed = TRUE;rn d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;rn d3dpp.BackBufferFormat = d3ddm.Format;rnrn if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,rn D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,rn &g_pD3DDevice)))rn rn return E_FAIL;rn rn return S_OK;rnrnvoid CleanUp()rnrn SafeRelease(g_pVertexBuffer);rn SafeRelease(g_pD3DDevice);rn SafeRelease(g_pD3D);rnrnHRESULT InitD3DInput()rnrn HRESULT hr=0;rn hr = DirectInput8Create( rn hInst, rn DIRECTINPUT_VERSION,rn IID_IDirectInput8,rn (void**)&Input, rn NULL);rn if(FAILED(hr))rn rn ::MessageBox(0, "DirectInput8Create( ) - FAILED", 0, 0);rn return false;rn rnrn //创建键盘输入设备rn hr=Input->CreateDevice(GUID_SysKeyboard, &InputDevice, NULL);rn if(FAILED(hr))rn rn ::MessageBox(0, "CreateDevice ( )-KEYBOD-FAILED", 0, 0);rn return false;rn rnrn //设置键盘输入设备的数据格式rn hr=InputDevice->SetDataFormat(&c_dfDIKeyboard);rn if(FAILED(hr))rn rn ::MessageBox(0, " SetDataFormat( )-FAILED", 0, 0);rn return false;rn rnrn //设置键盘输入设备的协调级别rn hr=InputDevice->SetCooperativeLevel(rn hWnd,rn DISCL_BACKGROUND|DISCL_NONEXCLUSIVErn );rn if(FAILED(hr))rn rn ::MessageBox(0, " SetCooperativeLevel( )-FAILED", 0, 0);rn return false;rn rnrn //获取键盘输入设备的访问权rn hr=InputDevice->Acquire();rn if(FAILED(hr))rn rn ::MessageBox(0, " Acquire( )-FAILED", 0, 0);rn return false;rn rnrn //键盘缓冲区清零rn ZeroMemory(keyBuffer,sizeof(char)*256);rn return true;rnrn以上是代码!如何封装键盘响应的静态库!菜鸟求解 论坛

没有更多推荐了,返回首页