当前位置:首页 » 编程软件 » 苹果编译环境搭建

苹果编译环境搭建

发布时间: 2023-02-13 16:24:13

‘壹’ MAC OSX用Xcode编译webkit,有详细的步骤吗

1.使用Xcode软件。Xcode是一个苹果系统上的集成开发环境(IDE),就是说用Xcode就能编写c语言程序,并编译运行。也能开发ios程序等,是一种软件。在windows上类似这种能编c语言的还有微软出的visual studio,和其他免费的一些如codeblocks,c-free等。
在Xcode中编译运行C/C++的操作步骤:
1)打开Xcode,在欢迎界面点击Create a new Xcode project。
2)弹出一个对话框,在左侧栏选择Mac OS X分类的Application,右侧选择Command Line Tool,点击Next。
3)在Proct Name填写项目名称,如HelloMac,其余默认即可(type里也可以选择C或C++),点击Next后选择路径并点击Create完成项目创建。
4)在Xcode主界面左侧点击main.m,把代码替换成C/C++的代码,点击左上角的Run按钮即可编译运行,界面下方会弹出控制台显示运行结果。

‘贰’ M1芯片Mac搭建前端开发环境

M1芯片出来了有一段时间了,各类软件的兼容性已经跟进的差不多了,迫于 M1 实在太香,我的 M1 Macbook 也于本周到达了我的手上。在花费了两三个小时搭建完开发环境后,立马用它开始干活了。这几天的感受只有寥寥一语可以概括:太 TM 香了!太强了

作为一个前端开发者,我可以负责任的说前端开发的场景 M1 已经可以完全覆盖,并且体验非常好。目前我依赖的开发环境,并且已经跑在 M1 Mac 上的如下:适配 m1 的 Vscode Insiders 版本 + Node v15(on arm) + Node v14 (on intel) + Nvm + Cocoapods + Xcode + Flutter。可以看到,大前端这一套是完全能够覆盖的。

我在 github 的 issue 中经常看到有关于 m1 安装环境的问题,为了帮助不愿意翻 issue 的开发者,遂决定写下这篇文章记录前端环境的搭建问题。

我会从以下几个步骤来记录:

Xcode 是苹果开发者工具,是一个功能非常强大的 IDE,可以用来开发苹果应用,并且自带了 git 环境, 并且有咱们后续依赖的 Xcode Command line tool , 先进入 app store 中安装 Xcode。安装好之后再进入后续步骤

如果你是一个 mac 老用户,那自然不用我介绍什么是 Homebrew 。若是你是一个新用户,那么请你一定要安装 Homebrew ,并使用它来管理 Mac 中的各类环境依赖。通过👇的命令即可安装 Homebrew

在终端中执行如下命令安装 Homebrew,安装 Homebrew 的时候,常常会因为网络问题导致安装失败,这个问题只能依赖大家自行解决科学上网了。

Nvm 是一个管理 Node 版本的工具,当项目多了以后,总会碰到需要切换 Node 环境的时候,所以推荐大家使用 Nvm 来安装 Node。

若是你已经按上述步骤安装好了 Homebrew,那么你可以直接通过 Homebrew 的命令轻松安装 Nvm

若是你不想使用 Homebrew 管理依赖,那么用 👇 的 curl 直接安装 Nvm 也是可以的

安装好 nvm 后,需要将环境变量写入我们的 shell 配置文件中。

如果你的默认 shell 的 zsh,那么将环境变量命令复制进 .zshrc :

如果不使用 zsh,那么将环境变量复制进 bash 中,通过如下命令创建 bash_profile,并且编辑 bash_profile。

最后将以下环境变量脚本 进 shell 配置文件中:

至此 Nvm 已经安装好,可以尝试在命令行中输入 nvm,你可以看到 nvm 已经正常工作了。

接下来我们通过 nvm 来安装 Node,我们先安装适配了 M1 的 node 版本。

该命令运行完后,会执行很久,编译 node ,大家耐心等就好了,大概需要 5-10 分钟,就会提示安装成功。再提醒一句,报任何错误,首先先检查是不是网络问题,例如 443 、 connect timeout 等,如果是网络问题,建议科学上网。

