用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
// .
/** @file stdc++.h
* This is an implementation file for a precompiled header.
*/
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#if __cplusplus >= 201103L
#include
#include
#include
//#include
#include
#include
#include
#include
#include
#endif
// C++
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
- 保存退出即可。
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\)行和最后一段)
Kind
Xcode.Xcode3.ProjectTemplateUnitKind
Identifier
com.apple.dt.unit.commandLineTool
Ancestors
com.apple.dt.unit.base
com.apple.dt.unit.osxBase
Concrete
SortOrder
50
Description
This template creates a command-line tool.
Targets
ProductType
com.apple.product-type.tool
TargetIdentifier
com.apple.dt.commandLineToolTarget
BuildPhases
Class
Sources
Class
Frameworks
Class
CopyFiles
DstPath
/usr/share/man/man1/
DstSubfolderSpec
0
RunOnlyForDeploymentPostprocessing
YES
Options
Identifier
languageChoice
Name
Language:
Description
The primary implementation language for the command-line tool
Default
Swift
Type
popup
Values
Swift
Objective-C
C++
C
Units
C
Nodes
main.c:comments
main.c:include
main.c:main:content
Definitions
main.c:include
#include <stdio.h>
main.c:main:content
// insert code here...
printf("Hello, World!\n");
return 0;
C++
Nodes
main.cpp:include
main.cpp:main:content
Definitions
main.cpp:include
#include <bits/stdc++.h>
using namespace std;
typedef int Int;
#define int long long
#define INF 0x3f3f3f3f
#define maxn 200000
int a[maxn];
main.cpp:main:content
ios::sync_with_stdio(false);
cin.tie(0);
return 0;
Objective-C
Nodes
main.m:comments
main.m:include
main.m:main:content
Definitions
main.m:include
#import <Foundation/Foundation.h>
main.m:main:content
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
}
return 0;
Swift
Project
Configurations
Debug
SWIFT_OPTIMIZATION_LEVEL
-Onone
Release
SWIFT_COMPILATION_MODE
wholemodule
SWIFT_OPTIMIZATION_LEVEL
-O
Targets
SharedSettings
SWIFT_VERSION
5.0
Nodes
main.swift:comments
main.swift:include
main.swift:main:content
Definitions
main.swift:include
import Foundation
main.swift:main
Beginning
End
main.swift:main:content
print("Hello, World!")
Definitions
*:main
Beginning
signed main() {
End
}
Indent
1
多文件编译
- 正常创建工程即可,当需要创建第二个文件时选择\(File->New->Target\)。然后正常创建一个\(Console\)文件。编译运行的时候,在窗口左上角选择要运行的文件即可。