Using CodeLite to compile/run standalone files

General questions regarding the usage of CodeLite
roon
CodeLite Curious
Posts: 2
Joined: Sun Jan 23, 2011 9:49 am
Genuine User: Yes
IDE Question: C++
Contact:

Using CodeLite to compile/run standalone files

Post by roon »

Hi,

I am really impressed with the CL and though I have been using CodeBlocks, I wish to switch to CL. However, there is a slight problem I am facing.

In Codeblocks, you could instantly compile and run standalone c++ files (F9). There was no need to create a workspace/project for simple files. So, I have 100s of standalone C++ files that I just wish to open, edit and run. The only way I can figure out to compile and run is to create workspace -> add project (g++ executable [console]) -> edit the main file -> build & run. Clearly, this does not suit my needs since it is not possible to keep doing it with so many individual files I keep working on.

Is there a way that I can simply compile and run my c++ files without the need to go through the entire workspace/project process. All my files have separate names and running them under a project (main.cpp) is a bad idea for me.

So, basically what I want is -

1. Open any c++ file anywhere in the system
2. Do a single press compile + run (console executable)

Lots of thanks for your time,
Roon.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CodeLite to compile/run standalone files

Post by eranif »

1) You failed to mention your OS - so I will assume Windows
2) You can achieve this in codelite by defining an external tool for the task:
  • From the menu: Plugins | External Tools | Configure external tools... | New...
  • Set up a tool with the following parameters:
    Name: Build and Run Single File
    Tool path:

    Code: Select all

    cmd
    Working directory:

    Code: Select all

    $(CurrentFilePath)
    Arguments:

    Code: Select all

    /c "g++ -g "$(CurrentFileFullPath)" -o $(CurrentFileName).exe && $(CurrentFileName).exe && pause"
  • In the "General" section of the tool, check *only* the option "Save all files before executing this tool"
  • Optionally you may select a toolbar icon for this tool
  • Click OK and close that dialog, you should now have a new icon in the toolbar
  • You may define a keyboard shortcut for this new tool from "Settings | Keyboard shortcuts..." and type in the "Filter" field "external", choose your tool ID (you can obtain the tool ID from the previous dialog)
This will create new toolbar button that compiles a single file using the file's path as the working directory.
If you are using Linux, change the tool command from 'cmd' into "

Code: Select all

/bin/sh
"
and the Arguments line into:

Code: Select all

-c 'g++ -g "$(CurrentFileFullPath)" -o $(CurrentFileName) && ./$(CurrentFileName) && sleep 100'
Eran
Make sure you have read the HOW TO POST thread
roon
CodeLite Curious
Posts: 2
Joined: Sun Jan 23, 2011 9:49 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CodeLite to compile/run standalone files

Post by roon »

Hi,

Thank you for your reply. I am sorry I didn't mention the OS because I use both Linux and Windows.

However, this trick seems more of a hack than a stable feature when used. The reason I say this is because -

1. When their are compilation/build errors, there are no warnings. The console just exists without any notice. So, it doesn't seem possible to code in this mode.
2. Execution is slow as compared to the project mode.
3. No debugging feature for the program as well like the project mode.
4. The whole experience is kind of "hack"-y and less stable than the project mode.

So, overall it is not exactly usable for this purpose. It would be totally amazing if one could have the project mode features on individual standalone files as well (kind of like CB which provides full compilation error logs etc..) . Also to mention, I am unable to read from files using freopen() in either of the modes.

Just these little things prevent me from switching to CL 100%. Other than that, it is an absolute pleasure to code in Code Lite.

Also, is there a Default Code option available ? I looked around and searched but could not find any info on it.

Thank you,
roon.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Using CodeLite to compile/run standalone files

Post by eranif »

roon wrote:3. No debugging feature for the program as well like the project mode.
codelite offers an option to debug without a project: 'Debug | Quick Debug' just select the exe to debug and go
roon wrote:1. When their are compilation/build errors, there are no warnings. The console just exists without any notice. So, it doesn't seem possible to code in this mode.
Yea, I forgot to mention:
Edit the tool to allow capturing the process output (Plugins | External Tools...)

Some drawbacks:
- You wont have parsing for the output


Ofc, this can be improved by extending the 'External Tools' plugin or maybe writing a new plugin for this purpose
roon wrote:Also, is there a Default Code option available ? I looked around and searched but could not find any info on it.
I am not sure I understand what "Default Code option" available

Eran
Make sure you have read the HOW TO POST thread
Post Reply