安装 Node 的部分写的很简单,因为按这个步骤,一般不会出问题。而当你用 nvm 尝试去安装 v14 及以下的 Node 版本时,大概率会报错,而我们在工作中恰恰又可能依赖 v14 及以下的 lts 版本。那么为什么会报错呢?究其原因还是因为低版本的 node 并不是基于 arm64 架构的,所以不适配 M1 芯片。在这里教大家两个方法,就能成功安装上低版本 Node。

在终端中,输入:

通过这个命令可以让 shell 运行在Rosetta2下。
之后你可以通过 nvm install v12 来安装低版本 Node。
在此之后,您可以不用在 Rosetta2 中就可以使用安装的可执行文件,也就是说,您可以将 Node v15与其他节点版本互换使用。

方法二就是通过 Rosetta2 来启动终端,这样通过 Rosetta2 转译到 x86 架构中执行安装,也一样可以安装成功。

至此,我们的 M1 就已经完成了 git + 各版本 Node + npm 的搭建,完成这部分工作后,前端项目已经可以正常运行,各位买了 M1 Mac 的前端小伙伴又能愉快的干活了。希望本文能够帮助被 M1 的开发环境困扰过的您。

‘叁’ 如何在苹果系统上安装PyQt4

安装PtQt4前你需准备:

  1. Xcode(10.6.1 自带Xcode)

  2. Qt

  3. SIP

  4. PyQt4

创建了一个pyqt文件夹在硬盘根目录下,并将sip-4.12.1.tar.gz和PyQt-mac-gpl-snapshot-4.8.4.tar.gz放到其中并解压

1、先安装qt,默认安装,这一步大部分人不会有问题,跳过。

2、接下来,打开终端(Terminal,在 Applications(应用程序)/Utilities(实用工具)/ 下),在终端输入:export VERSIONER_python_PREFER_32_BIT=yes。

3、使用"cd 路径"命令将当前目录设为sip-4.12.1,如: cd /pyqt/sip-4.12.1/, 然后进行配置(configure)【Re-build SIP in 32bit】在终端中执行

python configure.py --arch i386
配置(configure)完成后就开始编译,在终端中执行引用make clean(清除以前的安装信息)make
编译完成后就安装,在终端中执行引用sudo make install


在这个过程中没出现错误就是安装成功了

编译安装PyQt4,过程和上面的一样。 【Build PyQt4 in 32bit 】
在终端中使用"cd 路径"命令将当前目录设为PyQt-mac-gpl-snapshot-4.8.4,如

引用cd /Users/schi/pyqt/PyQt-mac-gpl-snapshot-4.8.4

然后进行配置(configure),在终端中执行引用python configure.py --use-arch i386
配置时会遇到引用Determining the layout of your Qt installation...
This is the GPL version of PyQt 4.6 (licensed under the GNU General Public
License) for Python 2.6.2 on darwin.

Type '2' to view the GPL v2 license.
Type '3' to view the GPL v3 license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.

Do you accept the terms of the license?


输入yes,再按回车就行

配置(configure)完成后就开始编译,在终端中执行

引用make cleanmake


编译比较花时间,请耐心等待。

编译完成后就安装,在终端中执行

引用sudo make install


在这个过程中没出现错误就是安装成功了

也可以在IDLE中导入PyQt4的模块,能成功导入就说明安装成功

Python代码

fromPyQt4importQtCore,QtGui

下面分析一下安装过程中可能遇到的问题:

1.问题如下

##############

ld: warning: in /Library/Frameworks/Python.framework/Python, missing required architecture x86_64 in file
Undefined symbols:
"_Py_Initialize", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyLong_AsVoidPtr", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyErr_Print", referenced from:
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyString_FromString", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyType_IsSubtype", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyMole_GetDict", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_CallObject", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_CallFunctionObjArgs", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyList_Append", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_Py_IsInitialized", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyDict_Next", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyImport_ImportMole", referenced from:
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_GetAttrString", referenced from:
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [libpythonplugin.dylib] Error 1
make: *** [all] Error 2
这个问题的原因就是:qt是在32位mac上编译的,但pyqt默认是在64位机子上编译的,所以我们在编译的时候要制定编译环境:是i386 还是x86_64.

