How to compile/run MS Visual C++ 2008 Exp. Ed. in Textpad?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
shamindra74
Posts: 1
Joined: Tue Feb 24, 2009 4:53 pm
Location: Nashville

How to compile/run MS Visual C++ 2008 Exp. Ed. in Textpad?

Post by shamindra74 »

Hello everyone!

I have used Textpad mainly for latex and fell in love with it. Few days backs, I started learning C++ and I downloaded MS Visual C++ 2008 Express Edition. However,

(i) for writing programs, I would prefer my simple Textpad rather than the fancy MS stuff

(ii) but use MS Visual as a compiler.

I was looking for instructions for compiling and running C++ programs in Textpad. I did search the forum; the only lead which I got is:

http://forums.textpad.com/viewtopic.php ... ght=visual

which hardly gives any step-by-step instruction. It would be great, if anyone could provide some information about this.[/url]
shaqmeister
Posts: 18
Joined: Sun Feb 15, 2009 12:50 pm

Re: How to compile/run MS Visual C++ 2008 Exp. Ed. in Textpa

Post by shaqmeister »

Hello Shamindra

I can understand your wanting to steer away from the heavyweight tools like Visual C++ Express. I too am currently building C# .NET programs using TextPad and hooking into the environment behind Visual C# Express. However, owing to the different nature of the language and the set-up, I think this is going to be harder to do with Visual C++.

The first thing to think about is how you would set all the environment variables that would need to be set, even before you call the compiler on your code. It's not enough, I'm afraid, just to set up a tool to call cl.exe.

Still, there is a simple trick to at least get this far.

If you've installed Visual C++ Express 2008 then you should have in the start menu under 'Microsoft Visual C++ 2008 Express Edition | Visual Studio Tools' a shortcut for the 'Visual Studio 2008 Command Prompt'. This will open up a command window having first set all the necessary variables. Then, if you type at the prompt the fully-qualified path to the TextPad executable ...

Code: Select all

"D:\Program Files\TextPad 5\TextPad.exe"
on my machine (remembering to use quotes if there are any spaces in the path names) then TextPad will launch and the proper environment variables will be set and you at least have something to work with.

Then, for starters, you should be able to compile a single code file with the following "Run..." command:

Code: Select all

Command: cl
Parameters: /EHsc $FileName
Initial Folder: $FileDir
just to try it out, and capture the output. If you set it up as a tool you'll need the full path to cl.exe, which in a standard installation should be:

Code: Select all

