修改Cocos2d-X-3.2中的setup.py, 使其能用python3

Cocos2d-x的最新版是v3.2,下载地址为:http://cn.cocos2d-x.org/download/

在运行setup.py时,他会提示你安装python2.7,因为这个版本是他们"well tested"。

 

但是我电脑上已经安装了python3.3,又不想因为这事而卸载python3.3再重新安装python2.7, 于是就尝试修改setup.py文件。修改后的setup.py如下:

 

#!/usr/bin/python
#coding=utf-8
"""****************************************************************************
Copyright (c) 2014 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************"""
'''
This script will install environment variables needed to by cocos2d-x. It will set these envrironment variables:
* COCOS_CONSOLE_ROOT: used to run cocos console tools, more information about cocos console tools please refer to 
https://github.com/cocos2d/cocos2d-console
* NDK_ROOT: used to build android native codes
* ANDROID_SDK_ROOT: used to generate applicatoin on Android through commands
* ANT_ROOT: used to generate applicatoin on Android through commands
On Max OS X, when start a shell, it will read these files and execute commands in sequence:
~/.bash_profile
~/.bash_login
~/.profile
And it will read only one of them. So we will add environment variable in the same sequence.
Which means that
* add environment variables into ~/.bash_profile if it exists
* otherwise it will the add environment variables into ~/.bash_login if it exists
* otherwise it will the add environment variables into ~/.profile if it exists
Will create ~/.bash_profile when none of them exist, and add environment variables into it.
'''
import os
import sys
import fileinput
import shutil
import subprocess
from optparse import OptionParser
COCOS_CONSOLE_ROOT = 'COCOS_CONSOLE_ROOT'
NDK_ROOT = 'NDK_ROOT'
ANDROID_SDK_ROOT = 'ANDROID_SDK_ROOT'
ANT_ROOT = 'ANT_ROOT'
def _check_python_version():
major_ver = sys.version_info[0]
print ("The python version is %d.%d" % (major_ver, sys.version_info[1]))
return True
class SetEnvVar(object):
RESULT_UPDATE_FAILED = -2
RESULT_ADD_FAILED = -1
RESULT_DO_NOTHING = 0
RESULT_UPDATED = 1
RESULT_ADDED = 2
MAC_CHECK_FILES = [ '.bash_profile', '.bash_login', '.profile' ]
LINUX_CHECK_FILES = [ '.bashrc' ]
ZSH_CHECK_FILES = ['.zshrc' ]
RE_FORMAT = r'^export[ \t]+%s=(.+)'
def __init__(self):
self.need_backup = True
self.backup_file = None
self.current_absolute_path = os.path.dirname(os.path.realpath(__file__))
self.file_used_for_setup = ''
def _isWindows(self):
return sys.platform == 'win32'
def _isLinux(self):
return sys.platform.startswith('linux')
def _is_mac(self):
return sys.platform == 'darwin'
def _is_zsh(self):
shellItem = os.environ.get('SHELL')
if shellItem is not None:
if len(shellItem) >= 3:
return shellItem[-3:] == "zsh"
return False
def _get_unix_file_list(self):
file_list = None
if self._is_zsh():
file_list = SetEnvVar.ZSH_CHECK_FILES
elif self._isLinux():
file_list = SetEnvVar.LINUX_CHECK_FILES
elif self._is_mac():
file_list = SetEnvVar.MAC_CHECK_FILES
return file_list
def _get_filepath_for_setup(self):
file_list = self._get_unix_file_list();
file_to_write = None
if file_list is None:
return ''
home = os.path.expanduser('~')
for file_name in file_list:
file_path = os.path.join(home, file_name)
if os.path.exists(file_path):
file_to_write = file_path
break
if file_to_write is None:
self.need_backup = False
file_to_write = os.path.join(home, file_list[0])
file_obj = open(file_to_write, 'w')
file_obj.close()
return file_to_write
# modify registry table to add an environment variable on windows
def _set_environment_variable_win32(self, key, value):
ret = False
import winreg
try:
env = None
env = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER,
'Environment',
0,
winreg.KEY_SET_VALUE | winreg.KEY_READ)
winreg.SetValueEx(env, key, 0, winreg.REG_SZ, value)
winreg.FlushKey(env)
winreg.CloseKey(env)
ret = True
except Exception:
if env:
winreg.CloseKey(env)
ret = False
return ret
def _gen_backup_file(self):
file_name = os.path.basename(self.file_used_for_setup)
file_path = os.path.dirname(self.file_used_for_setup)
backup_file_name = file_name + ".backup"
path = os.path.join(file_path, backup_file_name)
i = 1
while os.path.exists(path):
backup_file_name = file_name + ".backup%d" % i
path = os.path.join(file_path, backup_file_name)
i += 1
return path
def _set_environment_variable_unix(self, key, value):
if self.need_backup:
# backup the environment file
self.backup_file = self._gen_backup_file()
shutil.copy(self.file_used_for_setup, self.backup_file)
self.need_backup = False
file = open(self.file_used_for_setup, 'a')
file.write('\n# Add environment variable %s for cocos2d-x\n' % key)
file.write('export %s=%s\n' % (key, value))
file.write('export PATH=$%s:$PATH\n' % key)
if key == ANDROID_SDK_ROOT:
file.write('export PATH=$%s/tools:$%s/platform-tools:$PATH\n' % (key, key))
file.close()
return True
def _set_environment_variable(self, key, value):
print("  -> Add %s environment variable..." % key)
ret = False
if self._isWindows():
ret = self._set_environment_variable_win32(key, value)
else:
ret = self._set_environment_variable_unix(key, value)
if ret:
print("	->Added %s=%s\n" % (key, value))
else:
print("	->Add failed\n")
return ret
def _search_unix_variable(self, var_name, file_name):
if not os.path.isfile(file_name):
return None
import re
str_re = SetEnvVar.RE_FORMAT % var_name
patten = re.compile(str_re)
ret = None
for line in open(file_name):
str1 = line.lstrip(' \t')
match = patten.match(str1)
if match is not None:
ret = match.group(1)
return ret
def _find_environment_variable(self, var):
print("  ->Search for environment variable %s..." % var)
ret = None
try:
ret = os.environ[var]
except Exception:
if not self._isWindows():
file_list = self._get_unix_file_list()
if file_list is not None:
home = os.path.expanduser('~')
for name in file_list:
path = os.path.join(home, name)
ret = self._search_unix_variable(var, path)
if ret is not None:
break
else:
import winreg
try:
env = None
env = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER,
'Environment',
0,
winreg.KEY_READ)
ret = winreg.QueryValueEx(env, var)[0]
winreg.CloseKey(env)
except Exception:
if env:
winreg.CloseKey(env)
ret = None
if ret is None:
print("	->%s not found\n" % var)
else:
print("	->%s is found : %s\n" % (var, ret))
return ret
def _get_input_value(self, var_name):
#ret = raw_input('  ->Please enter the path of %s (or press Enter to skip):' % var_name)
ret = input('  ->Please enter the path of %s (or press Enter to skip):' % var_name)
ret.rstrip(" \t")
return ret
#		 # python on linux doesn't include Tkinter model, so let user input in terminal
#		 if self._isLinux():
#			 input_value = raw_input('Couldn\'t find the "%s" envrironment variable. Please enter it: ' % sys_var)		
#		 else:
#			 # pop up a window to let user select path for ndk root
#			 import Tkinter
#			 import tkFileDialog
#			 self.tmp_input_value = None
#			 root = Tkinter.Tk()
#			 if sys_var == NDK_ROOT:
#				 root.wm_title('Set NDK_ROOT')
#			 else:
#				 root.wm_title('Set ANDROID_SDK_ROOT')
#			 def callback():
#				 self.tmp_input_value = tkFileDialog.askdirectory()
#				 root.destroy()
#			 if sys_var == NDK_ROOT:
#				 label_content = 'Select path for Android NDK:'
#				 label_help = """
# The Android NDK is needed to develop games for Android. 
# For further information, go to:
# http://developer.android.com/tools/sdk/ndk/index.html.
# You can safely skip this step now. You can set the NDK_ROOT later.
#				 """
#			 if sys_var == ANDROID_SDK_ROOT:
#				 label_content = 'Select path for Android SDK'
#				 label_help = """
# The Android SDK is needed to develop games for Android. 
# For further information, go to:
# https://developer.android.com/tools/sdk/ndk/index.html. 
# You can safely skip this step now. You can set the ANDROID_SDK_ROOT later.
#				 """
#			 Tkinter.Label(root, text=label_help).pack()
#			 Tkinter.Button(root, text=label_content, command=callback).pack()
#			 self._center(root)
#			 root.mainloop()
#			 input_value = self.tmp_input_value
#			 self.tmp_input_value = None
#		 return input_value
#	 # display a window in center and put it on top
#	 def _center(self, win):
#		 win.update_idletasks()
#		 width = win.winfo_width()
#		 height = win.winfo_height()
#		 x = (win.winfo_screenwidth() / 2) - (width / 2)
#		 y = (win.winfo_screenheight() / 2) - (height / 2)
#		 win.geometry('{}x{}+{}+{}'.format(width, height, x, y))
#		 win.wm_attributes('-topmost', 1)
def _check_valid(self, var_name, value):
ret = False
if var_name == NDK_ROOT:
ret = self._is_ndk_root_valid(value)
elif var_name == ANDROID_SDK_ROOT:
ret = self._is_android_sdk_root_valid(value)
elif var_name == ANT_ROOT:
ret = self._is_ant_root_valid(value)
else:
ret = False
if not ret:
print('	->Error: "%s" is not a valid path of %s. Ignoring it.' % (value, var_name))
return ret
def _is_ndk_root_valid(self, ndk_root):
if not ndk_root:
return False
ndk_build_path = os.path.join(ndk_root, 'ndk-build')
if os.path.isfile(ndk_build_path):
return True
else:
return False
def _is_android_sdk_root_valid(self, android_sdk_root):
if not android_sdk_root:
return False
if self._isWindows():
android_path = os.path.join(android_sdk_root, 'tools', 'android.bat')
else:
android_path = os.path.join(android_sdk_root, 'tools', 'android')
if os.path.isfile(android_path):
return True
else:
return False
def _is_ant_root_valid(self, ant_root):
ant_path = ''
if self._isWindows():
ant_path = os.path.join(ant_root, 'ant.bat')
else:
ant_path = os.path.join(ant_root, 'ant')
if os.path.isfile(ant_path):
return True
else:
return False
def remove_dir_from_win_path(self, remove_dir):
import winreg
try:
env = None
path = None
env = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER,
'Environment',
0,
winreg.KEY_SET_VALUE | winreg.KEY_READ)
path = winreg.QueryValueEx(env, 'Path')[0]
path_lower = path.lower()
remove_dir = remove_dir.replace('/', '\\')
remove_dir_lower = remove_dir.lower()
start_pos = path_lower.find(remove_dir_lower)
if (start_pos >= 0):
length = len(remove_dir_lower)
need_remove = path[start_pos:(start_pos + length)]
path = path.replace(need_remove, '')
path = path.replace(';;', ';')
winreg.SetValueEx(env, 'Path', 0, winreg.REG_SZ, path)
winreg.FlushKey(env)
winreg.CloseKey(env)
print('  ->Remove directory \"%s\" from PATH!\n' % remove_dir)
except Exception:
print('  ->Remove directory \"%s\" from PATH failed!\n' % remove_dir)
def set_windows_path(self, add_dir):
ret = False
import winreg
try:
env = None
path = None
env = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER,
'Environment',
0,
winreg.KEY_SET_VALUE | winreg.KEY_READ)
path = winreg.QueryValueEx(env, 'Path')[0]
# add variable if can't find it in PATH
path_lower = path.lower()
add_dir_lower = add_dir.lower()
if (path_lower.find(add_dir_lower) == -1):
path = add_dir + ';' + path
winreg.SetValueEx(env, 'Path', 0, winreg.REG_SZ, path)
winreg.FlushKey(env)
winreg.CloseKey(env)
ret = True
except Exception:
if not path:
path = add_dir
winreg.SetValueEx(env, 'Path', 0, winreg.REG_SZ, path)
winreg.FlushKey(env)
ret = True
else:
winreg.SetValueEx(env, 'Path', 0, winreg.REG_SZ, path)
winreg.FlushKey(env)
ret = False
if env:
winreg.CloseKey(env)
if ret:
print("  ->Add directory \"%s\" into PATH succeed!\n" % add_dir)
else:
print("  ->Add directory \"%s\" into PATH failed!\n" % add_dir)
def set_console_root(self):
print("->Check environment variable %s" % COCOS_CONSOLE_ROOT)
cocos_consle_root = os.path.join(self.current_absolute_path, 'tools', 'cocos2d-console', 'bin')
old_dir = self._find_environment_variable(COCOS_CONSOLE_ROOT)
if old_dir is None:
# add environment variable
if self._isWindows():
self.set_windows_path(cocos_consle_root)
self._set_environment_variable(COCOS_CONSOLE_ROOT, cocos_consle_root)
else:
if old_dir == cocos_consle_root:
# is same with before, nothing to do
return
# update the environment variable
if self._isWindows(): 
self.remove_dir_from_win_path(old_dir)
self.set_windows_path(cocos_consle_root)
self._force_update_env(COCOS_CONSOLE_ROOT, cocos_consle_root)
def _force_update_unix_env(self, var_name, value):
import re
home = os.path.expanduser('~')
str_re = SetEnvVar.RE_FORMAT % var_name
patten = re.compile(str_re)
replace_str = 'export %s=%s\n' % (var_name, value)
file_list = SetEnvVar.MAC_CHECK_FILES
if self._isLinux():
file_list = SetEnvVar.LINUX_CHECK_FILES
print("  ->Update variable %s in files %s" % (var_name, str(file_list)))
variable_updated = False
for file_name in file_list:
path = os.path.join(home, file_name)
if os.path.isfile(path):
lines = []
# read files 
need_over_write = False
file_obj = open(path, 'r')
for line in file_obj:
str_temp = line.lstrip(' \t')
match = patten.match(str_temp)
if match is not None:
variable_updated = True
need_over_write = True
lines.append(replace_str)
else:
lines.append(line)
file_obj.close()
# rewrite file
if need_over_write:
file_obj = open(path, 'w')
file_obj.writelines(lines)
file_obj.close()
print("	->File %s updated!" % path)
# nothing updated, should add variable
if not variable_updated:
print("\n  ->No files updated, add variable %s instead!" % var_name)
ret = self._set_environment_variable(var_name, value)
else:
ret = True
return ret
def _force_update_env(self, var_name, value):
ret = False
if self._isWindows():
print("  ->Force update environment variable %s" % var_name)
ret = self._set_environment_variable_win32(var_name, value)
if not ret:
print("	->Failed!")
else:
print("	->Succeed : %s=%s" % (var_name, value))
else:
ret = self._force_update_unix_env(var_name, value)
return ret
def _get_ant_path(self):
return self._get_sdkpath_for_cmd("ant", False)
def _get_androidsdk_path(self):
return self._get_sdkpath_for_cmd("android")
def _get_ndkbuild_path(self):
return self._get_sdkpath_for_cmd("ndk-build", False)
def _get_sdkpath_for_cmd(self, cmd, has_bin_folder=True):
ret = None
print("  ->Search for command " + cmd + " in system...")
if not self._isWindows():
import commands
state, result = commands.getstatusoutput("which " + cmd)
if state == 0:
ret = os.path.realpath(result)
ret = os.path.dirname(ret)
# Use parent folder if has_bin_folder was set
if has_bin_folder:
ret = os.path.dirname(ret)
if ret is not None:
print("	->Path " + ret + " was found\n")
else:
print("	->Command " + cmd + " not found\n")
return ret
def _find_value_from_sys(self, var_name):
if var_name == ANT_ROOT:
return self._get_ant_path()
elif var_name == NDK_ROOT:
return self._get_ndkbuild_path()
elif var_name == ANDROID_SDK_ROOT:
return self._get_androidsdk_path()
else:
return None
def set_variable(self, var_name, value):
print("->Check environment variable %s" % var_name)
find_value = self._find_environment_variable(var_name)
var_found = (find_value is not None)
action_none = 0
action_add = 1
action_update = 2
need_action = action_none
if var_found:
if value and self._check_valid(var_name, value):
# should update
need_action = action_update
else:
# do nothing
need_action = action_none
else:
if not value:
# find the command path in system
value = self._find_value_from_sys(var_name)
if not value:
value = self._get_input_value(var_name)
if value and self._check_valid(var_name, value):
# should add variable
need_action = action_add
else:
# do nothing
need_action = action_none
if need_action == action_none:
# do nothing
return SetEnvVar.RESULT_DO_NOTHING
elif need_action == action_add:
# add variable
if self._set_environment_variable(var_name, value):
return SetEnvVar.RESULT_ADDED
else:
return SetEnvVar.RESULT_ADD_FAILED
elif need_action == action_update:
# update variable
if self._force_update_env(var_name, value):
# update succeed
return SetEnvVar.RESULT_UPDATED
else:
# update failed
return SetEnvVar.RESULT_UPDATE_FAILED
else:
return SetEnvVar.RESULT_DO_NOTHING
def set_environment_variables(self, ndk_root, android_sdk_root, ant_root):
print('\nSetting up cocos2d-x...')
self.file_used_for_setup = self._get_filepath_for_setup()
self.set_console_root()
if self._isWindows():
print('->Configuration for Android platform only, you can also skip and manually edit your environment variables\n')
else:
print('->Configuration for Android platform only, you can also skip and manually edit "%s"\n' % self.file_used_for_setup)
ndk_ret = self.set_variable(NDK_ROOT, ndk_root)
sdk_ret = self.set_variable(ANDROID_SDK_ROOT, android_sdk_root)
ant_ret = self.set_variable(ANT_ROOT, ant_root)
# tip the backup file
if (self.backup_file is not None) and (os.path.exists(self.backup_file)):
print('\nA backup file \"%s\" is created for \"%s\".' % (self.backup_file, self.file_used_for_setup))
if self._isWindows():
print('\nPlease restart the terminal or restart computer to make added system variables take effect\n')
else:
print('\nPlease execute command: "source %s" to make added system variables take effect\n' % self.file_used_for_setup)
if __name__ == '__main__':
if not _check_python_version():
exit()
parser = OptionParser()
parser.add_option('-n', '--ndkroot', dest='ndk_root', help='directory of ndk root')
parser.add_option('-a', '--androidsdkroot', dest='android_sdk_root', help='directory of android sdk root')
parser.add_option('-t', '--antroot', dest='ant_root', help='directory that contains ant/ant.bat')
opts, args = parser.parse_args()
# set environment variables
env = SetEnvVar()
env.set_environment_variables(opts.ndk_root, opts.android_sdk_root, opts.ant_root)
if env._isWindows():
import ctypes
HWND_BROADCAST = 0xFFFF
WM_SETTINGCHANGE = 0x1A
SMTO_ABORTIFHUNG = 0x0002
result = ctypes.c_long()
SendMessageTimeoutW = ctypes.windll.user32.SendMessageTimeoutW
SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, u'Environment', SMTO_ABORTIFHUNG, 5000, ctypes.byref(result))


 