请参考如下的信息:

The problem is that the Qt library is 32bit while, by default, python builds PyQt4 in 64bit. That caused problem when it tried to link 64bit object files with 32bit Qt library. To fix this issue, we need to force python to build PyQt4 in 32bit, and we also need to re-build SIP in 32bit mode.If you use the python version that comes with Mac OS (2.5 for Snow Leopard), make sure that it runs in 32bit mode by issuing the command

2.个问题如下:


>>> from PyQt4 import QtGui

Traceback (most recent call last):

File "<stdin>", line 1, in <mole>

ImportError: dlopen(/Library/Python/2.6/site-packages/PyQt4/QtGui.so, 2): Symbol not found: __

Referenced from: /Library/Python/2.6/site-packages/PyQt4/QtGui.so

Expected in: flat namespace

in /Library/Python/2.6/site-packages/PyQt4/QtGui.so


这个问题是所有的包安装都没有问题但是当导入QtGui或其他包时,总报这个问题,这个问题的原因是,当前pyqt release的包本身带的一个bug,PyQt-mac-gpl-snapshot-4.8.3,所以你下载下个要release的包就可以了。如我下的是:PyQt-mac-gpl-snapshot-4.8.4。

下面给大家介绍一下我写的自动安装这些程序的python源码

#!/usr/bin/env python
"""
Automated installer for Python 2.6 (final)

This installer is able to handle any previous
versions of Python.

NOTE: This file *must* be copied to
//nssgsvr/tools/pyInstall_OSXwhen modified!

"""

import os
import sys
import re
import shutil
import platform
import tarfile

# Constants
PYTHON_PKGS = {"dmgFile" : "python-2.6.1-macosx2008-12-06.dmg",
"mpkgList": ["MacPython.mpkg"] }
#WXPYTHON_PKGS = {"dmgFile" : "wxPython2.8-osx-unicode-2.8.9.2-universal-py2.6.dmg",
# "mpkgList": ["wxPython2.8-osx-unicode-universal-py2.6.pkg"] }
#ANGELIA
XCODE_PKGS = {"dmgFile" : None, "mpkgList": ["Xcode.mpkg"]}

QT_PKGS = {"dmgFile" : "qt-mac-cocoa-opensource-4.6.2.dmg",
"mpkgList": ["Qt.mpkg"] }

THIRD_PARTY_INSTALL = ["sip-4.12.1", "PyQt-mac-gpl-snapshot-4.8.4","Pyro-3.9.1", "pyserial-2.4"]

# Environment constants
TCSH_ENV_FILE = '/etc/csh.login'
BASH_ENV_FILE = '/etc/profile'
SCRIPTS_ROOT_ENV = "TEST_SCRIPTS_ROOT"

TARGET_VER = "2.6"
IS_POSIX = (os.name == 'posix')
IS_MAC = (sys.version.find('Apple') != -1)
IS_OSX = (IS_MAC and IS_POSIX)
IS_OSX_LEOPARD = (IS_OSX and platform.mac_ver()[0].startswith('10.5'))
IS_OSX_SNOWLEOPARD = (IS_OSX and platform.mac_ver()[0].startswith('10.6'))

# NSSGSVR Constants
MOUNT_POINT = "/Volumes/Test"
HOSTSERVER = "NSSGSVR.global.avidww.com" # Server that contains SQA scripts
SHARE = "TEST" # NSSGSVR share that contains the Python scripts directory
USER = "qatest"
PASSWD = "Cmqat/$/$/$" # slashes needed to escape special character '$'

##################################################################################

class InstallerError(Exception):
""" Installer Exception class """
def __init__(self, description):
self.desc = description

def __str__(self):
return self.desc

