Difference between revisions of "Help on Gcc"

From Asibot & HOAP3 & TEO Wiki
Jump to navigation Jump to search
(Created page with '== Wrapping a class == http://oss.sgi.com/projects/inventor/mail/info-inventor-dev/msg00512.html You need to compile your source with the gcc option: -Wl,--wrap,__ctype_b the…')
 
Line 1: Line 1:
== Wrapping a class ==
+
Random low-level stuff somewhat related to gcc.
 +
 
 +
== Wrapping C in a C++ class ==
 
http://oss.sgi.com/projects/inventor/mail/info-inventor-dev/msg00512.html
 
http://oss.sgi.com/projects/inventor/mail/info-inventor-dev/msg00512.html
 
You need to compile your source with the gcc option:
 
You need to compile your source with the gcc option:
Line 11: Line 13:
 
     }
 
     }
 
and link it in.
 
and link it in.
 
  
 
== Creating a static/dynamic library ==
 
== Creating a static/dynamic library ==

Revision as of 01:39, 8 November 2010

Random low-level stuff somewhat related to gcc.

Wrapping C in a C++ class

http://oss.sgi.com/projects/inventor/mail/info-inventor-dev/msg00512.html You need to compile your source with the gcc option:

   -Wl,--wrap,__ctype_b

then compile an object (.o) from the following source

   #include <ctype.h>
   extern "C" {
   __const unsigned short int **__wrap___ctype_b (void) {
     return __ctype_b_loc();
   }
   }

and link it in.

Creating a static/dynamic library

Build libfoo.a on libc6 2.2.5 from foo.c as follows: % cat foo.c

  1. include <ctype.h>

int foo(int c) {

       return isdigit(c);

} % cc -o foo.o -c foo.c % ar ruv libfoo.a foo.o <----------important step. and copy libfoo.a to libc6 2.3.1 environment. On libc6 2.3.1: % cat bar.c

  1. include <stdio.h>

extern int foo(int c); int main(int argc, char *argv[]) {

       printf("%d\n", foo(*argv[1]));
       exit(0);

} % cc -o bar bar.c libfoo.a libfoo.a(foo.o)(.text+0xa): In function `foo':

undefined reference to `__ctype_b'

collect2: ld returned 1 exit status Of course, libfoo.a is rebuilt on libc6 2.3.1, there are no problem.