How to run .cc extension file in linux? - linux

I have main.cc file and i would like to run this file in linux. May i know what would be the correct way of executing this file ? Is it
gcc -o x main.cc
? Any help or feedback is appreciated.

In your case it would be gcc main.cc -o main.ou where main.cc is your main-file and main.ou your output file.
You can also read more about executing c/c++ files here:
http://www.cyberciti.biz/faq/compiling-c-program-and-creating-executable-file/

The command you gave will compile the file. The resulting executable is put in x. To run it, you do:
./x

Related

How to compile and run a c program in Linux terminal?

compile using gcc that the compiled code be saved with a different name and run it. I need the commands
To compile file.c and create executable file do
gcc -Wall -Werror -o file file.c
If you need additional libraries, add them after the C file.
To run the program do
./file

bash script uses gcc in a loop to compile all

I need write bash script that uses gcc in a loop to compile all .c source files in current directory into .o object files, and additionally creates .s assembly listings in Intel format. Then, the .o files are linked into run executable.
for i in *
do
gcc -type -f "*.c"
done
i just began that but I'm not sure I began it correctly
Rather them writing a bash script, it's acutally better to write a makefile which is specialised in automatizing this kind of things.

How to make scons make gcc with assembly file during compilation?

For example, I've got a 'b.c' file, I compile and generate the code, while I wish to see an intermediate assembly file, I can do under shell like this:
gcc -S b.c
gcc -c b.c
gcc b.o -o b
My question is, how to specify inside scons SConstruct, with all these steps, to make sure I get b.s, b.o and 'b' executable? Seems scons only support functions like Program, Object, Library, so I only get b.o and 'b'. But how to make out 'b.s', while I don't wish to introduce any duplicated work by the compiler(to save time).
Thanks.

how to run gcc command in script to exe main.c

I'm new in linux trying to run .C program from another directory in script. script is in home directory and .C program is in Desktop directory. here is script.
#!/bin/bash
chmod 777 myscript
cd /home/unifi-007/Desktop/
gcc main -o main.c
./main
But i'm not getting it right. how to execute main.c in script.
The usage of gcc is clearly wrong, it should be gcc -o main main.c.
BTW, .C is a suffix for C++ (at least for GCC it is), not C.
BTW again, normally, you do not run a C source file, you compile it, and run the executable file generated by compiler (by linker, actually).

Using .sh file to compile commands in source code

I am using FORTRAN to solve partial differentiate equations. Main program and subroutines have been put in .f file. And I got a .sh file to compile the commands in source code in linux operating system. This file has been attached. But I failed to run this. After struggling for a week, I really need some help on this. Please any help would be greatly appreciated!!!
#!/bin/bash
#
mkdir temp
cd temp
rm *
~/binc/$ARCH/f77split ../fishpack.f
#
for FILE in `ls -1 *.f`;
do
gfortran -c -g $FILE >& compiler.txt
if [ $? -ne 0 ]; then
echo "Errors compiling " $FILE
exit
fi
rm compiler.txt
done
rm *.f
#
ar qc libfishpack.a *.o
rm *.o
#
mv libfishpack.a ~/libf77/$ARCH
cd ..
rmdir temp
#
echo "Library installed as ~/libf77/$ARCH/libfishpack.a."
This looks like the shell script is simply trying to compile a fortran file, but instead of using gfortran's internal toolchain, it is compiling parts manually then linking them together. I have a feeling (though I haven't confirmed) that the call to the program ar is bad, even if it got that far (I'm guessing it should be ar -qc instead of ar qc.).
Anyway, if all the source is in a single fortran file that someone else gave you (fishpack.f), you might be able to compile the whole thing with a single call to gfortran:
gfortran fishpack.f
It should create (by default) an output executable with a filename a.out. If the fortran code is not structured such that it can be lumped into a single file, you may need to work on separating some things out (--as well as updating to at least f90, though that's an aside--).
Good luck.

Resources