class PkgInstaller:
""" Installer class for pkg files."""
def __init__(self, packageName, mpkgList, dmgFile = None ):
"""
packageName (str) Name of "package" to be installed
dmgFile (str) Path to dmg file to mount
mpkgList (list) List of mpkg files to launch when dmg file is mounted
"""
self.dmgFile = dmgFile
self.packageName = packageName
self.mpkgList = mpkgList

self.mountpoint = os.path.join(os.getcwd(), self.packageName)
self.removeMountPoint = False

if not type(self.mpkgList) == list:
raise InstallerError("Expected list for parameter mpkgList received %s" % /
type(self.mpkgList))

# Mountroot must exist for hdiutil to succeed.
if not os.path.exists(self.mountpoint):
print "Creating mountroot %s" % (self.mountpoint)
os.makedirs(self.mountpoint)
self.removeMountPoint = True

def _cleanup(self):
"""
## Performs cleanup
"""
unmount_cmd = "hdiutil unmount %s" % (self.mountpoint)

if self.dmgFile:
print "Unmounting %s" % (self.mountpoint)
ret = os.system(unmount_cmd)
if ret:
raise InstallerError("hdiutil unmount of %s failed: errno %d" % /
(self.mountpoint, ret))

if self.removeMountPoint:
print "Removing directory %s" % (self.mountpoint)
os.rmdir(self.mountpoint)

def _mount_dmg(self):
""" Mounts the dmg file. """
hdiutil_mount = "hdiutil mount %s -mountpoint %s" % (self.dmgFile,
self.mountpoint)

if os.path.exists(self.dmgFile):
print "Mounting %s" % (self.dmgFile)
ret = os.system(hdiutil_mount)
if ret:
raise InstallerError("hdiutil mount of %s failed: errno %d" % (self.dmgFile, ret))
else:
raise InstallerError("DMG file %s does not exist" % (self.dmgFile))

def _launch_pkgs(self):
""" Launches the pkg installers. """
for install_file in self.mpkgList:
if install_file.endswith('pkg'):
install_path = os.path.join(self.mountpoint, install_file)
if not os.path.exists(install_path):
raise InstallerError("File %s does not exist" % (install_path))
# 'installer' is Apple's package installer tool.
# -pkg specifies the package to be installed
# -target specifies the destination install volume
# -allow allows the installer to automatically upgrade any previous packages
# see 'man installer' for more details.
cmd = 'installer -pkg "%s" -target / -verbose -allow' % (install_path)
ret = os.system(cmd)
if ret:
msg = "Package %s failed to install: err %d" % (install_file, ret)
raise InstallerError(msg)
else:
raise InstallerError("File %s is not a valid package file" % install_file)

def install(self):
""" Main installer method. """

print "Installing package %s" % (self.packageName)
if self.dmgFile:
self._mount_dmg()
self._launch_pkgs()
self._cleanup()
print "Finished installing package %s" % (self.packageName)

def set_all_test_scripts_root(path):
"""
## Sets TEST_SCRIPTS_ROOT to <path> for
## both Bash and Tcsh shells if needed.
"""
bash_line = 'export TEST_SCRIPTS_ROOT="%s"' % (path)
tcsh_line = 'setenv TEST_SCRIPTS_ROOT "%s"' % (path)

‘肆’ 如何使用xcodebuild在命令行编译iOS工程

、准备工作 1、jenkins环境。搭建jenkins环境可以参考jenkins平台搭建和配置一节。需要注意的是,虽然涉及iOS开发,但是jenkins平台却不必搭建在mac机器上,只要在jenkins上添加mac节点就可以了。 2、iOS开发环境。iOS开发环境主要是指Xcode开发环境,Xcode是免费的,只要在苹果应用商店里下载一个就可以了。当然,还有重要的一点儿---开发者证书,现在个人也已经有免费的证书了,没有证书的话,只能打模拟器用的包了。 3、git项目。强烈建议把代码放在git上,这样便于团队开发。当然,不放git上也可以。 4、jenkins Xcode持续集成插件。常用的插件Xcode integration,这个插件能够快速的帮助我们进行Xcode打包配置,当然,只用纯shell脚本也是可以的。 在jenkins上打包之前,我们最好手工测试一下可以打包成功,首先用Xcode图形界面进行测试,然后用命令行测试,如果都能打包成功就可以挂在jenkins上运行了,毕竟jenkins的原理也是通过执行一系列命令来完成的。 三、jenkins配置 1、创建一个任务,创建任务的时候最好选自由风格的软件项目,这样配置起来比较方便,如果有需要,也可以选择其他的风格。 2、描述

