用Xcode配置完美ACMer环境

前言

​ 作为\(ACMer\),需求大致为强大的文本编辑功能\((VIM)\),便捷的文件模版功能以及多文件编译功能。\(vscode\)虽然强大,但是与集成\(IDE\)相比其缺点也很明显,就是没有完美的\(Debug\)功能。而\(Xcode\)刚好有此功能,但是在其他方面却显得有些笨拙,经过在网上探查,逐步实现了\(Xcode+vim+多文件编译 +自定义模版\)等功能。下面就来一一介绍如何配置。

万能头文件

  • 打开\(Finder\)

  • 按快捷键:\(Command+Shift+G\)。

  • 输入路径:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
  • 创建名为"bits"的文件夹

  • 创建名为"stdc++.h"的文件

  • 文件中写入以下代码:

// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file stdc++.h
* This is an implementation file for a precompiled header.
*/
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
//#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
  • 保存退出即可。

Vim插件

  • 首先确认\(Xcode\)处于关闭状态
  • 因为\(Vim\)插件属于第三方软件,所以需要给其注册一个证书:
# 下载注册软件
git clone https://github.com/slegetank/ResignXcode.git # 进入安装目录
cd ResignXcode # 运行注册程序
python2.7 ResignXcode.py
  • 等待,可能时间比较长
  • 安装\(Vim\)插件:
# 确认 Xcode 指向 /Applications/Xcode.app/Contents/Developer
xcode-select -p # 下载 XVim2
git clone https://github.com/XVimProject/XVim2.git # 下载完毕后,进入目录
cd xvim2 # 安装
make
  • 安装完成后显示\(BUILD\ SUCCEEDED\)则表示安装成功。

  • 打开\(Xcode\)提示Unexpected code bundle "XXVim2.xcpplugin,选择Load Bundle 即可。

自定义模版格式

  • 打开\(Finder\)。
  • 按快捷键:\(Command+Shift+G\)
  • 输入文件路径:
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/Mac/Application/Command Line Tool.xctemplate
  • 复制文件\(TemplateInfo.plist\)到以下目录中:(没有文件夹的需要创建文件夹)
~/Library/Developer/Xcode/Templates/Application/My Command Line Tool.xctemplate
  • 修改\(TemplateInfo.plist\)文件:(根据需要自行修改第\(100\)行和最后一段)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Kind</key>
