我正在尝试在Linux / Ubuntu 14.04上运行C ++程序
我正在使用SFML库,tutorial建议在运行之前包含此行,如果SFML安装在非标准路径中(它是):
$ export LD_LIBRARY_PATH=<sfml-install-path>/lib
我可以使用以下输入从终端运行程序:
$ export LD_LIBRARY_PATH=/home/dan/SFML-2.3.1/lib && ./YorickTheSavant
但是,当尝试使用sublime-build文件在Sublime Text 2中启动程序时,我收到以下错误:
[Errno 2] No such file or directory
[cmd: [u'export', u'LD_LIBRARY_PATH=/home/dan/SFML-2.3.1/lib', u'&&', u'./YorickTheSavant']]
[dir: /home/dan/yorickthesavant]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/dan/.rvm/bin]
[Finished]
这是我的sublime-build文件供参考:
{
"cmd": ["g++", "-m32", "-c", "-std=c++11",
"src/buff.cpp",
"src/card.cpp",
"src/clickableObject.cpp",
"src/creature.cpp",
"src/dataHandler.cpp",
"src/dungeonRun.cpp",
"src/enemy.cpp",
"src/gameQueue.cpp",
"src/gameSystem.cpp",
"src/graphics.cpp",
"src/hoverText.cpp",
"src/infoText.cpp",
"src/main.cpp",
"src/player.cpp",
"src/queueBlock.cpp",
"src/queueEffect.cpp",
"src/roundedCornerRect.cpp",
"src/save.cpp",
"src/ttText.cpp",
"-I", "include"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "/home/dan/yorickthesavant/",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Link",
"cmd": ["g++", "-m32",
"buff.o",
"card.o",
"clickableObject.o",
"creature.o",
"dataHandler.o",
"dungeonRun.o",
"enemy.o",
"gameQueue.o",
"gameSystem.o",
"graphics.o",
"hoverText.o",
"infoText.o",
"main.o",
"player.o",
"queueBlock.o",
"queueEffect.o",
"roundedCornerRect.o",
"save.o",
"ttText.o",
"-o", "YorickTheSavant",
"-L", "/home/dan/SFML-2.3.1/lib",
"-lsfml-graphics",
"-lsfml-window",
"-lsfml-system"]
},
{
"name": "Run",
"cmd": ["export", "LD_LIBRARY_PATH=/home/dan/SFML-2.3.1/lib", "&&", "./YorickTheSavant"]
}
]
}
“Run”变体是我正在使用的变体。如何在游戏在终端外部和Sublime Text 2中启动时自动包含此行?
答案 0 :(得分:4)
.sublime-build文件中的cmd
键指定要运行的程序。
第一个值应该是程序,其余的是参数,
所以它找不到名为export
的程序时会失败 - 因为它是一个内置的shell。
要在shell中运行整个命令(就像手动操作一样),您可以在"shell" : true
变体中指定Run
(或使用shell_cmd
代替{{1} }}):
cmd
这应该比直接调用{
"name": "Run",
"cmd": ["export", "LD_LIBRARY_PATH=/home/dan/SFML-2.3.1/lib", "&&", "./YorickTheSavant"],
"shell" : true
}
更好,我认为你不需要将cmd数组中的条目压缩成一个字符串了。
或者,您也可以尝试使用/bin/sh -c <stuff>
键(也找到here)在运行可执行文件之前指定env
环境变量:
LD_LIBRARY_PATH