android编译surface c++程序时,报错缺少.o文件

Posted ljbguanli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)












































































































以上是关于android编译surface c++程序时,报错缺少.o文件的主要内容,如果未能解决你的问题,请参考以下文章

如何解决`E Qt JAVA:找不到Surface 1-通过意图恢复到Qt @ android应用程序时出错?

用vs2015写c++,编译报错项目已过期,怎么回事?

如何使用android的ndk编译器 编译c++的库

android开发 surfaceView与按钮共存时,按钮的隐藏、显示问题

我的Android进阶之旅Android Studio的NDK项目可以运行,但是C++代码全部报红的错误

我的Android进阶之旅Android Studio的NDK项目可以运行,但是C++代码全部报红的错误