class library in c++

E

EventHelix.com

In general, a class library would consist of several header files and
the associated source files.
 
P

pooja

thanks.
Tell me one more thing , that how can I hide my header files and other
source file in a class library, so that my client would not be able to
open it and can not tamper the classes with in it.
 
E

EventHelix.com

Search Google for "c++ code obfuscator".

For source files, you could just ship the object files.
 
E

E. Robert Tisdale

pooja said:
Tell me one more thing,
"How can I hide my header files and other source file in a class library
so that my client would not be able to open it
and can not tamper the classes with in it?"

You can't.
You *must* distribute the header files
which define the public interface for the library.
Developers who distribute proprietary libraries
distribute object files in library archives
and *not* the source files which define the implementation.
You can do this too if you can compile your library
for every target platform.
 
P

pooja

how can I distribute the header files
which define the public interface for the library.?
how does Developers distribute proprietary libraries
distribute object files in library archives
and *not* the source files which define the implementation.
Tell me the code snippet for it.
also teel me the site from where i can get the information
 
J

John Harrison

pooja said:
how can I distribute the header files
which define the public interface for the library.?
how does Developers distribute proprietary libraries
distribute object files in library archives
and *not* the source files which define the implementation.

That depends on your toolset. For instance on Unix you might use the
'ar' command. With Microsoft VC++ you might use the 'lib' command.

Tell me the code snippet for it.
also teel me the site from where i can get the information

There is no code snippet. You just write the code as normal, make a
library from it. Then send the library and the header files to whoever
wants to use the library.

You get the information by reading the documentation that comes with
your compiler and other tools.

john
 
P

pooja

Can we develop library files and header files in a way so that it can
not be tampered by the programmers by using Turbo C and Borland C
compiler?
 
K

Kai-Uwe Bux

pooja said:
Can we develop library files and header files in a way so that it can
not be tampered by the programmers by using Turbo C and Borland C
compiler?

The library file is compiled already. Without access to the sources, your
customers will not be inclined to change. (The obvious path of changing a
library file is to recompile the source. This path is blocked if your keep
the source. Non-obvious paths of changing the binary exist, but the few who
can do that, you cannot stop.)

As for the headers, your customers would not use the compiler to "tamper"
with the header. They would just use their favorite text editor and change
it. More likely, however, they would create a different version and then
include their file rather than yours. Nothing forces a user to tell the
compiler about your header just because he intends to tell the linker about
your library. The compiler has no premonitions, it simply does not know
about the linker.

Also, why would that be of your concern? Keep in mind that, since their
version still would have to match the library file, they cannot really
depart very much. However, they could put certain identifiers into a
different namespace. Actually, your customers might have a very legitimate
reason for doing exactly that: it could be the only way to avoid conflicts
arising from the use of several libraries.


Best

Kai-Uwe Bux
 
P

pooja

Ok thanks , but still some confussion is there

suppose I have created a file "abcd.h" like this
//abcd.h
#inlcude<iostream.h>
class c1
{
public:
void sum()
{
cout<<"I am sum function";
}
};

now I created another file "file1.cpp" , in which I included this
"abcd.h" file.
//file1.cpp
#include"abcd.h"
void main()
{
c1 obj;
obj.sum();
}

I want that my customer would also use "abcd.h" header file as I am
using it in the above file1.cpp.


Tell me how should I distribute "abcd.h" to my programmer using TC as a
compiler.
Can I Simply copy it on a CD and hand it to the customer or so some
other steps are there?
 
K

Karl Heinz Buchegger

pooja said:
Ok thanks , but still some confussion is there

suppose I have created a file "abcd.h" like this
//abcd.h
#inlcude<iostream.h>
class c1
{
public:
void sum()
{
cout<<"I am sum function";
}
};

now I created another file "file1.cpp" , in which I included this
"abcd.h" file.
//file1.cpp
#include"abcd.h"
void main()
{
c1 obj;
obj.sum();
}

I want that my customer would also use "abcd.h" header file as I am
using it in the above file1.cpp.

Tell me how should I distribute "abcd.h" to my programmer using TC as a
compiler.
Can I Simply copy it on a CD and hand it to the customer or so some
other steps are there?

In this case: copy it to the CD and you are fine.
 
