The equivalent of "./" in windows is ".exe" extension? - c

I'm running in windows and I want to know what is the equivalent of ./my_program in windows?
For example if I compile a file in c with gcc, something like
gcc my_program.c -o my_program
The I 've to launch it with ./my_progrm in Linux,but in windows?
If I compile this : gcc my_program.c -o my_program, after I can't launch, I have to compile in that way : gcc my_program.c -o my_program.exe
I'm using minGW
Thank you

./ is not an instruction to execute a program in Linux, but the path to the program to execute.
Actually, ./my_prog means I want to execute le 'my_prog' program in the current directory (.), but you can also do ../my_dir/my_prog or anything else.
When you do ls -l, the shell understand /bin/ls -l.
In windows, if you are in the same directory as your .exe, you don't need to provide the path, just do my_program.exe
Actually, the executables files for Linux are binary files and they don't have any extension, but in windows it is .exe

Related

The Makefile in my c program doesn't work in CMD but fine in Linux terminal

I installed MinGW and i can type in CMD "gcc -o FileName main.c header.h" fine
but when i type in console "make" it tells me it doesn't know that command. Although i have a file called "Makefile" with no extenstion. Whats wrong?
MinGW has a renamed make, try mingw32-make.
You might like to copy it with the more common name in the same directory.

Ubuntu:: ./program: Permission Denied

Firstly, my problem is similar to this: Ubuntu says "bash: ./program Permission denied"
However, I feel the need to further clarify.
When I compile my program using:
gcc -c file.c -o file
and run
./file
I get this error:
bash:./file: Permission denied
When I use
chmod u+x file
and then run
./file
I get this error:
bash: ./file: cannot execute binary file: Exec format error
However, when I compile using
gcc file.c -o file <br/>
My program runs perfectly well using
./file
Can someone point out what is the problem with using the -c argument with gcc?
Type gcc --help to see some help.
-c Only run preprocess, compile, and assemble steps
This means that, when run with this option, GCC doesn't link the executable with any (even system) libraries.
In short, to run a program, the OS needs a starting point, which is located in some system library. Since in your case GCC isn't linking the executable with anything, the OS doesn't know how to run the file, where to start.

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

mingw to cygwin

I am a newbie in cygwin. However, I have used mingw so far, but it is not supporting fork(), so I need to switch to cygwin. I have created a build.bat file in my mingw (programming language C):
gcc -o mask mask.c -pg -I/c/opencv/build/include -lopencv_core231 -lopencv_highgui231 -lopencv_imgproc231 -L. -L/c/opencv/build/x86/mingw/lib
Can anyone suggest me how I can run this .bat file at cygwin or refer me to a site.
How can I run mingw executable with cygwin? Any refernce will be appreciated.
Thanks for your help
Emon
I believe that cygwin can run cmd (DOS command interpreter), which can then run your batch file. The problem is that cmd won't be able to use the non-windows paths that you have in your batch script. Try to run: cmd /c myBuildFile.bat at a cygwin prompt, and you should see what I mean.
It is better to use cygwin-style tools for making a build script. You should have the make program on your path which will allow you to write simple and more complex build scripts.
Alternatively you could convert your .bat build script into a shell script, something like this:
#!/bin/sh
gcc -o mask mask.c -pg -I/c/opencv/build/include -lopencv_core231 -lopencv_highgui231 -lopencv_imgproc231 -L. -L/c/opencv/build/x86/mingw/lib
Name it anything, e.g. myBuildScript.sh, then make it executable with: chmod u+x myBuildScript.sh.

gcc library linking issue in Windows after cygwin installation

C:\slite\1.1>gcc -c ".\src\SDR.c" -o ".\obj\SDR.o" -I".\inc"
C:\slite\1.1>gcc ".\obj\SDR.o" -o ".\exe\SDR.exe" -L".\lib" -lsres -lshis
.\lib/sres.dll: file not recognized: File format not recognized
collect2: ld returned 1 exit status
Could not compile C program using gcc after installing cygwin in Windows 2003.
Before installing cygwin, I was able to compile successfully.
I am compiling the code from Command prompt, not from cygwin terminal.
The gcc being used is from Dev-Cpp distribution.
Is the problem because of the directory separator ('/') between the libraries directory specified by -L and individual libs specified by -l, being used by gcc after cygwin was installed?
If i try to compile in cygwin terminal I am getting unknown function calls error, though the functions are defined in the headers included.
EDIT:
C:\srmlite\x7.5.0.146-1600>where gcc
C:\Dev-Cpp\bin\gcc.exe
The gcc was not from cygwin.
I have uninstalled cygwin and removed its directory too. I still see this problem.
Try to add the correct bin directory into the path in your Environment variables.
Something like this: C:\soft\cygwin\bin
Seems that Cygwin modified the default environment, adding itself to %PATH%, so you're actually calling cygwin's gcc, check that out.

Resources