What does ./outputfile mean in Terminal - xcode

I'm new to using Terminal for compiling code. In the following
gcc inputfile.m -o outputfile
./outputfile
What does the ./ mean?
Thanks

./outputfile tells Bash (the program that runs the Terminal) to run the file outputfile which is located in the current directory (./)
Bash can run any file, whether is a compiled file (like you case) or a script.

That is your compiled program. The line ./outputfile is calling the executable you created. It may seem a little strange that you have to do this in your case because you are only using 1 input file, but imagine that you are creating a bigger program with a many files that all need to be compiled together.
gcc inputfile1.m inputfile2.m class1.m class2.m main.m -o outputfile
All those files would be compiled and put into outputfile.

Related

I compiled a program in fortran using GCC but the executable outputs files to the user path of my system instead of where the program is located

The program is placing the files to the path Users/gavinpaull/ instead of the Oil and Cells folder. Can I fix this issue with the compiling command?
I used gfortran -o Planar_Surfactant Planar_Surfactant.f while inside of the Oil and Cells folder to compile the executable.
gavinpaull#Gavins-MacBook-Pro-2 ~ % /Users/gavinpaull/Documents/BMEN\ Research/Oil\ And\ Cells/Planar_Surfactant ; exit;
this is what shows up when I run the program along with some information about the base values.
I'm pretty new to fortran coding so I'm not quite sure what to try or how to resolve this issue.
Paths in the program are relative to the current working directory, which starts off as the directory where the program is launched, not where the program binary happens to be located.
(This is per se not specific to Fortran.)

mingw5.4 : cannot open output file /home/user1/test.o: No such file or directory

I am building my test.c using mingw5.4 using command:
/software/mingw5.4/bin//x86_64-w64-mingw32-gcc test.cxx -o /home/user1/test.o
But I am getting following error:
c:/cygwin64_new/home/admin/software/mingw5.4/bin/../lib/gcc/x86_64-w64-mingw32/5.4.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot open output file /home/user1/test.o: No such file or directory
If I use version mingw4.8.3 the same file is compiling fine.
/usr/bin/x86_64-w64-mingw32-gcc test.cxx -o /home/user1/test.o
If anybody know reason of error in case of version mingw5.4 please let me know.
LOL. I've done that. There is a command called test on *nix systems. Some shells have it built in (for speed). Try running ./test or text.exe or call the executable something else.

Running an executable in Mac Terminal

I just made a .c file and compiled it with gcc in the terminal on OS X 10.8.2.
My syntax was gcc -o <filename> <sourcefile> and that was fine. Now I see I have an executable and file <filename> tells me as such, but I'm not sure how to actually run it beside double clicking the icon, /lame. When I try running the executable by just typing I get command not found, but I thought it was executable...?
Thank you.
EDIT: I"m so stupid, it was just open <filename>
Unix will only run commands if they are available on the system path, as you can view by the $PATH variable
echo $PATH
Executables located in directories that are not on the path cannot be run unless you specify their full location. So in your case, assuming the executable is in the current directory you are working with, then you can execute it as such
./my-exec
Where my-exec is the name of your program.
To run an executable in mac
1). Move to the path of the file:
cd/PATH_OF_THE_FILE
2). Run the following command to set the file's executable bit using the chmod command:
chmod +x ./NAME_OF_THE_FILE
3). Run the following command to execute the file:
./NAME_OF_THE_FILE
Once you have run these commands, going ahead you just have to run command 3, while in the files path.

Cannot Execute File in Terminal OSX

I can run compile in OSX terminal using g++ -Wall -c pa1.cpp -o pa1. Which creates pa1, so I know my compilation works in terminal but I am having issues with execution. I have tried ./pa1 , ./a.out, pa1 and few others. I believe the issue is with Xcode, yet the fact that my code will compile in terminal and creates an executable makes me unsure. Thought, I would ask here for suggestions before reinstalling Xcode.
Use g++ pa1.cpp -o pa1 and then you'll be able to run your new executable as ./pa1. This require that your whole program is in pa1.cpp. If it is spread in multiple files, you'll have to list all of them on the command-line.
As said in the comments, the -c option means compile, ie. Create an object file that can be passed to the linker to build an executable. If you don't use this option, g++ will first compile any source file, then invoke the linker on all the object files to create an executable named a.out by default (name comes from historical reason).
You can see that the output of your command was not an executable binary but an intermediate object file by using the file util.

gcc -c option not giving execute file permission to the output file

i am using ubuntu 10.10
i am trying to compile simple helloworld file using
gcc -c option
the output file is created but it does not have execute permission
if i dont use -c option the output file has execute permission ..
Please help
The command gcc -c generates a non-executable object file. If you want the output to be executable, do not use the -c option.
I am not sure what you hoped -c was for, but it is exactly for not generating an executable, and your GCC is working as designed.
From the man gcc:
-c Compile or assemble the source files, but do not link. The linking
stage simply is not done. The ultimate output is in the form of an
object file for each source file.
It is not executable. It needs to undergo linking process to become an execution file.

Resources