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)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用中提到,如果在VS2010以上版本的编译器中出现了缺少stdafx.h的,可以查看项目属性->C/C++->预编译头->预编译文件,看是否包含了"stdafx.h"文件。如果有的话,可以注释掉这段代码,不会对程序造成影响。 引用中说明了stdafx.h在C++中的作用是头文件编译,用于加快编译速度。它并不是标准的C++文件,而是与项目的源代码文件存放在同一个文件夹下的一个头文件。通过#include "stdafx.h"引用。 引用进一步解释了编译器是如何使用stdafx.h来使用预编译文件的。编译器会认为在#include "stdafx.h"之前的代码都是预编译的,它会跳过这条指令,直接使用projectname.pch编译这条指令之后的所有代码。 所以,如果在编译过程中出现了缺少stdafx.h的误,可以检查是否需要使用预编译文件,如果不需要,可以注释掉#include "stdafx.h"这段代码。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [VS2015 无法打开源文件 “stdafx.h“问题](https://blog.csdn.net/weixin_46196863/article/details/109602723)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值