【问题标题】:Google's Native Client and Compiling SDL2Google 的 Native Client 和编译 SDL2
【发布时间】:2015-12-15 03:00:41
【问题描述】:

我在使用 SDL2 库构建带有 pepper_46 的应用时遇到了问题。我搜索了互联网,终于找到了谷歌的webports,它让我能够正确地为 pnacl 编译 SDL2。

我现在遇到的问题实际上是使用 makefile 编译所有内容...

这是我试图编译的调用 SDL_Init 的最小 C++ 文件:

#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "SDL2/SDL.h"

class firstInstance : public pp::Instance {
public:
  explicit firstInstance(PP_Instance instance) : pp::Instance(instance)  {
    SDL_Init(SDL_INIT_VIDEO);
  }

  virtual ~firstInstance() {}
};

class firstModule : public pp::Module {
  public:
    firstModule() : pp::Module() {}
    virtual ~firstModule() {}

  virtual pp::Instance* CreateInstance(PP_Instance instance) {
    return new firstInstance(instance);
  }
};

namespace pp {
  Module* CreateModule(){
    return new firstModule();
  }
}

我还对我的 makefile 进行了一些更改,希望它能正确编译:

# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# GNU Makefile based on shared rules provided by the Native Client SDK.
# See README.Makefiles for more details.

VALID_TOOLCHAINS := pnacl

NACL_SDK_ROOT ?= $(abspath $(CURDIR)/..)

TARGET = first

include $(NACL_SDK_ROOT)/tools/common.mk

LIBS = SDLmain SDL2 ppapi_gles2 ppapi_simple ppapi_cpp nacl_io ppapi pthread

CFLAGS = -Wall -std=c++11
SOURCES = first.cc

# Build rules generated by macros from common.mk:

$(foreach src,$(SOURCES),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS))))

# The PNaCl workflow uses both an unstripped and finalized/stripped binary.
# On NaCl, only produce a stripped binary for Release configs (not Debug).
ifneq (,$(or $(findstring pnacl,$(TOOLCHAIN)),$(findstring Release,$(CONFIG))))
$(eval $(call LINK_RULE,$(TARGET)_unstripped,$(SOURCES),$(LIBS),$(DEPS)))
$(eval $(call STRIP_RULE,$(TARGET),$(TARGET)_unstripped))
else
$(eval $(call LINK_RULE,$(TARGET),$(SOURCES),$(LIBS),$(DEPS)))
endif

$(eval $(call NMF_RULE,$(TARGET)))

但我得到的最好的是这个错误:

bobkingof12vs$ make serve
  CXX  pnacl/Release/first.o
  LINK pnacl/Release/first_unstripped.bc
/nacl/pepper_46/lib/pnacl/Release/libppapi_simple.a: error: undefined reference to 'PSUserMainGet'
make: *** [pnacl/Release/first_unstripped.bc] Error 1

我读过一篇帖子,建议有人用ldflag-Wl,--undefined=PSUserMainGet 修复了类似的问题...但我不知道如何将其正确添加到makefile...正确修复。我还看到他们的LIBS 的顺序错误......并且将SDL2ppapi_simple 在列表中两次对其他人有用。虽然它们都是旧帖子,但我没有尝试过任何工作(不一定我尝试正确)

我非常迷茫...任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: c++ makefile sdl-2 google-nativeclient


    【解决方案1】:

    嗯,我找到了一些帮助我最终弄清楚的来源......

    因此,在完成 webports 交易以正确安装 SDL 之后,我继续寻找要使用的正确 makefile。

    终于在 github 上找到了一个:https://github.com/emscripten-ports/SDL2/blob/master/test/nacl/Makefile(看起来和普通的 nacl makefile 差很多!)

    这里有做什么的描述:https://github.com/emscripten-ports/SDL2/blob/master/docs/README-nacl.md

    我唯一需要做的另一件事就是将此函数添加到我的 c++ 代码中:

    int SDL_main(int argc, char *argv[]){
      return 0;
    }
    

    我的代码现在至少可以编译了!立即崩溃,但可以编译!

    如果我发现缺少一些有用的东西,我会发布更多内容

    【讨论】:

    • 我仍然遇到同样的错误。我使用的辣椒版本是 47。 libppapi_simple.a: 错误:未定义对 'PSUserMainGet' 的引用
    • 我知道这是半年前的事了,但你有没有让它正常工作?如果是这样,知道你做了什么会很有帮助。
    • 对不起,这些是我在这篇文章之后唯一拥有并且没有使用过的笔记。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多