Setting up the command gdb on windows - windows

Well I am relatively new in computer's world, and I learned programming on a virtual machine using linux S.O. I am using minGW32 command prompt, and I can compile and run my c codes as needed, however I recently installed gdb debugger (for debugging my programms), and it is bit uncomfortable to write:
"c:\mingw\bin\gdb.exe" exe_name
in order to debug my programs. Is there a way for having something like:
gdb exe_name
like in linux?
Thanks in advance.
extra question: And the same for valgrind?
best regards

You should add the path "c:\mingw\bin" in your environment variable. This way whenever you type gdb on command prompt, it would search from the above path.
And the same for valgrind?
Till date Valgrind does not run on Windows platform.

Related

Executing fortran script with single line from Windows cmd

I need to run a fortran (77) script from the Windows 10 command window, but it should be a one-liner. The reason is that the fortran scipt - a file called external_command.f - is actually part of a Matlab script, where I can run external code through the operating system's command window (by using the ! "bang" symbol or system()-command. I quickly want to point that out without focusing too much on Matlab). But I'm having trouble doing that in Windows.
So far I tried:
using a fortran compiler for Windows, like Msys2 (which has the functions of gfortran, as far as I understand). However, it looks like I have to start Msys2 first, which then opens a separate window, which Matlab doesn't seem to be able to use because it's not Windows cmd anymore
installing gfortran in Ubuntu using Windows 10's WSL (Windows Subsystem for Linux). Same problem here: the cmd window changes to a Ubuntu terminal before I can use any fortran scripts. Furthermore, I can't easily change files located in Windows with commands from within a virtual machine
If it's not possible to run fortran scripts in Windows 10 in a one cmd line, I'd appreciate some guidance on how to change my approach.
EDIT: after Ronald kindly explained in a comment how fortran works I think this whole (rather complicated) question is just based on my own misunderstanding of fortran. I'm pretty sure I can now solve the issue after compiling my fortran code and using the resulting exe file in my cmd-window.

what command on cmd works just the same as the "makefiles" command on Linux?

