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]
How to compile/run MS Visual C++ 2008 Exp. Ed. in Textpad?
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 1
- Joined: Tue Feb 24, 2009 4:53 pm
- Location: Nashville
-
- Posts: 18
- Joined: Sun Feb 15, 2009 12:50 pm
Re: How to compile/run MS Visual C++ 2008 Exp. Ed. in Textpa
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 ...
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:
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:
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
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"
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
Code: Select all
C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe
In the meanwhile, happy coding. C++ is a fine language. Enjoy!
S
Re: How to compile/run MS Visual C++ 2008 Exp. Ed. in Textpa
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.
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.
-
- Posts: 18
- Joined: Sun Feb 15, 2009 12:50 pm
Re: How to compile/run MS Visual C++ 2008 in Textpad
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.)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.
- 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: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.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"
(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.) - 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)
- 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; }
- 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:which you can save as vc_hello.mak and send to the tool set up in 2. to start the build.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
Hope this is useful.
Last edited by shaqmeister on Sun Mar 29, 2009 1:09 am, edited 4 times in total.
Re: How to compile/run MS Visual C++ 2008 in Textpad
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.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.)
Anyway you answered the original question so i'm sure that's helpful for those that prefer to use textpad for this purpose.