<string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
<key>Identifier</key>
<string>com.apple.dt.unit.commandLineTool</string>
<key>Ancestors</key>
<array>
<string>com.apple.dt.unit.base</string>
<string>com.apple.dt.unit.osxBase</string>
</array>
<key>Concrete</key>
<true/>
<key>SortOrder</key>
<integer>50</integer>
<key>Description</key>
<string>This template creates a command-line tool.</string>
<key>Targets</key>
<array>
<dict>
<key>ProductType</key>
<string>com.apple.product-type.tool</string>
<key>TargetIdentifier</key>
<string>com.apple.dt.commandLineToolTarget</string>
<key>BuildPhases</key>
<array>
<dict>
<key>Class</key>
<string>Sources</string>
</dict>
<dict>
<key>Class</key>
<string>Frameworks</string>
</dict>
<dict>
<key>Class</key>
<string>CopyFiles</string>
<key>DstPath</key>
<string>/usr/share/man/man1/</string>
<key>DstSubfolderSpec</key>
<string>0</string>
<key>RunOnlyForDeploymentPostprocessing</key>
<string>YES</string>
</dict>
</array>
</dict>
</array>
<key>Options</key>
<array>
<dict>
<key>Identifier</key>
<string>languageChoice</string>
<key>Name</key>
<string>Language:</string>
<key>Description</key>
<string>The primary implementation language for the command-line tool</string>
<key>Default</key>
<string>Swift</string>
<key>Type</key>
<string>popup</string>
<key>Values</key>
<array>
<string>Swift</string>
<string>Objective-C</string>
<string>C++</string>
<string>C</string>
</array>
<key>Units</key>
<dict>
<key>C</key>
<dict>
<key>Nodes</key>
<array>
<string>main.c:comments</string>
<string>main.c:include</string>
<string>main.c:main:content</string>
</array>
<key>Definitions</key>
<dict>
<key>main.c:include</key>
<string>#include &lt;stdio.h&gt;
</string>
<key>main.c:main:content</key>
<string>// insert code here...
printf(&quot;Hello, World!\n&quot;);
return 0;
</string>
</dict>
</dict>
<key>C++</key>
<dict>
<key>Nodes</key>
<array>
<string>main.cpp:include</string>
<string>main.cpp:main:content</string>
</array>
<key>Definitions</key>
<dict>
<key>main.cpp:include</key>
<string>#include &lt;bits/stdc++.h&gt;
using namespace std;
typedef int Int;
#define int long long
#define INF 0x3f3f3f3f
#define maxn 200000
int a[maxn];</string>
<key>main.cpp:main:content</key>
<string>ios::sync_with_stdio(false);
cin.tie(0);
return 0;
</string>
</dict>
</dict>
<key>Objective-C</key>
<dict>
<key>Nodes</key>
<array>
<string>main.m:comments</string>
<string>main.m:include</string>
<string>main.m:main:content</string>
</array>
<key>Definitions</key>
<dict>
<key>main.m:include</key>
<string>#import &lt;Foundation/Foundation.h&gt;
</string>
<key>main.m:main:content</key>
<string>@autoreleasepool {
// insert code here...
NSLog(@&quot;Hello, World!&quot;);
}
return 0;
</string>
</dict>
</dict>
<key>Swift</key>
<dict>
<key>Project</key>
<dict>
<key>Configurations</key>
<dict>
<key>Debug</key>
<dict>
<key>SWIFT_OPTIMIZATION_LEVEL</key>
<string>-Onone</string>
</dict>
<key>Release</key>
<dict>
<key>SWIFT_COMPILATION_MODE</key>
<string>wholemodule</string>
<key>SWIFT_OPTIMIZATION_LEVEL</key>
<string>-O</string>
</dict>
</dict>
</dict>
<key>Targets</key>
<array>
<dict>
<key>SharedSettings</key>
<dict>
<key>SWIFT_VERSION</key>
<string>5.0</string>
</dict>
</dict>
</array>
<key>Nodes</key>
<array>
<string>main.swift:comments</string>
<string>main.swift:include</string>
<string>main.swift:main:content</string>
</array>
<key>Definitions</key>
<dict>
<key>main.swift:include</key>
<string>import Foundation
</string>
<key>main.swift:main</key>
<dict>
<key>Beginning</key>
<string></string>
<key>End</key>
<string></string>
</dict>
<key>main.swift:main:content</key>
<string>print(&quot;Hello, World!&quot;)
</string>
</dict>
</dict>
</dict>
</dict>
</array>
<key>Definitions</key>
<dict>
<key>*:main</key>
<dict>
<key>Beginning</key>
<string>signed main() {</string>
<key>End</key>
<string>}</string>
<key>Indent</key>
<integer>1</integer>
</dict>
</dict>
</dict>
</plist>

多文件编译

  • 正常创建工程即可,当需要创建第二个文件时选择\(File->New->Target\)。然后正常创建一个\(Console\)文件。编译运行的时候,在窗口左上角选择要运行的文件即可。