I'm new on C programming and I had been wondering what command on cmd works just the same as makefiles on Linux. You see, the OS of the computers we use in school is Linux and Mac and my laptop is Windows 8 and so the text editor I use is only Notepad++. I started coding just a few weeks from now and I'm going crazy since I got something to hand in and I cannot figure out what command to use. Plus, I do not have Visual Studio or whatsoever installed on my computer. It might just be a simple problem for you guys so someone help me?
So the basic HelloWorld.c:
#include <stdio.h>
int main ()
{
printf("HelloWorld\n");
return 0;
}
to compile: gcc HelloWorld.c -o HelloWorld -Wall
to run: HelloWorld
#Beta That's how I do it on Windows
Sounds like you need some tools to get your code done.
Option 1:
You said you don't have visual studio, did that mean you wanted it?
Microsoft offers Visual Studio Express for free, I have a 2010 version that I use when I need to reproduce something on there, but there's a 2012 version listed as well.
Option 2:
You said you have Windows but they use Linux at your school? Well have you ever heard of Oracle's VirtualBox? It's a very simple application that lets you run a Linux box inside your windows machine, and it's free! Go to Oracle's site and download VirtualBox then go to the site of your favorite Linux distro and download a .iso image of it (for example if you were feeling Minty you could go get a iso here)
Then you can follow the instructions to set up and "install" the iso in the virtual machine and voila! You have Linux at home. Gcc/Make and everything you're used to.
Option 3:
If you just want Make GCC and such tools you can get them from the MinGW site. You can set things in your windows environment variables such that you can call gcc and make right from the command prompt wherever it is.
So far, so good. Now try make -v, to determine whether you have Make installed, and if so which version.
EDIT:
All right, let's try a very simple makefile:
all:
#echo hello
This is just a text file called makefile. The whitespace at the beginning of the second line is a TAB, not spaces. (I'll explain the '#' later.) Once you have written this file, try make. It should say hello.

How to develop in Linux-Like Shell (bash) on Windows?

I'm Windows user. But according to my project requirements, I need to write Linux Shell Script(Bash shell). How to develop Linux Shell on Windows?
Is there any IDE for writing Linux Shell Scripting? Please share me some ideas and resource links.
You have quite a number of options:
cygwin
Install cygwin. It will give you a bash.
mingw
The minimal GNU for windows. Comes with set of commands, compilers. This came with my Git on Windows and now the default shell for small scripts
VM, such as VirtualBox
There are tons on VMs, VirtualBox being easy to use(it powers the Boot2Docker). You can do development and test on real Linux distros.
Ubuntu on Windows 10
There is new kid on the block. This allows you to run User Space Ubuntu using Windows Subsystem for Linux (WSL). see more on it at Microsoft blog
Other notes/IDE support
Shell scripts should be small, requires less IDE etc. I use VIM with syntax highligthing. But it seems ShellED may be useful in your case. I got the link from answer for this question - Bash script plugin for Eclipse?
IntelliJ has couple of plugins too for Bash..
I prefer Gow (Gnu on Windows) over Cygwin. Both will give you bash on Windows, but Cygwin has unnatural conventions for filesystem access (/cygdive/c/some/path instead of c:\some\path).
The native windows command terminal is pretty lame, take a look at Conemu.
I'm not aware of any bash IDE, but there are a plethora of windows text editors with decent syntax highlight for bash scripts. I like Notepad++ and Sublime text (the multiple cursor feature from Sublime rocks!). I don't recommend bash for anything with more than 30 lines, if you ever feel the need for an IDE, perhaps the task is more suited for Python, Ruby or Perl (IMHO Python is more maintainable).
The Bash shell is coming to Windows 10 in the upcoming Anniversary Update (Redstone).
The Bash shell is coming to Windows. Yes, the real Bash is coming to Windows, said Microsoft's Kevin Gallo at Build 2016 keynote. This is not a VM [Virtual Machine]. This is not cross-compiled tools. This is native."
Here's the steps to run Bash on Windows 10 OS:
Open the Windows Start menu
Type "bash" [hit enter]
Which opens a console running Ubuntu's /bin/bash with full access to all of Ubuntu user space
Yes, you are right, that means apt, set, ssh, rsync, find, ls, grep, awk, sed, sort, xargs, md5sum, gpg, curl, wget, apache, mysql, python, perl, ruby, ruby gem, php, gcc, tar, vim, emacs, diff, patch, nano...and most of the tens of thousands binary packages available in the Ubuntu archives!
Reference
Step-vise Guide to Enable Windows 10’s Ubuntu Bash Shell (Windows Subsystem for Linux)
The Bash shell is coming to Windows 10 in the upcoming Anniversary Update (Redstone).
Run native Bash on Ubuntu on Windows
Since you need to write linux shell scripts, you are learning Linux. So you should install Linux on your machine (preferably on its own partition and boot from it, otherwise in a VM).
Using cygwin or whatever imitation of Linux shell is not using Linux. You'll learn a lot more by installing and using Linux (and by developing on it with an editor like emacs or gedit or gvim ....). Also, take advantage that Linux is almost entirely free software, so you can study its source code and improve it.
Not installing Linux is not doing yourself a favor.
I believe cygwin is for those who love Linux but have to use Windows. It cannot give you the entire Linux feeling (e.g. you won't be able to write shell scripts looking into /proc which does not exist in Windows, even with cygwin).
If you want to use a simple environment emulating all Linux environment as alternative to cygwin (more lightweight) you can try mingw and you can use notepad++ or emacs or vim to provide some syntax highlight on sh scripts.
Everyone has said to go full Linux or use various mocks.
Cloud9.io is a good option if you don't need that much.
You can set up a "workspace" which can be accessed online, lets you write in literally any language similar to np++, but the best part is, it's an online Linux, so you have a terminal, with all your shell commands - no mock up, no dual boot.
The downside to this is that the free users aren't given that much power, so if you wanted to execute some high-level maths or output a large image, it will crash as you will be using too much memory. But it is still really worth getting into, it's only ever crashed once on me, and I do some pretty memory-intensive things.
There is cygwin , that's a linux console for windows.. so you can execute all the linux command with it.
Install Cygwin to execute the commands. However you can use NotePad++ as editor which has native windows binaries.
http://www.cygwin.com/
http://notepad-plus-plus.org/
For Eclipse Luna Should use this one old version fails on UI error
Help > Install New Software… > Add…
Name: ShellEd
Location: http://sourceforge.net/projects/shelled/files/shelled/update/
I had a similar problem.
I like both Linux and Windows, and I am working on both systems, but for programming (and generally, for text editing) I use Windows, for different reasons. For example, I write C/C++ code on Windows, using the Windows DevC++ IDE, then I can compile this project on Linux, by sharing the files on LAN. Now I have to write long scripts, and I would like to do it in a similar way. Ok, maybe its a special request, but maybe I am not the only one who works in such a mixed environment.
First, I tried notepad++ (it is suggested by others as well), but does it support syntax highlight for Linux scripts? I didn't found this feature...
Then I tried gedit compiled for Windows. It requires the GTK library installed (actually it was already on my Windows). Gedit has syntax highlight for scripts!
So I suggest using gedit for Windows for this case. The edited script can not directly be started/tested with it, but for editing, it is fine!

compiling g++ on vmware player ubuntu - on win XP

I installed a virtual machine VMWare Player Ubuntu on my win XP.
At first when ever I tried to compile my program it didn't work so I installed something that allowed me to use G++
but now when i run:
g++ - Wall a.cpp -o out
It creates an executable out. But if I run it by the command out
it gives me an error
bash: out command not found
Does any one know the problem?
Thanks
The compiler is most likely compiling just fine.
Try running the program like this:
./out
It should not matter, if Ubuntu is installed in a virtual environment, at all. As I see it, the only problem is running the program :-)
Because . isn't in the PATH by default, you need to give bash the exact name of your executable; it won't find an executable file in your current working directory. (This is a good thing; it vastly improves security on multiple-user systems, and the habit is a good one to be in on single-user systems.)
Try: ./out.
I suggest giving the filename something better than out -- a.out is the typical output filename for historical reasons, but nothing says you have to keep it or anything like it. :)

