I have a simple ./compile.make script that produces a bunch of object .o files. The contents are like this (first 5 lines printed):
compile.make:
gfortran -c -O3 active.f
gfortran -c -O3 alchemy.f
gfortran -c -O3 analysis.f
I run the script by doing ./compile.make. I'd like to compile everything with the -g flag so I can debug using (gdb) but I was wondering if there is a better way to add the "-g" flag without having to manually edit every line of my compile.make file.
*EDIT: I know that find/replace option is available and not much of a hassle at all. I was just curious as to whether the flags can be added upon execution of the script.
http://www.brunolinux.com/02-The_Terminal/Find_and%20Replace_with_Sed.html
Related
I am new to the clang++ compiler flags. I have an issue regarding compilation. Here is my cmd:
clang++ -I ../llvm-project/llvm/include -I ../llvm-project/clang/include
-I ../llvm-project/build/tools/clang/include -I ../llvm-project/build/include
-O3 -c $(llvm-config-7 --cxxflags)
projectToTestHeadersBuilding.cpp -o projectToTestHeadersBuilding
I am getting error:
./projectToTestHeadersBuilding: cannot execute binary file: Exec format error
After execution I have projectToTestHeadersBuilding file. But I can not run executable. Can you please help me to understand how to get executable, so I can run it using ./projectToTestHeadersBuilding ?
In your initial command you use the -c flag which makes clang output an object file. This is part of a compiled program but not a complete executable, in order to get the final executable you must perform a linking step, usually with other object files.
A simple compilation can be done as so:
clang++ projectToTestHeadersBuilding.cpp -c -o projectToTestHeadersBuilding.o
clang++ projectToTestHeadersBuilding.o -o projectToTestHeadersBuilding
./projectToTestHeadersBuilding
Generally we do not need to explicitly pass all those -I flags you have passed. If they are needed with your setup, add them to the commands I've included above.
the program no run. how to fix it ( i use C-Free 4.0)
? g++.exe : cannot specify -o with -c or -S and multiple compilations
Can you include the entire build command that you are using? My guess is that you are trying to compile multiple files into an executable in a single command (such as g++ file1.cc file2.cc file3.cc -o file.exe), but you've also got a -c flag in the commpilation command.
For reference, normally when you compile, two things happen. First, source code gets turned into machine code. Second, machine code gets linked to produce an executable.
In gcc/g++, you can compile one source file into machine code by using the -c flag. You can link one (or many) machine code file(s) into an executable by using the -o flag. There's a shorthand where you can compile and link all in one step using the -o flag (but that's generally not a good idea, because then any change to any file requires you to recompile everything).
As for -S, that's for when you want to generate assembly code from source code. I'm guessing that's not what you are doing, though.
Here's an example, just to round it all out. Suppose that you have files file1.cc and file2.cc, and there is a main() function in file1.cc. Then you can create machine code like this:
g++ file1.cc -c
g++ file2.cc -c
This will result in there being two new files, file1.o and file2.o.
Next, you can link them like this:
g++ file1.o file2.o -o file.exe
This will produce file.exe, the final executable that you can run.
Netbeans is not forming the compile instructions correctly. The line below is the compile instructions.
g++ -m64 -o dist/Debug/MinGW-Windows/firebirdconnection_test build/Debug/MinGW-Windows/main.o -lall_in_one.cpp -static
and you can see that it is not putting the space between -l and all_in_one.cpp.
This there anyway to modify the build instructions to allow for that space?
I am using libtool and automake to build our project. Project has CPP and ASM code.
CPP code is built properly and .o files are created.
To build ASM code below given instructions are given in config
AM_PROG_AS, CCASFLAGS
ASM code seems to be not building. In compilation summery I see that ASM code with .s extension is built but object file are missing. When I run below command separately(Which I have taken from the verbose of compilation) it runs but not generating the object file.
libtool: compile: gcc -S -DARCH_X86_64=1 -g -O2 -c file.s -fPIC -DPIC -o .libs/file.o
What could be the reason ?? Any additional configuration is required.
Is there any option where I can force libtool to use yasm for ASM code building??
-S option instructs gcc to generate an assembly file, not assemble. It only makes sense for C files, if you want to examine generated assembly code. Remove that. Next time consult the manual for the meaning of the options.
Say I have two files file_1.f90 and file_2.f90 and they use some libraries. Could be any programming language. Then I compile and link in one step using
ifort -I/include_dir_loc -o my.o file_1.f90 file_2.f90 -L/Lib_dir_loc
Is there a way to tell the terminal or ifort or whoever takes over to tell me the individual steps it carries out. It could be that it goes
ifort -I/include_dir_loc -c -o file_1.f90
ifort -I/include_dir_loc -c -o file_2.f90
ifort -o my.o file_1.o file_2.o -L/Lib_dir_loc
What actually happens after I type the first command? Who carries out the compilation using what commands and who coordinates between the compiler and the linker?
for ifort:
-v will show the tool commands and execute them
-dryrun will show the tool commands but will not execute