用Xcode配置完美ACMer环境的更多相关文章

  1. 2016年最新mac下vscode配置golang开发环境支持debug

    网上目前还找不到完整的mac下golang环境配置支持,本人配置成功,现在整理分享出来. mac最好装下xcode,好像有依赖关系安装Homebrew打开终端窗口, 粘贴脚本执行/usr/bin/ru ...

  2. 越狱开发:用iosOpenDev配置越狱开发环境 编写第一个hello world-b

    上网搜索越狱环境搭建,查到iosOpenDev软件,是个很方便的编写插件,而且可以直接用Xcode创建的工具,便开始着手学习如何去安装 集合了网上的方法后,我安装的时候发现: 1.作者最后更新的时间是 ...

  3. macOS Mojave配置OpenGL开发环境

    ---恢复内容开始--- 前言: 本文写作目的: 是由于本人参考 csdn原文 的方法配置环境时踩了很多坑,所以在此写一篇文防止以后用到. 工具: Xcode CMake 步骤: 准备工作: Xcod ...

  4. 安装与配置Flutter开发环境

    这篇博客我们介绍了Flutter,并且对比了H5,React Native,Flutter. 由于Flutter是跨平台的开发框架,开发一次可以同时运行在Android和iOS上面,所以我们开发时最好 ...

  5. Mac使用Xcode配置openGL

    Mac使用Xcode配置openGL 博主这学期有图形学课要用到OpenGL,于是首先就开始配置开发环境了.应该说网上Windows上配置OpenGL教程比较多,Mac版的比较少.博主特来分享配置过程 ...

  6. 【OS X系统】Xcode中搭建Python环境。

    虽然按照网上教程一步一步来,但还是遇到了几个错误点,现整理出来,主要是自己做个笔记,同时也希望能帮助到其他像我一样第一次在Xcode上搭建Python环境的人.首先感谢原作者:https://zhid ...

  7. 配置OpenCV+VS2013环境

    配置OpenCV+VS2013环境 准备工作 win7系统 下载opencv的windows编译版 安装vs2013 express 设定环境变量 按windows窗键输入path,选择第二个结果编辑 ...

  8. 在 IntelliJ IDEA 中配置 JSF 开发环境的入门详解

    JSF 作为 JavaEE 官方标准,在了解并掌握其基本开发技术后,对于功能要求较高.业务流程复杂的各种现代 Web 应用程序开发将会成为非常合适且强大的高效率开发利器.JSF 的开发环境搭建涉及到在 ...

  9. Mac上通过docker配置PHP开发环境

    这篇文章介绍的内容是关于Mac上通过docker配置PHP开发环境,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 更多PHP相关知识请关注我的专栏PHP​zhuanlan.zhihu. ...

随机推荐

  1. node不要使用最新版本,使用LTS版本

    错误现象 const { Math, Object, Reflect } = primordials; 原因 使用了最新的node版本 解决 使用稳定版本,参考官网说明,目前10.x的版本是稳定版本( ...

  2. charles Windows 安装

    本文参考:charles Windows 安装 在实际开发.测试中需要通过代理截取 app 的网络请求报文来快速定位问题.https 双向认证的 app 越来越多,fiddler在这方面并不好用.由于 ...

  3. alpine docker exec: "/bin/bash": stat /bin/bash: no such file or directory 解决方案

    sudo docker exec -it 1df4f9732e06 sh

  4. PHP去重的简单写法

    PHP去重的简单写法用array_flip实现去重效果 <pre><?php$arr =array("a"=>"a1","b& ...

  5. 使用video.js 7在html中播放rtmp视频流

    1.背景 最近要做摄像头视频的展示,不想使用硬件方的专用插件,所以计划视频推送到SRS服务器,浏览器再通过rtmp协议显示,类似于直播. 经查询,了解到可以用ckplayer(有许可条款)和video ...

  6. IDEA 的操作与使用

    idea 设置syso File –> Setting –> Editor –> Live Templates debug 调试: F7 在 Debug 模式下,进入下一步,如果当前 ...

  7. php扩展安装方式

    目录 扩展安装 php源码编译安装 PEAR.PECL phpize 源码安装 扩展安装 以php安装swoole扩展为例. php源码编译安装 下载源码包并编译安装 $ wget http://cn ...

  8. P1308(字符串类,处理字符串查找)

    题目描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给 ...

  9. 09 单例设计模式、__new__函数

    设计模式 设计模式是前任工作的总结和提炼,通常,被人们广泛流传的设计模式都是针对某一特定问题的成熟的解决方案. 使用设计模式是为了可重用代码.让代码更容易的被他人理解.保证代码的可靠性. 单例设计模式 ...

  10. javascript之typeof

    定义和用法