[英]Cannot run C++ program when using sublime-build, works fine when running from terminal
I'm trying to run a C++ program on Linux/Ubuntu 14.04 我正在尝试在Linux / Ubuntu 14.04上运行C ++程序
I'm using the SFML library, the tutorial suggests to include this line before running if SFML was installed in a non-standard path (which it was): 我正在使用SFML库,如果SFML安装在非标准路径中(本来是),则该教程建议在运行之前包括以下行:
$ export LD_LIBRARY_PATH=<sfml-install-path>/lib
I can run the program from the terminal using the following input: 我可以使用以下输入从终端运行程序:
$ export LD_LIBRARY_PATH=/home/dan/SFML-2.3.1/lib && ./YorickTheSavant
However, when attempting to launch the program in Sublime Text 2 with a sublime-build file, I get the following error: 但是,当尝试使用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]
Here is my sublime-build file for reference: 这是我的崇高构建文件供参考:
{
"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"]
}
]
}
The "Run" variant is the one I'm using. 我正在使用“运行”变体。 How would I make it so that this line is automatically included when the game is launched outside of the terminal and in Sublime Text 2? 我如何做到这一点,以便在终端之外启动游戏并在Sublime Text 2中自动添加该行?
The cmd
key in .sublime-build files specifies the program to run. .sublime-build文件中的cmd
密钥指定要运行的程序。 The first value is expected to be the program and the rest are the arguments, so it fails when it cannot find a program called export
- because it is a shell built-in. 第一个值应该是程序,其余的是参数,因此当它找不到名为export
的程序时会失败-因为它是内置的shell。
To run the entire command in a shell (like you would when doing it manually), you can specify "shell" : true
in your Run
variant (or use shell_cmd
instead of cmd
): 要在shell中运行整个命令(就像手动执行操作一样),可以在Run
变体中指定"shell" : true
(或使用shell_cmd
代替cmd
):
{
"name": "Run",
"cmd": ["export", "LD_LIBRARY_PATH=/home/dan/SFML-2.3.1/lib", "&&", "./YorickTheSavant"],
"shell" : true
}
This should work better than invoking /bin/sh -c <stuff>
directly, and I don't think you'll need to condense the entries in the cmd array into a single string anymore. 这应该比直接调用/bin/sh -c <stuff>
更好,并且我认为您不再需要将cmd数组中的条目压缩为单个字符串。
Alternatively, you could also try using the env
key (also found here ) to specify the LD_LIBRARY_PATH
environment variable before running your executable: 或者,您也可以尝试在运行可执行文件之前使用env
键(也在此处找到)指定LD_LIBRARY_PATH
环境变量:
{
"name": "Run",
"cmd": ["./YorickTheSavant"],
"env" : { "LD_LIBRARY_PATH" : "/home/dan/SFML-2.3.1/lib" }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.