月份:三月 2008

make file link with dynamic and static libraries

Posted on Updated on

  • to build static library
  • % gcc -c libtest.c -o libtest.o
    % ar rcs libtest.a libtest.o

  • to build dynamic library
  • -fPIC option tells gcc to create position independant code which is necessary for shared libraries

    % gcc -c -fPIC libtest.c -o libtest.o
    % gcc -shared -o libtest.so libtest.o

  • to use static library
  • % gcc -static main.c -L. -ltest -o testStatic

  • to use dynamic library
  • % gcc main.c -L. -ltest -o testDynamic

the source file of application who uses the library ltest, sould be located before -l options
-L<path to search libraries> (no spacing after -L)
-o <output file>
-l<lib_name> (no spacing after -l)

  • in static link, library name is lib.a ex: libtest.a libcheckitout.a or libxxxx.a
  • in dynamic link, library start with lib ex: libtest or libtest.so or lib….
  • gcc [options] -o

    to build-up EEE PC’s development environment

    Posted on

    1. install debian 4.r3 (2.6.18-6-686) and gtk+2.0 for developing GUI on EEE PC.
    2. write down a helloptg as the sample in GTK
    3. #include <gtk/gtk.h>

      int main(int argc, char**argv)
      {
      GtkWidget *window;
      gtk_init(&argc, &argv);
      window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_widget_show(window);
      gtk_main();
      return 0;
      }

    4. compiled by :
    5. % gcc -o hellogtk hellogtk.c `pkg-config –cflags –libs gtk+-2.0`

    6. copy it to EEE PC.
      change mode to 755
      and run it in console.
      It works.