So, I have been using CodeBlocks IDE for compiling my C and C++ programs. But I want to run the program from the command line. How do I go about this?
P.S I want to run it on Windows platform.
If you want to build a Code::Blocks workspace from the command line, use codeblocks.exe --build --target=W32_Release --no-batch-window-close MyApp.workspace where MyApp.workspace is your workspace. If you want to build a program from the command line without using Code::Blocks, use gcc -O2 program.c -o program where program.c is your program, or g++ -O2 program.cpp -o program for C++. You can get gcc & g++ from here.
Related
I'm writing a simple roguelike, and I was compiling statically to test, but I found that the program a) crashes when input is given, and b) does not seem to randomize at all when I compiled with MinGW. I switched over to Cygwin to check it out, and found that the statically-compiled version with Cygwin performed exactly as expected. I used the same commands for both: g++ -c FILE_NAME -std=c++14 -lncurses for each source file, then g++ -static -o dngn OBJECTS -std=c++14 -lncurses to link the final build.
The MinGW build:
mingw.png
The Cygwin build:
cygwin.png
Both images are screengrabs of it running with the respective compiler
I've written a program, saved it on the desktop under the name 'Swap.cpp' and when I run gdb (the first time), I get the error:
"/Users/myname/Desktop/Swap": not in executable format: File format
not recognized.
I have no idea what I'm doing wrong. Any help will be appreciated.
Sorry I should've given more information:
I am using Mac OS.
I've already compiled the program and have the Swap.o file that I can see on my desktop.And here are the commands that I enter while trying to run the debugger from bash:
$ clang++ -g Swap.cpp -o Swap
$ ./Swap
this runs Swap and then I try to access the debugger using:
$ gdb Swap
that then gives me the aforesaid message. I tried doing what Rakholiya Jenish suggested but to no avail.
To run gdb on windows:
path_to_gdb.exe program_to_debug
If the compilation was not proper, either compile it with your IDE (if you are using) or with g++ using cmd.exe as:
g++ -g Swap.cpp -o output -lm
I figured out how to use lldb instead of gdb. lldb works just fine. Here is what I did:
$ clang++ -g -o Swap Swap.cpp
$ lldb Swap
Thank you all for your help.
I have a simple c++ program I'd like to debug with gdb. When I compile it with
g++ -g main.cpp -o main.exe
I can use gdb just fine with the resulting executable. But when I use
mingw32-g++ -g main.cpp -o main.exe
gdb says things such as
in ?? ()
and functionality is limited; I seem to be able to set break points and run the program, but stepping and such yields the message
Cannot find bounds of current function
As I said, this only happens when compiling with the mingw32-g++ executable, and not with the plain g++ one.
Why is this, and how can I debug executables created with migw32-g++? Both executables run without issue.
Extra info:
Am on Windows 7.
g++ version: 4.8.2
mingw32-g++ version: 4.8.1
gdb version: 7.6.50.[lots of numbers]-cvs
If there's any other info I can provide to help find the issue, just let me know.
Say I have two files file_1.f90 and file_2.f90 and they use some libraries. Could be any programming language. Then I compile and link in one step using
ifort -I/include_dir_loc -o my.o file_1.f90 file_2.f90 -L/Lib_dir_loc
Is there a way to tell the terminal or ifort or whoever takes over to tell me the individual steps it carries out. It could be that it goes
ifort -I/include_dir_loc -c -o file_1.f90
ifort -I/include_dir_loc -c -o file_2.f90
ifort -o my.o file_1.o file_2.o -L/Lib_dir_loc
What actually happens after I type the first command? Who carries out the compilation using what commands and who coordinates between the compiler and the linker?
for ifort:
-v will show the tool commands and execute them
-dryrun will show the tool commands but will not execute
I use window Eclipse CDT gdb to debug a C++ program. When I wrote may own makefile as follows
all: prog1
prog1: prog1.cpp
g++ -o prog1 prog1.cpp
It compiled and run successfully. But if I click the debug button, it says no available source main.....
Edit
If I copy the same program to a new C++ project in Eclipse with its internal makefile (instead of writing my own makefile), I can use debug mode. But eventually, I have the following errors.
No source available for "__mingw_CRTStartup How should I do?
Thanks.
Try to change your line
g++ -o porg1 prog1.cpp
to
g++ -o prog1 prog1.cpp
Probably the name of the output (i.e., the program) is wrong, and therefore Eclipse can't launch it.