Re: Exporting Symbols From C++ Object File

From: Gregg (gregg_at_invalid.invalid)
Date: 09/23/04


Date: Thu, 23 Sep 2004 05:26:22 GMT

rolf21@indiatimes.com (chetan) wrote in news:4cb1a40c.0409222045.9e8b674
@posting.google.com:

> I am working on the project in c++ ,, I am in great confusion that
> should I export c++ member functions OR methods to create objects of
> that class OR
> previously cretaed objects .. So those can be used by users by using
> the header file ... of my " class "

It sounds like you want to put a class in a library that users can link
with. Is that correct?

Unlike C, there is no industry standard for storing C++ symbol
information in an object file (like "ELF") that is compatible with all
compilers. You will probably therefore have to use the same compiler for
both the library and the client code if you want to link symbolically.

The alternative that is commonly done is to export an extern "C" function
that is responsible for creating the object, which must have all virtual
functions. The client then invokes functions through an abstract
interface so it does not need to link symbolically. This is basically
what COM does in Windows.

> But by exporting member functions of C++ class user would not
> understand
> which are the private // public functions and would get compilation
> error ..!!!
> OR may simply change the header file from private to public and would
> use
> private functions ....!!!

The public/private stuff is not represented in the binary file because it
is only used at compile time, not run time. The client compiler will know
which is private and which is public from the header file. You are right
that the user could edit the header file, the access modes could be
chcanged. That is the case even without libraries. It is only a compile-
time mechanism.

Gregg



Relevant Pages

  • Re: Compiler and How It Handles Scope
    ... VB's compiler isn't really "state of the art" David. ... memory, no matter how many processes map the code into their virtual address ... words, no real distinction is made between Public/Private variables, or even ... > Modules can contain Public and Private variables, ...
    (microsoft.public.vb.winapi)
  • Re: Making function private/ not supplying declaration in header file
    ... I believe if the compiler can ... a variable) also serves as a declaration. ... > for all functions in a header file. ... > would be jolly useful for functions which can be thought of as private ...
    (comp.lang.c)
  • Re: header files
    ... As all code can be written in the header file ... > void foo() ... > compiler tries to compile main.c it eventually reaches the line ... > the compiler has never heared about a function called printf(). ...
    (alt.comp.lang.learn.c-cpp)
  • Re: include file question
    ... Where did you read that #pragma once is obsolete? ... because it suggests that what you need is some kind of weird compiler hack to make your ... inside the header file to prevent multiple execution of the contents. ... documentation about Objective C, which is a language which is NOT the C++ language, has ...
    (microsoft.public.vc.mfc)
  • Re: header files
    ... As all code can be written in the header file ... void foo() ... So when the compiler compiles ... the compiler has never heared about a function called printf(). ...
    (alt.comp.lang.learn.c-cpp)