Google 的本地客户端和编译 SDL2

Google's Native Client and Compiling SDL2

我 运行 遇到了使用 SDL2 库 pepper_46 构建应用程序的问题。我搜索了互联网,最终找到了 Google 的 webports,它使我能够正确地为 pnacl 编译 SDL2。

我现在遇到的问题实际上是用 makefile 编译所有东西...

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

#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

我读到一篇 post,建议有人用 -Wl,--undefined=PSUserMainGetldflag 解决了类似的问题...但我不知道如何正确地将其添加到makefile ...如果这是正确的解决方法。我还看到他们的 LIBS 顺序错误......并且将 SDL2ppapi_simple 放入列表中两次对其他人有效。虽然它们都是旧的 post,但我尝试过的都没有用(并不是说我一定试对了)

我迷路了...任何帮助将不胜感激。

谢谢

好吧,我找到了一些帮助我最终弄明白的资源...

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

终于在gituhub上找到了一个: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;
}

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

如果我发现遗漏的东西有帮助,我会post更多