Cannot run C++ program when using sublime-build, works fine when running from terminal - c++

I'm trying to run a C++ program on Linux/Ubuntu 14.04
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):
$ 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:
[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?

The cmd key in .sublime-build files specifies the program to run.
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.
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):
{
"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.
Alternatively, you could also try using the env key (also found here) to specify the LD_LIBRARY_PATH environment variable before running your executable:
{
"name": "Run",
"cmd": ["./YorickTheSavant"],
"env" : { "LD_LIBRARY_PATH" : "/home/dan/SFML-2.3.1/lib" }
}

Related

${relativeFile} fetched by visualstudio / cmake launch json file is not including the backslash

I have configured some tasks for CMake in Visual studio. One of the commands to execute includes the ${relativeFile} and it is under subdirectory. The fetched result is not including the '/' to separate the directories.
Here is the tasks.vs.json file sample:
{
"taskName": "TestTask",
"appliesTo": "*/",
"type": "remote",
"remoteWorkingDirectory": "/home/root/",
"contextType": "custom",
"localCopyDirectory": "${workspaceRoot}\\..\\build\\${env.name}\\bin",
"remoteMachineName": "${env.TARGET_MACHINE}",
"remoteCopyMethod": "sftp",
"remoteCopyDirectory": "/tmp/",
"command": "echo changing permissions for ${relativeFile}",
"args": ""
}
Expected result: changing permissions for test\test1
Current Result: changing permissions for testtest1

Add q/kdb Build System to Sublime 3

I am using Sublime Text 3 (on Mac OS) and would like to add a q/kdb build to it so I can run the q code directly from ST. I have the below build file:
{
"cmd": ["/Users/XXX/q/m32/q", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.q"
}
When in the CL this /Users/XXX/q/m32/q file.q runs just fine, but when within ST it doesn't do anything.
Any suggestions on what I m doing wrong here?
After trial an error: all I had to do is remove the [-u] option from the command like below:
{
"cmd": ["/Users/XXX/q/m32/q", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.q"
}

Sublime Text 3 - Stop printing shell cmd, dir and path when error is raised

I would like my Sublime Text to NOT print out the following extra info everytime my code throws an error.
See below for example - I do not need to see my shell_cmd, dir, or path to be printed out, just for clarity!
I have looked for a soloution but cannot seem to find one which works.
Many Thanks for any feedback!
You can edit the python build system using PackageResourceViewer. Just open the build system in Python/Python.sublime-build and add the attribute "quiet": true,.
The resulting build system should look like:
{
"shell_cmd": "python -u \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"quiet": true,
"variants":
[
{
"name": "Syntax Check",
"shell_cmd": "python -m py_compile \"${file}\"",
}
]
}
However this will also suppress other outputs like the duration.

How can I remove the color from build output in Sublime Text 3?

I use a build system in Sublime Text 3 that outputs color by default and I would like an easy way to strip that color out of the output in the build window.
Here is my sublime-project file:
{
"folders":
[
{
"follow_symlinks": true,
"path": ".",
"folder_exclude_patterns": ["obj", "bin", "build"]
}
],
"build_systems":
[
{
"name": "boost build",
"path" : "/usr/local/bin:/usr/bin:/bin",
"cmd": ["bash", "-c", "( cd ${project_path} && exec b2 )"]
}
]
}
How can I accomplish what I'm trying to do?
I'm not sure how to do this on systems other than Mac OS X, but I found the easiest way to do what you're trying to is by piping the output through sed to strip out the escape sequences.
Here is your build command modified accordingly:
"cmd": ["bash", "-c", "( cd ${project_path} && exec b2 | sed 's/\\ESC\\\\[[0-9;]*m//g' )"]
Now, unfortunately, I have no idea how to copy and paste the ESC character that Sublime Text uses to display an escape character, but I basically just copied that from the console window and placed it where ESC is written above. I couldn't figure out any other method of providing the escape character and I tried almost every combination of \033 and \x1B I could think of.
I didn't want to have to include a screenshot, but I'll provide one for the sake of clarity regardless:

running Sublime Text build with latex instead of pdflatex from LaTeXTools plugin

In the build file supplied with the LatexTools plugin for Sublime Text, I modified the statement
"cmd": ["latexmk", "-e", "\\$pdflatex = 'pdflatex %O -interaction=nonstopmode -synctex=1 %S'", "-f", "-pdf"]
by replacing the second instance of pdflatex with latex.
My question is, how do I specify whether I want to use "dvipdfm" or "dvi2ps + ps2pdf".
If someone could provide a sample build file for this purpose, that would be most helpful.
After a bit of trial and error, I finally have the following build file working correctly. This allows me to choose between pdflatex and latex, and also choose between dvipdfm and the alternative of "dvi2ps + ps2pdf"
// Compilation settings
// ====================
//
// The actual magic happens in the make_pdf command
// I stick to the format of standard ST2 sublime-build files
// with minor variations.
// NOTE: the viewer is NOT configured from here!
// As of 5/24/11, it cannot be changed, but I will introduce a setting later
{
// General settings; DO NOT MODIFY!!!
"target": "make_pdf",
"selector": "text.tex.latex",
//-----------------------
// Linux-specific settings
// ----------------------
// If linux/os variable is used, then command palette does not show variant names
// Linux texification settings
// -------------------------
// Personalize this, IF you know what you are doing!
// e.g. change 'pdflatex...' to 'xelatex...'
// Refer to the documentation for latexmk
//
// Note: do NOT include $file or similar!!!
// Only configure the compilation parameters you need, MINUS the
// actual file to be compiled
//
// By default, latexmk is told to use pdflatex, with synctex on for
// backward/forward search, forcing compilation (e.g. even if no bib file is found)
// and producing pdf rather than dvi output
"cmd": ["latexmk",
"-e","\\$dvipdf = 'dvipdfmx %O -o %D %S'", "-e", "\\$latex = 'latex %O -interaction=nonstopmode -synctex=1 %S'",
"-f", "-pdfdvi"],
"variants":
[
{ "cmd": ["latexmk",
"-e", "\\$pdflatex = 'pdflatex %O -interaction=nonstopmode -synctex=1 %S'",
"-f", "-pdf"],
"name": "Run"
},
{ "cmd": ["latexmk",
"-e", "\\$latex = 'latex %O -interaction=nonstopmode -synctex=1 %S'",
"-f", "-pdfps"],
"name": "LaTeX_PS_PDF"
},
{"cmd": ["latexmk", "-e", "\\$clean_ext = 'aux fls fdb_latexmk dvi ps synctex.gz'", "-c"],
"name" : "Clean "
}
]
}