其实改的地方根本不多的,总的有3处:

1. 将import _winreg改成"import winreg"

2. 将raw_input改成"input"

3. 修改“_check_python_version()"使其返回True

 

经测试,这个setup.py运行已经可以完全正确了!至于该工程中的其他*.py文件未作测试,因为还没到执行的时候,相信如果要改的话,应该也不会多的,只要你愿意花时间。

我的测试平台是win7 x64, python3.3.5

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/403992.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

函数 devm_kzalloc()

函数 devm_kzalloc() 和kzalloc()一样都是内核内存分配函数,但是devm_kzalloc()是跟设备(device)有关的,当设备(device)被detached或者驱动(driver)卸载(unloaded)时,内存会被自动释放。另外,当内存不在使用时,可以使用…

第四层交换

一,第四层交换简述   第四层交换的一个简单定义是:它是一种功能,它决定 传输不仅仅依据MAC地址(第二层网桥)或源/目标IP地址(第 三层路由),而且依据TCP/UDP(第四层) 应用端口号。第四层 交换功能就象是虚IP,指向物理服务器。它传…

未能加载文件或程序集“Autofac, Version=3.4.0.0,

遇到这个错误的时候&#xff1a;如下图 未能加载文件或程序集“Autofac, Version3.4.0.0, Cultureneutral, PublicKeyToken17863af14b0044da”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 只要在config加上 <runtime><assemblyBinding xmlns"…

