From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,645f699f5b04c00d,start X-Google-Attributes: gidfc89c,public X-Google-Thread: fee84,645f699f5b04c00d,start X-Google-Attributes: gidfee84,public X-Google-Thread: 1014db,a99b50a866c87572 X-Google-Attributes: gid1014db,public From: joei@conan (Jonathan Oei) Subject: Re: Function Scope question Date: 1995/07/15 Message-ID: <3u7ncg$gb@paperboy.ids.net>#1/1 X-Deja-AN: 106179817 references: <3tugkj$o5r@paperboy.ids.net> organization: IDS World Network Internet Access Service, (800)IDS-1680 newsgroups: comp.lang.c,comp.unix.programmer,comp.unix.osf.osf1 David Claude Brown (brown@falam.ch) wrote: > In article <3tugkj$o5r@paperboy.ids.net> joei@conan (Jonathan Oei) writes: > [snip] > >The question is: How can I declare f4() so that it is only > >visible WITHIN THE LIBRARY, and that f3() and g2() are the > >only externally visible functions? > >I am trying this on a AlphaServer 2100 running digital UNIX 3.2 > >(used to be OSF/1), using the cc compiler. > There is no way to do this in vanilla C. However, you can do this using > various tricks of your local environment: > > Unix Lookup things about shared-libraries > So now I have re-phrased the question: I am creating a shared library for use by other programmers but only want them to be able to access certain routines. (Sounds like a job for static/extern, but wait a sec...) Example: l1.c: extern int Func1 (void) { return 1; } // public function static int Func2 (void) { return 2; } // file scope/private extern int Func3 (void) { return Func4() }; // public function l2.c: int Func4 (void) { return 4; } // public function so Func3 can see it // create mylib.so ld -shared -no_archive -rpath . -o libmylib.so l1.o l2.o -lc // main program l.c main() { Func3(); // returns 4 Func4(); // also returns 4, but I want a link error here!!! } cc -no_archive l.c -L. -lmylib -o l Is there any way that I can hide Func4() from the user but not from l1.c? In other words, I am looking for 'library scope.' I am using an Alpha 2100 running digital UNIX 3.2 Thanks