cocos2d-js3.5 mac上自动绑定c++到js

按照官方教程来也会出现问题,现在把问题纪录下来,以免以后出现同样的问题不知道咋办了

按照readme.txt里面的引导,把需要下的软件都安装了,一般都比较简单,只需要输入几个命令即可。

文章最后会有readme的具体内容。

然后在终端输入依次输入

/bin/bash

export NDK_ROOT=/path/to/android-ndk-r9b

sh ./test.sh

这时候会出现一个问题。如下:

MissingSectionHeaderError: File contains no section headers.

file: userconf.ini, line: 1

‘-e [DEFAULT]\n‘

需要我们修改一下 tesh.sh脚本

随便一个编辑器打开,

把112行的

echo -e "$_CONTENTS" > "$_CONF_INI_FILE"

改成:

echo "$_CONTENTS" > "$_CONF_INI_FILE"

即可。

重新执行 sh test.sh应该会成功了。

-------readme.txt----------------

# What‘s new
* Add a prebuilt libclang3.4 in `libclang/`for mac, linux and windows.
* If you want use the prebuilt licbclang3.4 work with Android NDK, then `only the NDK r9b is can work corrently` with it.

# Requirements

* python2.7
* py-yaml
* cheetah (for target language templates)
* libclang, from clang 3.3 or later

# Usage

Usage: generator.py [options] {configfile}

Options:
-h, --help show this help message and exit
-s SECTION sets a specific section to be converted
-t TARGET specifies the target vm. Will search for TARGET.yaml

Basically, you specify a target vm (spidermonkey is the only current target vm) and the section from
the `.ini` file you want to generate code for.

## Run the simple test with prebuilt libclang3.4

Included in this repository is a simple test. Use this to confirm the generator is working and that your environment is set up correctly.

#### NOTE

* The test uses the prebuilt 3.4 libclang, so you should use `Android NDK r9b`.
* The test uses <string> and <stdint.h> so you need a C++ implementation that provides these
* Currently, the test script is setup to use the Android NDK‘s GNU libstdc++

### Mac OS X