‘伍’ 用苹果系统终端编写c语言之后怎么运行

若要在 Mac 的终端中编译并运行 C 源代码,你首先需要安装 Command Line Tools,里面包含有 GCC 编译器。安装方法为:

打开终端,输入 gcc。
如果你没有安装 Command Line Tools,会弹出一个窗口提示你安装,如图所示,点击安装即可。如果出现提示“clang_error: no input files”,说明你已经安装了 gcc 编译器,可以直接开始编译程序。

在终端中输入 ./可执行文件的名称 即可执行你的程序。例如,我输入

. est1

后,就可以执行程序了。如果提示你 Permission Denied,则是因为你没有赋予这个文件执行权限,需要在终端里输入

chmod u+x test //(最后参数为你的文件名,来使其可在你的账户下执行)1

如果运行时出现 Segmentation Fault,则说明你的代码里有 bug 导致程序崩溃。

‘陆’ 苹果电脑怎么写代码

1、使用Xcode软件。Xcode是一个苹果系统上的集成开发环境(IDE),就是说用Xcode就能编写C语言程序,并编译运行。也能开发ios程序等,是一种软件。2、在windows上类似这种能编

1、使用Xcode软件。
Xcode是一个苹果系统上的集成开发环境(IDE),就是说用Xcode就能编写C语言程序,并编译运行。也能开发ios程序等,是一种软件。
2、在windows上类似这种能编c语言的还有微软出的visualstudio,和其他免费的一些如codeblocks,c-free等。
您好,苹果电脑可以下载苹果开发工具应用来编写代码。可以到苹果应用商店里去搜索查询,并安装开发工具就可以开始编写代码了

‘柒’ 苹果MAC系统怎么编译C语言

在 Mac OS X 下学习C语言使用 Xcode。

在 Xcode 上运行C语言程序需要先创建工程,再在工程中添加源代码。

1、 打开 Xcode,选择“Create a new Xcode project”创建一个新工程,如下图所示:

左侧是工程目录,主要包含了工程所用到的文件和资源。单击“main.c”,即可进入代码编辑模
式,这里 Xcode 已经为我们创建好了一个“Hello World”小程序。点击上方的“运行”按钮,即
可在右下角的选项卡中看到输出结果。

拓展资料

Xcode是由Apple官方开发的IDE,支持C、C 、 Objective-C、Swift等,可以用来开发 Mac OS X 和 iOS上的应用程序。Xcode最初使用GCC作为 编译器,后来由于GCC的不配合,改用LLVM。

‘捌’ 苹果电脑上可以装c语言编译器吗

在苹果电脑上可以装c语言编译器,因为Mac系统本质上是一个Unix系统,是一个开放系统,Unix系统的编写语言就是C语,兼容C语言编译器是肯定的了。

目前苹果的操作系统Mac OS X的开发工具为Xcode,支持C和标准C++程序的编写。并且Mac平台有很多支持C语言编程的IDE,像NetBeans和Eclipse。

Mac OS X没有默认安装C语言编译器,你需要安装Xcode,Xcode包含了GCC编译器。

如果你只是用Mac来学习C语言,安装一个Xcode即可。Xcode的安装文件在系统盘的Optional文件夹里。

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:748
制作脚本网站 发布:2025-10-20 08:17:34 浏览:1012
python中的init方法 发布:2025-10-20 08:17:33 浏览:718
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:878
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:774
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1127
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:351
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:229
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:911
python股票数据获取 发布:2025-10-20 07:39:44 浏览:875