我已经尝试使用 SublimeText2 一段时间了。虽然几乎开箱即用地使用 Python 非常容易,但使用 C++ 则有点棘手。我可以通过复制和修改现有的 Makefile 脚本来设法设置 CMake 构建脚本,但是有很多东西不能像在 CMake 支持的 IDE 中那样工作,比如 Eclipse CDT。 SublimeText 2 似乎不理解单独构建目录的概念,它也无法让我通过 SublimeClang 自动完成,如果我包含引用 CMake 中添加的目录的库。 SublimeClang 一直提示它找不到库,当我尝试 #include
时,它甚至不能为我提供标准 STL 头文件名的自动完成功能,例如 algorithm.h 。如果有人想出了一个管道,我将不得不听听它。
我之前在更通用的使用相关论坛上问过这个问题,但没有得到任何回复,这就是为什么我想在这里发布它。
最佳答案
我将 Sublime Text 2 与 CMake 和 SublimeClang 结合使用。我也使用 SublimeGDB。我的构建目录在 [project root]/build
下。看看我的项目文件,看看它是否对你有帮助:
{
"folders":
[
{
"path": "."
}
],
"build_systems":
[
{
"name": "Build",
"cmd": [ "make", "-C", "build" ],
"file_regex": "/([^/:]+):(\\d+):(\\d+): "
}
],
"settings":
{
"sublimegdb_commandline": "gdb --interpreter=mi myapp",
"sublimegdb_workingdir": "build",
"sublimeclang_options" :
[
"-Wno-reorder"
],
"sublimeclang_options_script": "${project_path:scripts/compileflags.rb} ${project_path:build}"
}
}
compileflags.rb
脚本用于在 CMake 构建树中搜索 flags.make
文件,这是 CMake 保存其编译标志的地方。需要这些标志,以便 SublimeClang 知道在哪里可以找到您的包含。
这是位于 scripts/
下的脚本:
#!/usr/bin/env ruby
# Searches for a flags.make in a CMake build tree and prints the compile flags.
def search_dir(dir, &block)
Dir.foreach(dir) do |filename|
next if (filename == ".") || (filename == "..")
path ="#{dir}/#{filename}"
if File.directory?(path)
search_dir(path, &block)
else
search_file(path, &block)
end
end
end
def search_file(filename)
return if File.basename(filename) != "flags.make"
File.open(filename) do |io|
io.read.scan(/[a-zA-Z]+_(?:FLAGS|DEFINES)\s*=\s*(.*)$/) do |match|
yield(match.first.split(/\s+/))
end
end
end
root = ARGV.empty? ? Dir.pwd : ARGV[0]
params = to_enum(:search_dir, root).reduce { |a, b| a | b }
puts params
关于c++ - 在 CMake/C++ 项目中高效地使用 SublimeText 和 SublimeClang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12290456/