1

I think many of you are using or used to use Sublime Text 2 editor, on windows 8. I have strange error: C++ programs can't be built. My goal is to use Sublime Text 2 to build and run simple programs, so that it can show me the output in the window below, Xcode or Codeblocks style.

My C++.sublime-build (which are the default settings):

{
    "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",
            "cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
        }
    ]
}

When i compile a simple hello world program, it compiles and runs fine, and the output is shown on the lower panel of sublime text, exactly like I want it.

But If I run a more complex program such as below:

//  main.cpp
//  LongestIncreasingSubsequence
#include <iostream>
#include <vector>
#include <limits>
using namespace std;

int main(int argc, const char * argv[])
{


    int n;

    cin >> n;
    vector<int> nums(n);
    vector<int> lis_so_far(n);
    int final_longest = 1;

    for (int i=0; i<n; i++) {
        cin >> nums[i];
        lis_so_far[i] = 1;
    }
    int so_far;
    for (int j=n-1; j>=0; j--) {

        so_far = 0;

        for (int i=j+1; i<n; i++) {
         //   cout << "hi" <<endl;
            if (nums[i] > nums[j]) {
              //  cout << "hello" <<endl;

                if (lis_so_far[i] > so_far ) {
                    so_far = lis_so_far[i];
                    //cout << so_far << endl;
                }

            }
        }
        if (j<n-1) {
            lis_so_far[j] += so_far;
            if (lis_so_far[j] > final_longest) {
                final_longest = lis_so_far[j];
            }
        }
    }

    for (int i=0; i<n; i++) {
        cout << lis_so_far[i] << endl;
    }
    cout << final_longest << endl;


    return 0;
}

, it gives me a missing limits.h error, even though I have cygwin installed. Isn't ST2 supposed to know where the c++ libraries are?:

C:\Users\Leonardo\Desktop\main5.cpp:11: limits: No such file or directory
[Finished in 6.5s with exit code 1]

If I comment the #include limits line, it builds, but when i run it, it gives me a permission denied error, even though there isn't a command prompt running:

/cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/bin/ld: cannot open output file C:\Users\Leonardo\Desktop/main5.exe: Permission denied
collect2: ld returned 1 exit status

Any ideas? I just want ST2 to function as Xcode or Codeblocks would.

4

1 回答 1

0

这是一个崇高的控制台“错误”。这是因为您永远不会终止最后一次编译。例如。

#include <iostream>
int main(){
cout << "it's a program" << endl;
cin.get() // system pause
}

当你第一次运行时,你编译成功,但是,当你调用cin.get()暂停时,程序永远不会终止,并保持打开状态。

然后,如果你再次尝试编译,你会看到权限错误,因为程序仍在运行。删除 pause 命令,您就不会出错了。

于 2017-05-17T19:03:34.747 回答