用Xcode配置完美ACMer環境 前言 作為$ACMer$,需求大致為強大的文本編輯功能$(VIM)$,便捷的文件模版功能以及多文件編譯功能。$vscode$雖然強大,但是與集成$IDE$相比其缺點也很明顯,就是沒有完美的$Debug$功能。而$Xcode$剛好有此功能,但是在其他方面卻顯得有 ...
用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\)文件。編譯運行的時候,在視窗左上角選擇要運行的文件即可。