P

pooja

"In this case: copy it to the CD and you are fine. "
and what would be the other case?

How to create a header file and packaged it , so that my customer would
not be able to the see the functions and their implementation?
 
K

Karl Heinz Buchegger

pooja said:
"In this case: copy it to the CD and you are fine. "
and what would be the other case?

The other case would be to have no function implementations
in the header file :)
How to create a header file and packaged it , so that my customer would
not be able to the see the functions and their implementation?

Your case was:

#inlcude<iostream.h>
class c1
{
public:
void sum()
{
cout<<"I am sum function";
}
};

and you want to ship that to your customer.
But this is not the likaly case. You may have some functions the user can see, but
this is not the usual case.
The much more usual case would be this:

abcd.h
******

#ifndef ABCD_H_
#define ABCD_H_

class c1
{
public:
void sum();
};

#endif

abcd.cpp
********

#include <iostream>
#include <abcd.h>

void c1::sum()
{
std::cout << "I am sum function";
}


Now you compiler abcd.cpp with the compiler of your choice (and most always
needs to be the same compiler your customer uses). If there are more then 1
cpp files, you will want to collect all those object files (the results of
all the individual compiler runs) into a library. You then ship to your customer:
* the header file he needs (abcd.h in the above example)
* the object file (or the library)

Now you customer writes:

#include "abcd.h" // that is why he needs to have the header file
int main()
{
c1 obj;
obj.sum();
}

and links it with the object file (or the library) you provide.

Things to note:
* You have to supply the header file, because your customer needs it
* Whatever you write in the header file is visible to your customer. Thus
you may want to reduce this to a minimum. This is eg. why I moved the implementation
from abcd.h into another file which gets compiled and shipped in its compiled form.
* Depending on your platform and/or compiler you might be forced to compile the library
for different platforms/compilers and ship a customized version to your customer.
 
P

pooja

Thank you so much. I am really thank full to you for solving my problem
so nicely and so beautifully.
 
P

pooja

Thanks for clearing my doubts.
But there is a problem , that when I execute this code, at run time the
compiler shows an error message " undefined symbol c1::sum() in module
file1.cpp."

I have copied abcd.obj, abcd.h and file1.cpp(in which I have written
thye main()) in TCTEMP folder, and in this folder all other necessary
libraries, header files are present.
So why it is showing this error message?
How to solve this problem.
 
K

Karl Heinz Buchegger

pooja said:
Thanks for clearing my doubts.
But there is a problem , that when I execute this code, at run time the
compiler shows an error message " undefined symbol c1::sum() in module
file1.cpp."

Is it really a compiler error message? Looks more like a linker error
message to me.
I have copied abcd.obj, abcd.h and file1.cpp(in which I have written
thye main()) in TCTEMP folder, and in this folder all other necessary
libraries, header files are present.
So why it is showing this error message?

Did you tell your linker that it should include abcd.obj when it builds
the executable?
How to solve this problem.

Depends on your actual compiler/linker system what you need to do in order
to specify what needs to be linked to form the final executable.
 
P

pooja

I am using Turbo C compiler ,tell me how to link these obj files at
runtime. In UNIX I am able to do this. but in TC I don't know how to do
it. Tell me the how should I do.
 
K

Karl Heinz Buchegger

pooja said:
I am using Turbo C compiler ,tell me how to link these obj files at
runtime. In UNIX I am able to do this. but in TC I don't know how to do
it. Tell me the how should I do.

Sorry. I can't, since I don't know Turbo C.
But I am pretty sure that somewhere there is a newsgroup dealing
with that particular compiler.

(Did you read the documentation that came with your compiler?
Are there same example projects included with your compiler? Sometimes
studying examples sheds a lot of light on things.)
 
P

pooja

ok no problem . thanks any way for showing your kind attention towards
this topic , and clearing my doubts.
 
J

Jimmy Rose

pooja said:
I am using Turbo C compiler ,tell me how to link these obj files at
runtime. In UNIX I am able to do this. but in TC I don't know how to do
it. Tell me the how should I do.


From the project menu, choose "Add Item", then just double click on the .obj
file. You may have to edit the default dialog box to show all files in the
directory. (change *.prj to *.*, or whatever)

It will then link automatically when you compile.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top