Trying to compile and debug C++ from Vim

I've been learning C++ and Allegro using Code::Blocks on Windows XP, and recently felt like learning Vim. However, I have no idea how to compile a program "manually" (i.e., without using an IDE).
For compiling from within Vim, I have gotten as far as setting the makeprg to gcc, but I understand I also need a makefile. What is that and how do I write one? Is it with the makefile that I can use libraries such as Allegro?
Also, I've gotten quite fond of the CB debugger (I'm using gdb). Is it possible to do something similar with Vim?
Thank you.
Look at MinGW. I would avoid Cygwin if you only need gcc and make. You'll want both MinGW and MSYS. MSYS has a windows port of make.
If you're interested in more unix utlities for the windows command line I recommend CoreUtils.
For learning make see the manual
You don't necessarily need a Makefile, but it's the preferred (and possibly sanest) way of compiling code on UNIX-like systems.
I don't know if GNU Make has a Windows port, but you can probably run it under Cygwin.
To learn more about GNU Make and Makefiles:
make (Wikipedia)
GNU Make
GNU Make Manual
Also, see this question: compile directly from vim
Mandatory edit: I don't use Windows or Cygwin. You might want to take epochwolf's advice on that department.
I'm not in expert in makefiles and debugging but I know that Vim lets you do many things.
For example if you want to compile a file with gcc, it's not very different from the usual way. In normal mode type:
:!gcc file.c -o file
In fact you can use (almost) every system command just by adding "!" in front of your command.
gdb also works with Vim
:!gdb
I hope it will help you.
To integrate vim with devenv, you can use devenv from Visual Studio to complie the project in vim. The command as follows:
Devenv SolutionName /build SolnConfigName [/project ProjName [/projectconfig ProjConfigName]]
Typicatlly, the devenv should located in C:\Program Files\Microsoft Visual Studio 8\Common7\IDE. Set it to the path of environment to make it callable from vim. We also need to make vim recognize the error messages thrown by the commandline build tool devenv. Just put the following lines in your vimrc:
" Quickfix mode: command line devenv error format
au FileType cpp set makeprg=devenv.com\ /Build\ Debug\ *[SolutionName]*
au FileType cpp set errorformat=\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m
Then You can use :make to compile and build the program from vim.
EDIT1: A few bookmarks you might find useful:
GNU make tutorial (this one uses gcc and make, so it should be right up your alley)
Another one
Win port of some of GNU utils Can was mentioning; I personally use these and haven't had any problems with them on Windows platform.
Yes, you can compile without the makefile. If your program is simple (for example, one file only) you can compile by calling the compiler and including the name of the program in the same line (don't remember how it goes with gcc). Of course, to make things easier this can be mapped to a key within vim, so you don't have to jump to command prompt and back.
If you are working on a bigger project, which consists of several files and such, than a makefile is useful. It will "search" through the files, determine dependencies, include them in the build, maybe put the source files in one directory and the resulting exe file in the other and such. So it is more of a linking and building system than just compiling.
Although the GNU make mentioned in Can Berk Guder's answer is a popular one, there are quite a number of other tooks for "building makefiles" ("makefile" has become a type of synonym for that kind of operation) - here, you can see some other options on this link. Due to its part in history vim has good support for :make, but others can be easily used as well (there are a lot of texts on this subject on VimWikia.
Well, that's it. Just my 0,2 euros :)
As long as you have GNU-make installed (with cygwin or mingw under windows), you don't need to write a makefile for single-file projects. Just run :make from vim, and that's enough.
If your project is made of several files, then you will have to write a makefile (or any equivalent for scons, aap, (b)jam, ant, ...), tune your &makeprg in consequence, and finally call :make from vim. See the relevant category in vimtips. You can of course run the compiler as you would have ran any other external tool, but you would loose the possibility to jump to the line(s) of the error(s).
NB: if you are using the win32 version of vim, and gcc-cygwin, you'll need to translate the error messages obtained. I used to maintain a perl script for this purpose, it is now part of a bigger suite (still in beta stage)
Regarding your question about debugging, it can't be done from vim under windows for the moment. The only debugger that can be integrated so far is gdb, but under linux only ; see the pyclewn (.sf.net) project.
I'm not sure about debugging, but I know an easy way to compile and run the current program as I wrote a small vim plugin to do so.
http://pastebin.com/qc5Zp2P7
It assumes you are using the g++ compiler. If not, just change the name to the compiler you're using. Save this file to whereveryouinstalledvim/ftplugin/cpp.vim
In order to compile and run the currently open program, just type shift-e while in non-editing mode.

Resources