【发布时间】: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 的顺序错误......并且将SDL2 和ppapi_simple 在列表中两次对其他人有用。虽然它们都是旧帖子,但我没有尝试过任何工作(不一定我尝试正确)
我非常迷茫...任何帮助将不胜感激。
谢谢
【问题讨论】:
标签: c++ makefile sdl-2 google-nativeclient