浅谈关于SRAM与DRAM的区别

从名字上看&#xff0c;SRAM与DRAM的区别只在于一个是静态一个是动态。由于SRAM不需要刷新电路就能够保存数据&#xff0c;所以具有静止存取数据的作用。而DRAM则需要不停地刷新电路&#xff0c;否则内部的数据将会消失。而且不停刷新电路的功耗是很高的&#xff0c;在我们的PC…

字符串系列之最长回文子串

2019独角兽企业重金招聘Python工程师标准>>> 问题描述&#xff1a; 给定一个字符串SA1A2...An&#xff0c;要求找出其最长回文子串&#xff08;Longest Palindromic Substring&#xff09;。所谓回文子串就是S的某个子串Ai...Aj为回文。例如&#xff0c;对字符串Sab…

在中断程序里修改全局变量的童鞋注意啦~(C中的volatile作用 转载~)

一个定义为volatile的变量是说这变量可能会被意想不到地改变&#xff0c;这样&#xff0c;编译器就不会去假设这个变量的值了。精确地说就是&#xff0c;优化器在用到这个变量时必须每次都小心地重新读取这个变量的值&#xff0c;而不是使用保存在寄存器里的备份。下面是volati…

设计模式:单例和简单工厂

单例设计模式&#xff1a;只实例化一个类的对象&#xff01; 1 public class Person2 {3 //1&#xff1a;首先定义一个静态变量4 //2&#xff1a;将该类的构造函数私有化5 //3&#xff1a;定义一个静态方法&#xff0c;将该类对象赋给这个静态变量6 …

