1
votes

I wanted to build and run Pascal in Sublime Text 2 (or 3). I've searched as much as I could and although I could get sublime to BUILD my dpr or pas files in ST3, I struggle with getting them to run as an exe in command prompt. Therefore, I tried using this, as someone suggested (Qwerty answered this question on someone else's post):

{

"cmd": ["fpc", "${file_path}/${file_base_name}"],
"selector": "source.pascal",
"variants": [
    {
        "cmd": ["start", "cmd", "/c", "$file_base_name.exe & pause"],
        "name": "Run",
        "shell": true
    }
]

}

It works perfectly fine when compiling and running hello world, but gives me errors with everything else:

Free Pascal Compiler version 2.6.4 [2014/03/06] for i386

Copyright (c) 1993-2014 by Florian Klaempfl and others

Target OS: Win32 for i386

Compiling F:\Ali\Pascal\Projects\adult.pas

Linking F:\Ali\Pascal\Projects\adult.exe

adult.pas(32,1) Error: Can't create object file: F:\Ali\Pascal\Projects\adult.exe

adult.pas(32,1) Fatal: Can't create executable F:\Ali\Pascal\Projects\adult.exe

Fatal: Compilation aborted

Error: C:\FPC\2.6.4\bin\i386-Win32\ppc386.exe returned an error exitcode (normal if you did not specify a source file to be compiled)

[Finished in 0.4s with exit code 1]

Whereas if it's Hello World:

Copyright (c) 1993-2014 by Florian Klaempfl and others Target OS: Win32 for i386 Compiling F:\Ali\Pascal\Projects\hello.pas Linking F:\Ali\Pascal\Projects\hello.exe 4 lines compiled, 0.3 sec , 25936 bytes code, 1644 bytes data [Finished in 0.5s]

2

2 Answers

1
votes

This build system compiles your program AND runs it automagically. Although if you just want to compile or you only want to run the program you can do it by pressing Ctrl-Shift-B.

{
        "shell": true,
        "cmd": ["fpc", "${file_path}/${file_base_name}", "&&", "start", "cmd", "/c", "$file_base_name.exe", "&", "pause"],
        "selector": "source.pascal",
        "variants": [
            {
                "cmd": ["start", "cmd", "/c", "$file_base_name.exe & pause"],
                "name": "Run",
                "shell": true
            },
            {
                "cmd": ["fpc", "${file_path}/${file_base_name}"],
                "name": "Compile",
                "shell": true
            }
        ]
    }
0
votes

Check your processes. The exe that was built before is still running and locked by OS so that the fpc can't overwrite it. Hello was probably not running, so it was ok.

Everything else worked here.

My variant:

{  
 "cmd": ["C:\\lazarus\\fpc\\2.6.4\\bin\\i386-win32\\fpc.exe", "$file"],
  "selector": "source.pascal",
  "variants": [{
       "cmd": ["start", "cmd", "/c", "$file_base_name.exe & pause"],
       "name": "Run",
       "shell": true
   }]
}

PS! I didn't know you could do that. I like Sublime now even more ! Thanks.