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

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.

Related

How do I compile fortan code on a cluster using a given build file

I want to run a Fortran code on a cluster. This is to run a test case where all the needed files for the test case are provided.
I have uploaded all the files in a directory on the cluster. Among the files is a "build" file (the content of which is below) that seems to compile the code I want with specific flags using an Intel compiler. I don't know what file type it is (pop os sees it as an audio file which is not very helpful) and I don't know what bash command to use to make it compile the Fortran code.
I have tried build myfortrancode.f90 and make build but I get command not found for build and nothing to be done for build using make (and I guess it makes sense since there are no "make" files.) I have also checked the .pbs file that comes with the test case but as expected it doesn't refer to this build file.
ifort -O2 -r8 -fpe0 -g -traceback -c myFortranCode.f90
ifort -O2 -r8 -fpe0 -g -traceback -o myFortranCode myFortranCode.o
rm -f *.mod *.o
Try the bash command below to run all commands in your "build" file.
source build
Or you can add execute permissions to build and run it with the following bash commands:
chmod 775 build
./build

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.

Error fatal - No such file or directory

I have installed the cds library with command ./build.sh -b 64 -z '-std=c++0x' -l '-L /usr/lib/x86_64-linux-gnu' --with-boost /usr/include/boost --amd64-use-128bit at build folder.
After I tried to compile the example init.cpp of src folder, I typed this in terminal: g++ init.cpp -o init, and terminal showed: fatal error: cds/init.h: No such file or directory.
What should I do for compilation command in this case?
Thanks.
For general troubleshooting in cases like this, i would recommend finding where on the system the file got installed (if your build.sh actually installed the file). You would be able to find the missing header file using
find / -path '*/cds/init.h' 2>/dev/null
Then you need to supply two parameters to g++:
First one gets the compiler to know about the include files from the install directory
-I path_to_folder_one_step_above_cds_folder
Second one gets the linker to know about the librarys location. If the library file is called libcds.so, you can find it by running
find / -name libcds.so 2>/dev/null
So for linking, you supply the flag
-L path_to_folder_one_step_above_libcds.so
In your case you might not need the -L flag, since most of your library supposedly is header only.
UPDATE: the build.sh script is printing out important information at the top, starting with "Building with the following options:". The important bits will be "Compile options:" and "Link options:". Those should be enough to solve your specific option.
UPDATE2: build.sh also exports some flags which might include more options. You can print them out directly after running build.sh by running
echo LDFLAGS=$LDFLAGS
echo CFLAGS=$CFLAGS
echo CXXFLAGS=$CXXFLAGS
you are likely to need to pass all these options to g++ when compiling and linking against that library. LDFLAGS are specific to the linker only. Both the other ones are needed for compiling c++ files.

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.

What does ./outputfile mean in Terminal

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.

Resources