Templete Function called from shared object file(DLL)

Discussion in 'C++' started by Haro Panosyan, Apr 8, 2005.

  1. Suppose I have defined a templete function prototype in a header
    file and the body in .cpp file and created executable without actually
    calling the templete function.

    Now let say from that executable I am loading a shared object and
    executing(dlsym-ing) some f() function, which inside calls the templete
    function.
    (Of course the header file with templete prototype is included in
    shared object source file, so it could be compiled.)

    If I run the executable then I am getting an error:

    "referenced symbol not found"

    which is exactly what I am expecting, because there was no actual
    call of the templete function in the executable, hence no such
    function code was generated by a compiler.

    My question is it possible to make this work?
    To me it is not possible, but who knows, may be there are some compile
    options specificly designed for this case, something like to tell
    dynamic linker to create a function code during runtime.
    Sounds to hard to be true :), or I am lost.

    Thanks,
    -haro
    Haro Panosyan, Apr 8, 2005
    #1
    1. Advertising

  2. Haro Panosyan wrote:
    > Suppose I have defined a templete function prototype in a header
    > file and the body in .cpp file and created executable without actually
    > calling the templete function.


    Then there is no function.

    > Now let say from that executable I am loading a shared object and
    > executing(dlsym-ing) some f() function, which inside calls the
    > templete function.


    It can't call the template. I can only call a specialization of that
    template.

    > (Of course the header file with templete prototype is included in
    > shared object source file, so it could be compiled.)
    >
    > If I run the executable then I am getting an error:
    >
    > "referenced symbol not found"


    Of course. Since the body of the function wasn't available to the
    compiler, it didn't know what that function looks like. So it decided
    that the function will be provided externally, at the link time. It,
    of course, wasn't provided, since it was never instantiated.

    > which is exactly what I am expecting, because there was no actual
    > call of the templete function in the executable, hence no such
    > function code was generated by a compiler.


    Right.

    > My question is it possible to make this work?


    You need to cause the compiler to instantiate that function. You can
    use "explicit instantiation" (look it up).

    > To me it is not possible, but who knows, may be there are some compile
    > options specificly designed for this case, something like to tell
    > dynamic linker to create a function code during runtime.
    > Sounds to hard to be true :), or I am lost.


    Get a good book on templates.

    V
    Victor Bazarov, Apr 9, 2005
    #2
    1. Advertising

  3. Thanks Victor.

    "explicit instantiation" is what I was missing.

    -haro

    Victor Bazarov wrote:
    > Haro Panosyan wrote:
    >
    >>Suppose I have defined a templete function prototype in a header
    >>file and the body in .cpp file and created executable without actually
    >>calling the templete function.

    >
    >
    > Then there is no function.
    >
    >
    >>Now let say from that executable I am loading a shared object and
    >>executing(dlsym-ing) some f() function, which inside calls the
    >>templete function.

    >
    >
    > It can't call the template. I can only call a specialization of that
    > template.
    >
    >
    >>(Of course the header file with templete prototype is included in
    >>shared object source file, so it could be compiled.)
    >>
    >>If I run the executable then I am getting an error:
    >>
    >>"referenced symbol not found"

    >
    >
    > Of course. Since the body of the function wasn't available to the
    > compiler, it didn't know what that function looks like. So it decided
    > that the function will be provided externally, at the link time. It,
    > of course, wasn't provided, since it was never instantiated.
    >
    >
    >>which is exactly what I am expecting, because there was no actual
    >>call of the templete function in the executable, hence no such
    >>function code was generated by a compiler.

    >
    >
    > Right.
    >
    >
    >>My question is it possible to make this work?

    >
    >
    > You need to cause the compiler to instantiate that function. You can
    > use "explicit instantiation" (look it up).
    >
    >
    >>To me it is not possible, but who knows, may be there are some compile
    >>options specificly designed for this case, something like to tell
    >>dynamic linker to create a function code during runtime.
    >>Sounds to hard to be true :), or I am lost.

    >
    >
    > Get a good book on templates.
    >
    > V
    >
    >
    Haro Panosyan, Apr 11, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?YmFzdWxhc3o=?=

    How can I add an event to a control in a templete column?

    =?Utf-8?B?YmFzdWxhc3o=?=, Jul 29, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    357
    =?Utf-8?B?YmFzdWxhc3o=?=
    Jul 29, 2005
  2. =?Utf-8?B?YmFzdWxhc3o=?=

    Getting value from a control in header templete?

    =?Utf-8?B?YmFzdWxhc3o=?=, Jul 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    355
    Scott Allen
    Jul 29, 2005
  3. MDB

    Datagrid Templete Value

    MDB, Mar 22, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    432
  4. Douglass Turner
    Replies:
    2
    Views:
    2,012
    Manfred Bartz
    Sep 4, 2003
  5. Felix
    Replies:
    1
    Views:
    328
    Felix
    Sep 29, 2006
Loading...

Share This Page