gcc -pg creates a.out instead of gmon.out - gcc

How can I make my gcc -pg create a gmon.out file instead of an a.out? I'm trying to profile my CPU using gprof, but when I compile my .c file I get an a.out, which is not what I need.

The profile is generated when you run the compiled program, not upon compilation.

$ gcc -pg yourfile.c #compile with -pg
$ ./a.out #execute it
Now, you can see the gmon.out file.

Related

How to set gcc flags in Emscripten

I compile with the following command:
gcc -Wall -march=native -O3 -ffast-math -I/usr/local/include -I/usr/local/include -o waon main.o notes.o midi.o analyse.o fft.o hc.o snd.o -L/usr/local/lib -L/usr/local/lib -lfftw3 -L/usr/local/lib -lsndfile -lm
I now would like to compile with Emscripten. How do I convert the above gcc command into an emcc command?
The command you have described in the question is linking rather than compiling. However in general you should just be able to replace gcc with emcc and it will do the right thing. In this case you will need to replace not only this linking command but also the commands used to compile the sources to the .o files.
It would probably be a good idea to take out the -march option.
It looks like your project is using libsndfile and FFTW. You will probably need to compile these libraries yourself using emscripten. Both of them are using autotools so with a bit of luck you can compile them with emscripten simply by adding the following parameters when you run the configure script:
./configure --prefix=$HOME/emscripten-libs CC=emcc
make && make install
Then when you link your program you can specify -L$HOME/emscripten-libs/lib instead of -L/usr/local/lib.
Make research about emsdk download&setup on your computer.
Download emsdk instruction
Next interest link is :
emcc or em++ instruction
https://emscripten.org/docs/tools_reference/emcc.html
When you setup emcc in command line you can see this project (i make emcc final look based on python script runner.py etc.):
c-cpp-to-javascript
Basic and useful example's :
Pretty analog with gcc :
Args:
-lGL for openGL
-s TOTAL_MEMORY=512MB --memory-init-file 1 Memory staff
--preload-file folderWithImages/--use-preload-plugins If you use assets
-I forInclude/someheader.h
-L libraryFolder/someLib.lib
-std=c11
Simple run:
./emcc -O2 a.cpp -o a.js
or
./emcc -O2 a.cpp -o a.html
Links:
./emcc -O2 a.cpp -o a.bc
./emcc -O2 b.cpp -o b.bc
./emcc -O2 a.bc b.bc -o project.js
Or :
to get JS
emcc -s WASM=1 myAdds.a myLib.a source1.c source2.cpp -o build.js
to get html
emcc -s WASM=1 myAdds.a myLib.a source1.c source2.cpp -o build.html
Link together the bitcode files:
emcc project.bc libstuff.bc -o allproject.bc
Compile the combined bitcode to HTML
emcc allproject.bc -o final.html
Important note :
You can't take an existing .a library and convert it. You must build lib with emcc also.

How to create a shared library (.so) file in Mac os X using terminal

How to create a shared library (.so) file in Mac os X using terminal
Thanks in Advance.
This might be very late, but incase someone stumbles upon this I know how to make an so files for c++/c code. Assuming that you are in the directory with your .cpp/.c and .h files, in the terminal you must type:
g++ -c file1.cpp file2.cpp (add as many cpp/c files you want in the so file)
g++ *.o -dynamiclib -o lib_name.so
Then if you are using a cpp file that will run it:
g++ -c test.cpp -o test.o (compiling the program to see if the shared library works)
g++ -o test test.o -L. -l_name (create an executable to run)
./test (run the test)
For C code so files, it's the same but replace g++ with gcc.

g++ linker options changes target file name

I need help it is bug or I don't understand how compilation options are working ?
I have sample main.c file and try to compile it as:
$ g++ -nostdlib -g -fno-rtti -fno-exceptions -ffreestanding -nostdinc -nostdinc++ -Wl,--build-id=none,-g,-nostdlib,-nostartfiles,-zmax-page-size=0x1000 main.c -o main
and as output I have this:
$ ls
main.c startfiles
I am trying to understand why g++ created file named "startfiles" not "main" ?
If you read the GNU ld official documentation you will see that there is no option named -nostartfiles. What you do pass for arguments to the linker with that is the options -n and -ostartfiles.
If I were you, I would check those other options you try to pass to the linker as well.
-nostartfiles is a compiler flag as far as I know, not a linker flag.
For the linker, it's the same as -n -o startfiles, which is why you're getting that output file name.

Compile all .c files in a directory using GCC compiler in CMD

Is there a way to compile all .c files in a given folder by using the command line with GCC compiler ?
I've seen this page for Linux : http://www.commandlinefu.com/commands/view/3230/compile-all-c-files-in-a-directory but couldn't find any equivalent for CMD.
I guess gcc itself doesn't have such a parameter.
But you can try the regular wildcard argument of gcc *.c -o Output where the * (wildcard) is to read as "any".
You can compile your files with following command:
gcc -c -Wall file1.c file2.c file3.c
Here. -Wall will give you all the warnings and errors.
Do not forget to browse to the same directory where these files reside.

GCC equivalent of llvm-link

I use the following LLVM tools to convert a cpp project which is written in multiple files into "ONE" single assembly file.
clang *.cpp -S -emit-llvm
llvm-link *.s -S -o all.s
llc all.s -march=mips
Is there any way of doing this in GCC? In particular, is there any way of linking GCC generated assembly files into one assembly file? i.e., what is the equivalent of LLVM-LINK?
Perhaps LTO (Link Time Optimization) is what you want.
Then, compile each compilation unit with gcc -flto e.g.
gcc -flto -O -Wall -c src1.c
g++ -flto -O -Wall -c src2.cc
and use also -flto (and the same optimizations) to link them:
g++ -flto -O src1.o src2.o -lsomething
LTO works in GCC by putting, in each generated assembly file and object file, some representation of the internal GCC representations (like Gimple). See its documentation
You might want to use MELT to customize GCC (or simply use its probe to understand the Gimple, or try just gcc -fdump-tree-all).

Resources