Complation problem involving namespaces.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frederick Reeve

    Complation problem involving namespaces.

    Hey all I have a little compilation problem I think is related to name
    spaces but being new to C++ still I don't know the program
    (http://rafb.net/paste/results/f1416037.html) when it is being linked
    returns with "undefined reference to foo" for function in a C lib i have
    linked... any Ideas?

    I am attempting to link a C lib and I think the complication comes in here
    also.

    If it would be better I can post the program in another message. Its only
    153 lines. The program in the opening comments includes the command I use
    to compile this and the c version of it. The C version compiles fine by
    the way.

    Thanks for being there guys.

    --


    Want to email me? remove both dashes from the email address.


  • Ivan Vecerina

    #2
    Re: Complation problem involving namespaces.


    "Frederick Reeve" <fred-e-rick@woodland-i.org> wrote in message
    news:pan.2003.1 1.20.03.09.50.4 36285@woodland-i.org...
    | Hey all I have a little compilation problem I think is related to name
    | spaces but being new to C++ still I don't know the program
    | (http://rafb.net/paste/results/f1416037.html) when it is being linked
    | returns with "undefined reference to foo" for function in a C lib i have
    | linked... any Ideas?
    |
    | I am attempting to link a C lib and I think the complication comes in here
    | also.
    .....
    | The C version compiles fine by the way.

    To include C headers from a C++ program, you need to place them
    within an extern "C" block:
    extern "C" {
    #include <SomeCHeader. h>
    }
    This is because the C++ compiler uses name mangling (encoding the type
    of the parameters into the link name of a function) to allow function
    overloading. This mangling is disabled within the extern "C" block...


    Cheers,
    Ivan
    --
    Ivan Vecerina - expert in medical devices, software - info, links, contact information, code snippets



    Comment

    • Frederick Reeve

      #3
      Re: Complation problem involving namespaces.

      > To include C headers from a C++ program, you need to place them[color=blue]
      > within an extern "C" block:
      > extern "C" {
      > #include <SomeCHeader. h>
      > }
      > This is because the C++ compiler uses name mangling (encoding the type
      > of the parameters into the link name of a function) to allow function
      > overloading. This mangling is disabled within the extern "C" block...[/color]

      Thanks a lot Ivan That took care of the problem.

      Frederick.

      --


      Want to email me? remove both dashes from the email address.


      Comment

      Working...