Re: How to declare functions in so to be accessable to applications

From: Måns Rullgård (mru_at_kth.se)
Date: 02/25/04


Date: Wed, 25 Feb 2004 18:10:42 +0100

Fletcher Glenn <fletcher@removethisfoglight.com> writes:

> Micha wrote:
>> Hi there!
>> I finally compiled my code (with CC on a SPARC4/Solaris8) and got my
>> libugs.so
>> I used this command line to compile:
>> CC -KPIC -G $(INCS) ugs.o ugsMain.o ugsWrapper.o -o libugs.so
>> But the application tells my, that it didn't find the entry point
>> "ugsInit", which is a function delcared as extern in ugsWrapper.h and
>> implemented in ugsWrapper.cpp.
>> Do I have to use an other compile command option?
>> Do I have to set a flag or a macro in the code?
>> Is there a special syntax to use?
>> thx, Micha
>
> Your header file that the application uses, must declare the function
> prototype normally, not as an extern. The symbol will then be satisfied
> at ld time when you include your library. When you declare it extern,
> you are just confusing the linker.

Wrong. Both the header and the source should declare the function as
"extern". Since there is C++ involved, I'd start looking for name
mangling issues.

-- 
Måns Rullgård
mru@kth.se


Relevant Pages

  • Re: confused about extern use
    ... going to achieve by declaring it as extern in the header file a.h. ... composed on one or more compilation units. ... Essentially you *declare* the type wherever it is ...
    (comp.lang.c)
  • Re: keyword extern
    ... > declared multiple times using extern in all the files file2.c ... NEVER, ever, define a variable in a header file. ... declare it with the "extern" qualifier in the header file for the ... misuse. ...
    (comp.lang.c)
  • Re: Exported function mangaled name
    ... with many DLLs and supporting this for Windows 32 bit ... that header file; ... You have to declare the function the same way in your .cpp file as in ... extern "C" { ...
    (microsoft.public.vc.mfc)
  • Re: keyword extern
    ... my preferred way would be to declare it in all the .c files that ... > need the extern variable rather than put the extern declaration in the ... > header file and include the header file in the c files. ... A header is certainely not the place for an object definition for an ...
    (comp.lang.c)
  • Re: Exported function mangaled name
    ... that header file; it must be declared as __declspec ... You have to declare the function the same way in your .cpp file as in ... #define LIBSPEC __declspec ... See my essay on The Ultimate DLL Header File on my MVP Tips site. ...
    (microsoft.public.vc.mfc)