Command not found, c++ application - c++

I'm workin in a bingo application, in pairs, my partner sends me his source code, it compiled with no problems but when I tried to run it:
~/Escritorio/Bingo $ g++ -o Bingo main.cpp Bingo.cpp Bingo.h -std=c++11
~/Escritorio/Bingo $ ./Bingo --version
$: Command not found
it saids no command found /(orden no encontrada)
He's on windows while I'm on linux instead, I never had this problem before.

Your compilation command builds a Bingo executable. Your execution command tries to run a bingo program. Case is significant.
You really should compile with all warnings and debug info and don't need to pass any header file to the compiler (header which you should #include inside Bingo.cpp and main.cpp):
g++ -std=c++11 -Wall -Wextra -g main.cpp Bingo.cpp -o Bingo
Then, edit your code till you got no warnings, and repeat the compilation above.
Check with
ls -l Bingo Bingo.cpp main.cpp
that you've got that executable and that its timestamp is newer than the source code.
Then try to run it:
./Bingo --version
if you need to debug it, use gdb as
gdb ./Bingo

Related

Compiling with MinGW crashes while Cygwin works

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

Debugger error: not in executable format: File format not recognized

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.

Command line arguments with CodeBlocks

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.

gdb not debugging mingw32-g++ compiled code well, but works with g++

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.

Tell ifort to show tool commands

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