Sublime Forum

No output other than build time (Sublime Text 3, C++)

#1

When I compile/run my .cpp script, I am not seeing any output in Sublime Text 3. I am trying to use Sublime Text 3 as my main code editor for C++ scripts. I’ve edited my .sublime-build to include the folders needed, and defined the library folders as well. My .sublime-build file is as follows:

{
    "cmd": ["g++", "-Wall", "-Wextra", "-std=c99", "${file}", "-o", "${file_path}/${file_base_name}", "-I", "C:/Program Files/ArrayFire/v3/include", "-I", "C:/Program Files/ArrayFire/v3/include/af"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",

    "variants":
    [
      {
         "name": "Run",
         "shell_cmd": "g++ \"-Wall\" \"${file}\" -o \"${file_path}/${file_base_name}\" -I \"C:/Program Files/ArrayFire/v3/include\" -I \"C:/Program Files/ArrayFire/v3/include/af\" -I \"C:/package/armadillo74002/include\" -L \"C:/Program Files/ArrayFire/v3/lib\""
      }
    ]
}

However, when I run my script, I only get the following output: [Finished in 1.3s]. My code is simple, and is shown below:

#include <iostream>
#include "arrayfire.h"

using namespace std;

int main(){
    cout << "Check" << endl;
    return 0;
}

Additionally, when I run the .exe file, it closes immediately. Both of these suggest to me that something isn’t correct, but I cannot seem to find my error.

0 Likes

#2

After reading through some StackOverflow posts, it seems that my script was running correctly after all. Making the end of my main() function to be:

cin.clear();
cin.get();
return 0;

the .exe output stays open and does not close immediately, allowing me to see the printed script. I’d still love to know how I can display this in Sublime Text 3 output, instead of running the .exe every time.

0 Likes

#3

g++ doesn’t send any output to the console when compiling unless it needs to tell you any warnings or errors, so assuming your code compiles cleanly, I would expect the build to tell you nothing except how long it took to run. Try introducing a syntax error and see if that starts generating output for you.

If you’re running your executable by double clicking it in a file explorer, this is expected behaviour; console applications only display their window while they’re running. You would need to put something in to wait for a key press at the end of your application or run it from a command prompt.

1 Like

#4

Your run variant in the build system needs to actually run the executable. The way you’ve outlined it above, trying to run it just compiles it again. Swap the shell_cmd from what you have above to the name of the executable that’s being created and sublime will run it instead of the compiler, which is probably what you intended.

[edit]
Actually, you should compare yours to the C++ Single File.sublime-build run variant; that one includes an additional command after compilation that runs the result, which you omitted above. Setting it to just run the executable won’t build it for you, which is probably not what you want (here I have keys set up to run different make commands to build or run separately).
[/edit]

0 Likes

#5

i too faced the exact same problem today and Luckily found how to get this rectified. Just press (shift + ctrl + b) and select (your_sublime_build_file)-run and there you go :slight_smile:.

P.S. couldn’t upload screenshot because window disappears if switched to other apps.

2 Likes

#6

Hello Everyone,

I recently installed sublimtext editor in windows 10 , I have done config setup,however After running the c++/c I don’t find any output no error also.

Please help someone.

.cpp
#include
#include

using namespace std;

int main()
{
string s;
cout << “Please enter your first name followed by a newline\n”;
system(“pause”); // <----------------------------------
return 0; // This return statement isn’t necessary
}
.c
#include<stdio.h>
int main()
{
printf(“Test 1”);
}
C++_Runbuild
{
“shell_cmd”: “g++ “${file}” -o “${file_path}/${file_base_name}””,
“file_regex”: “^(…[^:]):([0-9]+):?([0-9]+)?:? (.)$”,
“working_dir”: “${file_path}”,
“selector”: “source.c, source.c++”,

“variants”:
[
{
“name”: “Run”,
“shell_cmd”: “g++ “${file}” -o “${file_path}/${file_base_name}” && “${file_path}/${file_base_name}””
}
]
}
C build

See http://www.sublimetext.com/docs/build for details

build make
lineNumberRegex ^(…?):([0-9]):?([0-9]*)
showWhenFinished true
workingDir $ProjectDir
{
“shell_cmd” : “gcc $file_name -o ${file_base_name}”,
“working_dir” : “$file_path”,

“variants”:
[
{
“name”: “Run”,
“shell_cmd”: “gcc $file_name -o ${file_base_name} && ${file_path}/${file_base_name}”
}
]
}

0 Likes

#7

I am having same problem .It is saying process finished but does not show any output.plz help me.I have included two files with main file i.e input text, output.txt

0 Likes