* The OSX 10.9 has a built-in python2.7 and if your os don‘t have python2.7 then use [Homebrew](http://brew.sh/) to install the python and use pip install the python dependencies.
<pre>
brew install python
</pre>

* Install python dependices by pip.
<pre>
sudo easy_install pip
sudo pip install PyYAML
sudo pip install Cheetah
</pre>

* Download [64bit ndk-r9b-x86_64](http://dl.google.com/android/ndk/android-ndk-r9b-darwin-x86_64.tar.bz2) from [google](http://developer.android.com/tools/sdk/ndk/index.html)
* If you are using python installed from other way, copy user.cfg.sample and rename it as `user.cfg` then set the absolute path to python `PYTHON_BIN` in `user.cfg`
* Run follow command, it will generate a `userconf.ini`, and check the values in it if it occorus any error.
<pre>
export NDK_ROOT=/path/to/android-ndk-r9b
./test.sh
</pre>

### Ubuntu Linux 12.04 64bit
* Install python
<pre>
sudo apt-get install python2.7
</pre>
* Install python dependices by pip.
<pre>
sudo apt-get install python-pip
sudo pip install PyYAML
sudo pip install Cheetah
</pre>
* Download [64bit ndk-r9b-x86_64]( https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2) from [google](http://developer.android.com/tools/sdk/ndk/index.html)
* If you are using python installed from other way, copy user.cfg.sample and rename it as `user.cfg` then set the absolute path to python `PYTHON_BIN` in `user.cfg`
* Run follow command, it will generate a `userconf.ini`, and check the values in it if it occorus any error.
<pre>
export NDK_ROOT=/path/to/android-ndk-r9b
./test.sh
</pre>

### Windows 7 64bit
* Download python2.7.3 (`32bit`) from (http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi).
* Add the installed path of python (e.g. C:\Python27) to windows environment variable named ‘PATH‘.
* Download pyyaml from http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe and install it.
* Download pyCheetah from https://raw.github.com/dumganhar/my_old_cocos2d-x_backup/download/downloads/Cheetah.zip, unzip it to "C:\Python27\Lib\site-packages"
* Download [64bit NDK-r9b](http://dl.google.com/android/ndk/android-ndk-r9b-windows-x86_64.zip) from [google](http://developer.android.com/tools/sdk/ndk/index.html)
* Set the environment variables (`PYTHON_ROOT` and `NDK_ROOT`) or just them in `test.bat`.
* Run "test.bat". The generated codes will be under "simple_test_bindings".

### Expected output

Upon running the test you might see some warnings but should not see any errors.

The test will create a directory named simple_test_bindings that contains 3 files

* A .hpp header file for the bindings class
* A .cpp file implementing the bindings class
* A .js file that documents how to call (from JavaScript) the methods the C++ class exposes

# The `.ini` file

The `.ini` file is a simple text file specifying the settings for the code generator. Here‘s the
default one, used for cocos2d-x

[cocos2d-x]
prefix = cocos2dx
events = CCNode#onEnter CCNode#onExit
extra_arguments = -I../../cocos2dx/include -I../../cocos2dx/platform -I../../cocos2dx/platform/ios -I../../cocos2dx -I../../cocos2dx/kazmath/include -arch i386 -DTARGET_OS_IPHONE -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -x c++
headers = ../../cocos2dx/include/cocos2d.h
classes = CCSprite
functions = my_free_function

## Required sections

* prefix: the prefix for the project. Must be a valid identifier for the language of the target vm.
Most of the time, the name will be intermixed between the class name and the function name, since
all generated (probably) will be free functions, we do that in order to avoid name collition. The
script will generate ${prefix}.cpp and ${prefix}.hpp as a result.
* events: a list of identifiers in the form of ClassName#functionName that are events to be called
from the native world to the target vm.
* extra_arguments: extra arguments to pass to the clang interface. Basically you can think of this
as the arguments to pass to the "compiler", so add as many as you need here. If you‘re targetting
C++, make sure you add "-x c++" as the last argument to force C++ mode on a ".h" file. Otherwise,
name your header files as ".hpp".
* headers: list of headers to parse. Usually you add a single header that in turn `#include`s the
rest of the files.
* classes: the classes that will be parsed. Right not is just a string, but it will accept regular
expressions
* functions: space-separated list of free functions to be binded. Same as with classes, it will
support regular expressions.
* skip: a space-separated list of `Classes::functions` or just `functions` to not generate any code.

# The templates

The generator is using [Cheetah templates](http://www.cheetahtemplate.org/) to create a more
flexible generator. The way it was thought, is that for every target environment, you should provide
with a way to generate the same C/C++ functionality. Every template has access to the proper meta
information for the code or generator (function, classes, etc.)

Right now it‘s separated in the following set of templates:

* prelude.c/.h: The header of the generated files.
* ifunction.c/.h: The template for an instance function
* ifunction_overloaded.c: The template for the implementation of an overloaded function. An
overloaded function is exactly the same as a function, but it has an array of functions sharing
the same name. The current implementation for spidermonkey only works if the overloading is with
different number of arguments.
* sfunction.c/.h: The template for a static function
* sfunction_overloaded.c: The template for an overloaded static function
* register.c: Here you should add the constructor/finalizer, the registration function (if needed)
and the footer of the header file. This is the last chunk being generated

Templates are stored in the `templates/${target}` directory and follow the naming specified above.

One final part of the puzzle is the `${target}.yaml` file, that contains specific type conversion
snippets to be used by the templates. For instance, for spidermonkey, this is the place where we
specify the conversion routines for the native types (to and from int, float, string, etc.)

# Limitations

Currently the generator is leveraging clang in order to get information about the C/C++ code, so we
can only get as much information as clang give us. Known list of things that won‘t work:

* variable number of arguments. Solution: write a manual wrapper

时间: 2024-07-29 04:21:19

cocos2d-js3.5 mac上自动绑定c++到js的相关文章

Mac上git自动补全功能

在Mac上安装了git之后,发现命令不能自动补全,使用起来非常不方便,本文介绍怎么让git命令能够自动补全. 确保bash能够自动补全在终端(本文使用的是OS X的终端)执行如下命令: brew list 看看是否已经安装有bash-completion 如果没有安装,运行如下命令安装bash-completion: brew install bash-completion 等待安装完成之后,运行如下命令: brew info bash-completion 运行上面的命令后会在终端显示下图:

MAC上搭建Jenkins + Android + IOS自动开发部署环境

因为MAC是大小写不敏感的操作系统,很多Linux命令不支持,所以首先要创建大小写敏感的操作系统. 设置静态IP 打开"System Preferences..." 点击"Network" 设置静态IP 设置Terminal 在"Utilities"中找到Terminal,点击"Terminal" 右击Terminal图标,选择"Options" -> "Keep in Dock"

Mac如何自动发邮件给kindle推送文档

买过kindle的人一定对于它推送的服务印象深刻,只要你的kindle联网在,即便它被放在家里,你也可以在办公室给它发送书籍,等你回家就会发现,书籍已经自动下载好了,在不同平台下(Mac,windows等)都有相应的Send to kindle应用程序,有些程序是不支持中国亚马逊账户的,但我们可以采用通用的方式,通过邮件推送,可能有些人觉得发邮件很麻烦,但如果能实现自动发送邮件,你是否还这样觉得呢 首先需要准备如下几点 kindle绑定一个Amazon账号 在Amazon账户的个人文档设置里添加

在cocos2d-js实现自动绑定cocostudioUI控件与事件(二)

前两天有个刚学习使用cocos2d-js的同事问我,怎么实现一个功能:点击一个按钮UI显示计数加1,按住不放UI计数就不停的加. 这个功能不就是个长按事件吗?我给他描述了下实现长按事件的思路: 1. 在控件touchBegan时,使用 一次性定时器scheduleOnce传入touchLong函数,设定1秒后执行. 2.  touchLong触发时,开启schedule传入addOnce函数(ui显示计数加1),设定每0.1秒执行一次. 3.  在touchEnded时执行unschedule函

mac上安装python3 和 sqlite的问题

建议mac上安装python3不要使用源码自己编译安装,而要使用 brew install python3 来安装 另外安装完之后创建需环境的话,要指定新的python环境,如下: virtualenv  -p /usr/local/Cellar/python3/3.6.2/bin/python3  --no-site-packages obpy17 Mac OSX 正确地同时安装Python 2.7 和Python3 Mac OSX 正确地同时安装Python 2.7 和Python3(这个是

Laravel 框架在 Mac 上使用命令 npm run dev 时报错问题

我是看的Summer写的 Laravel 入门教程,用的 Mac 上 Homestead---Vagrant 第四章时一个步骤是要将 Laravel 默认生成的 .scss 文件编译成 .css 才行. 命令如下: npm run dev Linux 或 Mac 或 Windows 的环境都会碰到 cross-env 的问题,这时在评论方看到一个解决办法 其原理已经讲的很清楚了,算是 windows 的锅呗.貌似很多人通过这里的方法都解决了问题. 但是我这冥顽不灵,删除了 cross-env 还

XamarinAndroid 自动绑定View变量

Android 编程时我们少不了使用FindIdByView函数,在Xamarin Android开发时也需要如此.这个工作很无聊且烦人.在常规Android开发中,人们已经发明了一些方法免除这项工作,例如Android数据绑定,还有butterknife,都可以解决这个问题.关于它们我不去细说了.但是这两个方案在Xamarin Android开发里还无法使用.本文介绍一个函数,就可以把程序员从这项工作中解脱出来,原文请参见http://redth.codes/auto-wire-up-view

Mac上VirtualBox VS Parallels Desktop 以及 Ubuntu虚拟机多网卡设置

在Mac上使用过要license的Parallels Desktop和免费的VirtualBox,比较结果如下: 1. VirtualBox对鼠标的捕获和控制更加友好,Parallels需要按键来释放鼠标,但是VirtualBox里面完全自动. 2. VirtualBox里面虚拟机的运行速度似乎更快,至少关机比Parallels快. 3.VirutalBox里面可以很方便地复制虚拟机,但是在Parallels Desktop里面不知道什么原因“克隆”菜单为灰色不可用. 4. VirtualBox

appium1.6在mac上环境搭建启动ios模拟器上Safari浏览器

前言 在mac上搭建appium踩了不少坑,先是版本低了,启动后无限重启模拟器.后来全部升级最新版本,就稳稳的了. 环境准备: 1.OS版本号10.12 2.xcode版本号8.3.2 3.appium版本号1.6.4(appium-desktop1.1.0) 4.ios模拟器版本号10.3 一.OS10.12 1.这里Mac上的OS系统一定要升级到10.12,低于10.12是无法安装8.3.2的xcode版本的 2.下载地址:https://www.apple.com/macos/sierra