C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe
Further down the line (if you haven't got there already) there'll be further things to think about if you want to build more than one code file into a program. Then you'll have to be looking at things like 'makefiles' and then you may start to miss VS Express where all that is done for you. :)

In the meanwhile, happy coding. C++ is a fine language. Enjoy!

S
gan

Re: How to compile/run MS Visual C++ 2008 Exp. Ed. in Textpa

Post by gan »

If you are going to learn C++ i would strongly suggest that you learn the VS IDE as well. Unless you are only going to create simple "hello world" applications you are going to need something more then textpad for that purpose. Even if it might look a bit complicated you will find it easier when you start to learn and understand how it works and then i'm pretty sure you will not consider to use textpad again. Textpad is a nice text editor, but not any good to work with C++ code.
As already said you have to setup the environment variables and then you can see from within VS how the command line should be, but it's not like the parameters should be the same in all scenario's.
To start learning C++ and choose to use Textpad to write the code and compile without the knowledge how it's even working sounds very wrong to me. I would suggest to learn some C++ first and how the GUI works and how to use it, then learn how to compile from command line before you start using a text editor for this purpose.
shaqmeister
Posts: 18
Joined: Sun Feb 15, 2009 12:50 pm

Re: How to compile/run MS Visual C++ 2008 in Textpad

Post by shaqmeister »

gan wrote:If you are going to learn C++ i would strongly suggest that you learn the VS IDE as well. ... Textpad is a nice text editor, but not any good to work with C++ code.
As already said you have to setup the environment variables and then you can see from within VS how the command line should be, but it's not like the parameters should be the same in all scenario's.
To start learning C++ and choose to use Textpad to write the code and compile without the knowledge how it's even working sounds very wrong to me. I would suggest to learn some C++ first and how the GUI works and how to use it, then learn how to compile from command line before you start using a text editor for this purpose.
To play devil's advocate, I think I would want to offer an alternative viewpoint to the one you suggest based on the fact that the OP had specified that they had "started learning c++," recognizing at the outset that "c++" and "Microsoft Visual C++" are not at all the same thing. The first is a language and the second is a development environment, and there is much merit in wanting to learn the fundamentals of the language independently of any extended application. Then, for this purpose, TextPad is as good a choice of editor as any, and better than a lot. And in truth, it's not that difficult either to set it up to use the VC++ compiler. As an example, the following builds a couple of .cpp code files into an executable by sending a makefile to NMake (which will be available having installed, as the OP has, the Visual C++ Express Edition.)
  1. Setting up the environment variables
    You will first of all need to set up the environment variables in TextPad (requires TextPad 5.*?). This is done by adding them via Configure | Preferences... | Environment variables. For a standard installation of Microsoft Visual C++ 2008 Express Edition and the .NET Framework v3.5, these should be:

    Code: Select all

    "DevEnvDir"="C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE"
    "Framework35Version"="v3.5"
    "FrameworkDir"="C:\Windows\Microsoft.NET\Framework"
    "FrameworkVersion"="v2.0.50727"
    "INCLUDE"="C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v6.0A\include;"
    "LIB"="C:\Program Files\Microsoft Visual Studio 9.0\VC\LIB;C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib;"
    "LIBPATH"="C:\Windows\Microsoft.NET\Framework\v3.5;C:\Windows\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 9.0\VC\LIB;"
    "Path"="C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN;C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools;C:\Windows\Microsoft.NET\Framework\v3.5;C:\Windows\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 9.0\VC\VCPackages;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin;%PATH%"
    "SESSIONNAME"="TextPad"
    "VCINSTALLDIR"="C:\Program Files\Microsoft Visual Studio 9.0\VC"
    "VS90COMNTOOLS"="C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools"
    "VSINSTALLDIR"="C:\Program Files\Microsoft Visual Studio 9.0"
    "WindowsSdkDir"="C:\Program Files\Microsoft SDKs\Windows\v6.0A"
    
    but you can find the exact variables for your system by running the Visual Studio Command Line (which should be available from the start menu) and typing "SET" (without the quotes) at the prompt.
    (To be honest, you could probably get away with a very minimal subset of these if you are only wanting to experiment with the base c++ programming language. Very probably only INCLUDE, LIB and LIBPATH are necessary for this, but I haven't tried this so I have presented the full set here.)
  2. Adding a tool to TextPad
    For this, you could use the following settings (adjusting the path to NMake on your machine, if necessary):

    Code: Select all

    Command: C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\nmake.exe
    Parameters: /F $FileName
    Initial Folder: $FileDir
    Capture Output: Checked
    Regex: ^\([^(]+\)(\([0-9]+\)): (the default works fine)
    
  3. Write some code
    As an example, the following overcomplicates the canonical "Hello world," but only to illustrate how to build an executable from multiple code files. So, create and save the following files:

    Code: Select all

    // message.hpp
    
    #ifndef MESSAGE_HPP
    #define MESSAGE_HPP
    
    #include <string>
    
    class Messenger
    {
    public:
       static std::string GetMessage();
    };
    
    #endif
    

    Code: Select all

    // message.cpp
    
    #include "message.hpp"
    
    std::string Messenger::GetMessage()
    {
       return "Hello, World!";
    }
    

    Code: Select all

    // main.cpp
    
    #include "message.hpp"
    
    #include <iostream>
    #include <cstdlib>
    
    int main() {
    
       std::cout << Messenger::GetMessage() << std::endl;
    
       return EXIT_SUCCESS;
    }
    
  4. Finally, create a 'makefile' to send to NMake:
    Now, the syntax for makefiles can be very sophisticated, reflecting the fact that make utilities are very powerful tools. However, the following should be sufficient as a template for building applications suitable for learning the c++ language:

    Code: Select all

    # NMake makefile
    
    ### edit this section #####################
    
    PROG	 = vc_hello    # builds vc_hello.exe
    SRC 	 = \
            main.cpp \
            message.cpp
    
    ### leave rest as is  #####################
    
    all : $(PROG)
    
    OBJS 	= $(SRC:.cpp=.obj)
    FLAGS	= /EHsc /c
    
    $(PROG) : $(OBJS)
    	cl /Fe$(PROG) $(OBJS)
    
    .cpp.obj:
    	cl $(FLAGS) $(SRC)
    
    clean:
    	del $(PROG).exe $(OBJS) tp*.bat
    
    which you can save as vc_hello.mak and send to the tool set up in 2. to start the build.
Put all together, the above builds an executable called vc_hello.exe in the same directory as the code files, which can then be easily run from a TextPad tool setup to use $BaseName from the project makefile.

Hope this is useful.
Last edited by shaqmeister on Sun Mar 29, 2009 1:09 am, edited 4 times in total.
gan

Re: How to compile/run MS Visual C++ 2008 in Textpad

Post by gan »

shaqmeister wrote:To play devil's advocate, I think I would want to offer an alternative viewpoint to the one you suggest based on the fact that the OP had specified that they had "started learning c++," recognizing at the outset that "c++" and "Microsoft Visual C++" are not at all the same thing. The first is a language and the second is a development environment, and there is much merit in wanting to learn the fundamentals of the language independently of any extended application. Then, for this purpose, TextPad is as good a choice of editor as any, and better than a lot. And in truth, it's not that difficult either to set it up to use the VC++ compiler. As an example, the following builds a couple of .cpp code files into an executable by sending a makefile to NMake (which will be available having installed, as the OP has, the Visual C++ Express Edition.)
I know the language and the ide are two different things, but i still think it's better to start with vs 2008 enviroment for several reasons. It's not hard to setup and use Textpad, but that was never my point either.
Anyway you answered the original question so i'm sure that's helpful for those that prefer to use textpad for this purpose.
Post Reply