win10 gdb not in executable format: File format not recognized - c

I'm a C newbie who recently installed gcc and gdb on windows 10 through MinGW. However, when I tried to debug my program using gdb through win10 cmd I got an error.
Here's what I did on cmd:
gcc ./test.c
gdb ./a.exe
And I got this:
not in executable format: File format not recognized
Then I tried to install gdb on bash as well and did the following:
gcc ./test.c
gdb ./a.out
(gcc through bash would create a.out but would create a.exe through cmd)
This time gdb seems to be able to start the executable file correctly, however when I tried typing in break commands I got another error message:
No symbol table is loaded. Use the "file" command.
Can anyone help to solve the problem?
PS. I've tried using file but it didn't work either.
PSS.after using gcc -g ./test.c the gdb seems to be working correctly on bash. However the windows one still can't run .exe file.

Related

C Programming: The output window in vs code is empty

the screenshot shows what the empty field and the code writtenI have just set up VS Code for programming with C, I installed all the necessary things (gcc, gdb..etc)
But when I started writing basic code, vs code shows an empty output after I run it
Installation (Ignore if installed)
Windows
Install mingw/gcc/clang compiler and then add it to the path.
GNU/Linux
Install gcc/clang compiler using your package manager.
Arch Based Distros: `sudo pacman -S gcc`
Ubuntu/Other debian based distro: `sudo apt install gcc g++`
Now, install C/C++ extension for VSCODE here's the link C/C++ extension
Installing the C/C++ VSCODE extenion
Or you can directly install it through Ctrl+Shift+P and paste this snippet ext install ms-vscode.cpptools.
Compiling
Now, open your terminal in VSCODE and run gcc Test.c -o test and then run ./test to execute your program.
Or, if you have installed clang compiler then the terminal command goes here clang Test.c -o test and then run ./test to execute your program.
Main method have return type int, try return 0; after printf. Or you need to add argument to main method, in java program i know we can not run program without argument.
Or
Try make void main method

Using GCC to compile C code

I installed MinGW on my Windows 8 laptop and tried to compile a C code file with
gcc test.c -o test.exe
the compiler gave no warnings or errors but it did not create test.exe
how do i get the compiler to create the file
test.c
My terminal session
An interesting observation:
When I deliberately introduce an error in the code and try to compile the compiler shows the error
Code with error
Compiler output
When I try compiling the same code using Command Prompt
This is what it shows
But the file does exist in the MinGW\bin directory
I moved the
test.c
file to
C:\
and started the command prompt in the
C:\MinGW\bin
directory
and here is what it outputs
Problem partially solved:
I disabled hybrid boot in windows 8 and restarted the computer. The compiler now works in Command Prompt but not in PowerShell.
Try to compile your code normally as
gcc test.c
If you get default output file a.exe,then go for
gcc test.c -o test.exe
I would suggest you go through this compilation instruction :-
gcc -o test.exe test.c
I believe this code runs perfectly on your windows system.Please inform if it doesn't!
I know this is an old question, but I came across this after having this same issue and managed to solve it.
When I installed MinGW on my computer, I didn't add the MinGW bin directory to my PATH (<mingw install dir>\bin). I had written some code that referred to the GNU compiler binaries by their full path, and when I tried to compile something I experienced the same behavior you described.
So it seems like MinGW won't work properly unless it is added to your PATH. I think it's weird that gcc didn't complain about it though.
One possibility is Microsoft's use of VirtualStore.
This can cause problems with "missing" files with Cygwin. See for example, Cygwin sees a file that windows can't--I want to access this file from python and https://superuser.com/questions/400600/file-only-visible-to-cygwin-not-windows.
To verify whether this is the case, try doing a search of your entire hard drive for the file test.exe. Or try MinGW's ls rather than dir.
And since the OP "partially solved" the problem by moving to another directory, this could be the cause.

Installed cygwin but not able to run C programs

I am trying to write some C code and execute it through Cygwin command line interface using the below command but it throws me an error. I selected the gcc package when i have installed the Cygwin utility. Please kindly share your thoughts regarding the same. Thank you.
$ gcc HelloWorld.cpp -o HelloWorld
-sh: gcc: command not found

How do I compile on a Mac?

I'm trying to Compile my C program I have on my Mac.
I've been using Codepad.org to check that my Code works, but Codepad doesn't let me input my own values.
I need a Compiler that lets me input my own values, and I can save the Output as a txt file (to submit to my Professor).
2 possible ways,
get xcode, which includes gcc.
install macports, and use macports to install gcc.
Just use the Terminal app with gcc.
You can then run by appending ./ before the program name and > to save the output.
gcc -Wall program.c -o program
This will compile with all warnings (-Wall) with executable name program (-o).
run ./program > textfile.txt and this will put the output in a file.
(You might have to install Xcode and command line tools depending on your OS version)

How to execute and compile a program in Xcode via command line in c and where's the executable?

I'm trying to execute via command line a code written in C. I tried gcc -o file file.c, but it did not work. I need to learn how to compile and execute a code using gcc and llvm without graphical interface. Furthermore when I compile the program I cannot find the executable file in Finder (there's no Developer folder in Library).
Thanks in advance.
You can use xcrun tool:
#/usr/bin/xcrun cc -o file file.c
Note: if you have several Xcode versions you can chose with xcode-select and your command above will use compiler and the rest of the tools from the selected SDK.
If file.c is in the Desktop directory: Did you change to that directory beforehand?
Usually Terminal.app starts in the home directory, e.g.: /Users/yourname
To get to the Desktop directory:
cd ~/Desktop
Then check if the source file is there:
ls -l file.c
Then try again to compile:
gcc -o file file.c
Check for any error messages. If no output is given everything is fine and there should be an executable which can be (surprise!) executed:
ls -l file
./file

Resources