Difference between revisions of "Help on Gcc"
Jump to navigation
Jump to search
Jgvictores (talk | contribs) |
Jgvictores (talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Random low-level stuff somewhat related to gcc. | Random low-level stuff somewhat related to gcc. | ||
− | == Wrapping | + | == Wrapping a class (needed to compile Darwin2k on a 2010 kernel) == |
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 16: | Line 16: | ||
== Creating a static/dynamic library == | == Creating a static/dynamic library == | ||
Build libfoo.a on libc6 2.2.5 from foo.c as follows: | Build libfoo.a on libc6 2.2.5 from foo.c as follows: | ||
− | % cat foo.c | + | % cat foo.c |
− | #include <ctype.h> | + | #include <ctype.h> |
− | int foo(int c) | + | int foo(int c) |
− | { | + | { |
return isdigit(c); | return isdigit(c); | ||
− | } | + | } |
− | % cc -o foo.o -c foo.c | + | % cc -o foo.o -c foo.c |
− | % ar ruv libfoo.a foo.o <----------important step. | + | % ar ruv libfoo.a foo.o <----------important step. |
and copy libfoo.a to libc6 2.3.1 environment. | and copy libfoo.a to libc6 2.3.1 environment. | ||
On libc6 2.3.1: | On libc6 2.3.1: | ||
− | % cat bar.c | + | % cat bar.c |
− | #include <stdio.h> | + | #include <stdio.h> |
− | extern int foo(int c); | + | extern int foo(int c); |
− | int | + | int |
− | main(int argc, char *argv[]) | + | main(int argc, char *argv[]) |
− | { | + | { |
printf("%d\n", foo(*argv[1])); | printf("%d\n", foo(*argv[1])); | ||
exit(0); | exit(0); | ||
− | } | + | } |
− | % cc -o bar bar.c libfoo.a | + | % cc -o bar bar.c libfoo.a |
libfoo.a(foo.o)(.text+0xa): In function `foo': | libfoo.a(foo.o)(.text+0xa): In function `foo': | ||
: undefined reference to `__ctype_b' | : undefined reference to `__ctype_b' | ||
collect2: ld returned 1 exit status | collect2: ld returned 1 exit status | ||
Of course, libfoo.a is rebuilt on libc6 2.3.1, there are no problem. | Of course, libfoo.a is rebuilt on libc6 2.3.1, there are no problem. |
Latest revision as of 01:42, 8 November 2010
Random low-level stuff somewhat related to gcc.
Wrapping a class (needed to compile Darwin2k on a 2010 kernel)
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 #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 #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.