python3学习者的福音

偶然发现python3.3.5下的一个非常有用的目录&#xff1a;D:\Embedded\Python33\Lib\lib2to3 这下面的类有详细的说明,关于python2到3所做的一些更改&#xff0c;特别是模块名等&#xff0c;这个非常有用&#xff0c;尤其是对那些参考python2的源码&#xff0c;现在却要用pytho…

powershell 中的pause

一直想在ps中实现cmd中pause的效果 开始用sleep,不理想 无意中试了一下 cmd /c "pause" 可以了 之前一直被“执行会新开一个线程”给误导了 看来可能是调用其它程序时会… ---------------------------------- 备忘&#xff1a; 传枚举值&#xff0c;只要使用枚举值的…

错误:unrecognized command line option “-std=c++11”

From: http://my.oschina.net/chenyoca/blog/226455 摘要出现这个编译错误的原因在g gcc 版本不够高。目录[-] 添加源&#xff08;Ubuntu&#xff09; 安装4.8版本 查看本地安装版本 切换版本 再次查看g版本 出现这个编译错误的原因在g gcc 版本不够高。 添加源&#xff08;Ubu…

Java反射机制深入研究

ava 反射是Java语言的一个很重要的特征&#xff0c;它使得Java具体了“动态性”。在Java运行时环境中&#xff0c;对于任意一个类&#xff0c;能否知道这个类有哪些属性和方法&#xff1f;对于任意一个对象&#xff0c;能否调用它的任意一个方法&#xff1f;答案是肯定的。这种…

