用Xcode配置完美ACMer环境 前言 ? 作为 \(ACMer\) ,需求大致为强大的文本编辑功能 \((VIM)\) ,便捷的文件模版功能以及多文件编译功能。 \(vscode\) 虽然强大,但是与集成 \(IDE\) 相比其缺点也
用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 <stdio.h> </string> <key>main.c:main:content</key> <string>// insert code here... printf("Hello, World!\n"); 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 <bits/stdc++.h> 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 <Foundation/Foundation.h> </string> <key>main.m:main:content</key> <string>@autoreleasepool { // insert code here... NSLog(@"Hello, World!"); } 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("Hello, World!") </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\)文件。编译运行的时候,在窗口左上角选择要运行的文件即可。