1. 程式人生 > >android編譯surface c++程式時,報錯缺少.o檔案

android編譯surface c++程式時,報錯缺少.o檔案

最近在研究Android的surface系統,寫了個小demo,編譯的時候,一直報錯,說是缺少.o檔案,但是看程式碼一直沒問題,後來發現原來是在window下編寫的,然後在linux編譯的時候,字尾多了^M,所以導致編譯不過。

其實提示類似的錯誤,肯定是程式碼那塊地方出現了類似的錯誤。不知道的,查起來能累死,知道的很快的就能知道怎麼查。

順便把原始碼貼寫。

testsurface.cpp

#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>


#include <cutils/memory.h>
#include<native_window.h>


#include <utils/Log.h>


#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>


#include <ui/GraphicBuffer.h>
#include <gui/Surface.h>
#include <gui/ISurfaceComposer.h>
#include <gui/SurfaceComposerClient.h>
#include <cutils/properties.h>


#include <ui/DisplayInfo.h>
using namespace android;
int main(int argv,char *argc[])
{
    sp<ProcessState> proc(ProcessState::self());
    ProcessState::self()->startThreadPool();


    sp<SurfaceComposerClient> client = new SurfaceComposerClient();
    sp<SurfaceControl> surfaceControl = client->createSurface(String8("testsurface"),240, 160, PIXEL_FORMAT_RGBX_8888, 0);
    DisplayInfo dinfo;
    sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay(
            ISurfaceComposer::eDisplayIdMain);
    SurfaceComposerClient::getDisplayInfo(display, &dinfo);
    uint32_t dispw = dinfo.w;
    uint32_t disph = dinfo.h;


    /* create backgound surface */
    sp<SurfaceControl> bg_surfaceControl = client->createSurface(
            String8("test-bg-surface"), dispw, disph, PIXEL_FORMAT_RGBX_8888);


    sp<Surface> bg_surface = bg_surfaceControl->getSurface();

 /* set background layer z-order */
    SurfaceComposerClient::openGlobalTransaction();
    bg_surfaceControl->setLayer(200000);
    SurfaceComposerClient::closeGlobalTransaction();


    /* clear background layer black */
    ANativeWindow_Buffer outBuffer;


    bg_surface->lock(&outBuffer, NULL);
    ssize_t bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
    android_memset32((uint32_t*)outBuffer.bits, 0xFF000000, bpr * outBuffer.height);
    bg_surface->unlockAndPost();
    sleep(5);


    bg_surface->lock(&outBuffer, NULL);
     bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
    android_memset32((uint32_t*)outBuffer.bits, 0xF800, bpr * outBuffer.height);
    bg_surface->unlockAndPost();
    sleep(5);


    bg_surface->lock(&outBuffer, NULL);
    bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
    android_memset32((uint32_t*)outBuffer.bits, 0x7e56, bpr * outBuffer.height);
    bg_surface->unlockAndPost();
    sleep(5);
   return 0;
}

Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)


LOCAL_SRC_FILES:= testsurface.cpp


LOCAL_C_INCLUDES := external/skia/include/core \
                    frameworks/native/include/android


LOCAL_SHARED_LIBRARIES := libcutils \
    libutils \
    libbinder \
    libui \
    libgui \


LOCAL_MODULE:= testsurface


LOCAL_MODULE_TAGS := tests


include $(BUILD_EXECUTABLE)