编写安全 PHP 应用程序的七个习惯

在提及安全性问题时&#xff0c;需要注意&#xff0c;除了实际的平台和操作系统安全性问题之外&#xff0c;您还需要确保编写安全的应用程序。在编写 PHP 应用程序时&#xff0c;请应用下面的七个习惯以确保应用程序具有最好的安全性&#xff1a; 验证输入保护文件系统保护数据…

linux内核字符设备文件的自动创建

手动创建&#xff1a;mknod自动创建设备文件的步骤&#xff1a;1.保证根文件系统支持mdev可执行程序mdev将来是创建设备文件的真正的人&#xff01;which is mdev //查看mdev的路劲2.保证文件系统的etc目录下有fstab文件&#xff0c;文件内容必须有&#xff1a;proc /proc …

软件工程概论课堂作业3

题目&#xff1a;返回一个整数数组中最大子数组的和 要求&#xff1a; 输入一个一维整形数组&#xff0c;数组里有正数也有负数。 一维数组首尾相接&#xff0c;象个一条首尾相接带子一样。 数组中连续的一个或多个整数组成一个子数组&#xff0c;每个子数组都有一个和。 求所有…

Android硬件访问服务框架思想初识

Android的硬件访问服务提供了一个APP调用硬件实现的方法模型。我们从上往下来看。应用层面对的都是一个个的服务叫service.比如电源管理服务&#xff0c;震动服务等等。应用层代码首先就需要去查询系统是否存在这么一个服务&#xff0c;或者目前是不是可以被获取的。从这个角度…

