The Open Source Swiss Army Knife

/programmingToolBox/
/programmingToolBox/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /programmingToolBox 
Permalink: gcc.htm
Title: flags and options for the gcc compiler
article options : please login   |  print view

    gcc
  1. introduction
  2. debugging options
  3. command line options
  4. miscellaneous

introduction

    definitions
  • a native compiler is one where the host and target are the same. Compare to a non-native compiler, where you can compile code for another machine on your machine.
  • find out your gcc version by typing gcc -v
  • THANKS TO THE HOWTO I learned that a compiler can be forced to use another spec file by typing gcc -V version

compiling is a series of steps:gcc hello.c -o hello does all the steps at one time. See the section below on command-line options to the compiler.

debugging options

> Is this enough? I'm seeing that with --enable-debug only the
> option -g is passed to the compiler and the option -O2 is
> still there, is it not better compile with -O0 if you are
> going to debug it?

If you want to single-step through the code a lot, then -O0 is good.
But are you really gonna do that so much? I do most of my tracing
at the level of function calls.

I tend to use -O1 as a compromise setting --- the code isn't totally
scrambled but it doesn't run like a dog either. (Also, for development
purposes, -O0 is evil because it disables certain useful warnings in
gcc.)

command line options

    options to the compiler
  1. -o: specifies name of output file
  2. -c: specifies to just make the object file not link the object file to any libraries. If you omit -o and use -c the output file will be named the input file with .c replaced with .o
  3.  −E  Stop after the preprocessing stage; do not run the compiler proper.
               The output is in the form of preprocessed source code, which is
               sent to the standard output.
    
               Input files which don’t require preprocessing are ignored.
    
    source: man gcc

    gcc -E hello.c -o hello.cpp: shoves in macros with -E, output specified by -o
  4. gcc -x cpp-output -c hello.cpp -o hello.o (creates an object file by replacing .c with .o). -x tells the compiler to begin at that step, i.e. that resulting from the above statement gcc -E hello.c -o hello.cpp. -c tells gcc to compile without linking.
  5. link the object file to create the binary: gcc hello.o -o hello
    try compiling the code as cc -I -c .c -o .o
    cc -shared -o .so .o
  6. -Idir
    append dir to the list of directories to search for include files
  7. -llibrary
    use the library library when linking
    the library is actually a file named liblibrary.a
  8. -L
    the directories to search for the above library
  9. source: libssl source
     Note on multi-threading
     -----------------------
    
     For some systems, the OpenSSL Configure script knows what compiler options
     are needed to generate a library that is suitable for multi-threaded
     applications.  On these systems, support for multi-threading is enabled
     by default; use the "no-threads" option to disable (this should never be
     necessary).
    
     On other systems, to enable support for multi-threading, you will have
     to specify at least two options: "threads", and a system-dependent option.
     (The latter is "-D_REENTRANT" on various systems.)  The default in this
     case, obviously, is not to include support for multi-threading (but
     you can still use "no-threads" to suppress an annoying warning message
     from the Configure script.)
    

command-line blues

6. When linking PHP, it complains about a number of undefined references.
Take a look at the link line and make sure that all of the appropriate libraries are being included at the end. Common ones that you might have missed are '-ldl' and any libraries required for any database support you included.
If you're linking with Apache 1.2.x, did you remember to add the appropriate information to the EXTRA_LIBS line of the Configuration file and re-rerun Apache's Configure script? See the INSTALL file that comes with the distribution for more information.
Some people have also reported that they had to add '-ldl' immediately following 'libphp4.a' when linking with Apache.

miscellaneous


Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top