Ubuntu更新过程被中断后的问题

From: http://defe.me/os/368.html Ubuntu的更新过程是先下载完源里的文件就开始执行升级&#xff0c;如果涉及到一些因为版权或是其他问题没加入源的文件&#xff0c;在升级安装的中途再从第三方服务器上下载。有时需要下载的文件比较大&#xff0c;而网速又不给力&#xff0c…

机器码和字节码

什么是机器码 机器码 机器码(machine code)&#xff0c;学名机器语言指令&#xff0c;有时也被称为原生码&#xff08;Native Code&#xff09;&#xff0c;是电脑的CPU可直接解读的数据。 通常意义上来理解的话&#xff0c;机器码就是计算机可以直接执行&#xff0c;并且执行速…

shell脚本常用语句用法笔记

脚本基本语句用法笔记 grep -i 查询时不区分大小写 -n打印匹配的行号 -v 打印不匹配的行 -AX包括每次匹配之后X行 -BX包括每次匹配之后X行 cat /etc/passwd |grep student (-i 表示不关心大小写) 正则表达式中 ^代表开始 $代表结束 cat /etc/passwd|grep ^# -v (…

CI框架分页类

分页类1.分页类参数说明 base_url > 指向你的分页所在的控制器类/方法的完整的 URL, total_rows > 数据的总行数, per_page > 每页显示的项目, uri_segment > 自动检测哪一段包含页数, num_links > 放在当前页前后显示的链接数, 2.分页类使用 $this->load-&g…