Sign in to follow this  
sfx81

c++ static libs

Recommended Posts

Hi All.
I was going though tutorial for shared lib (static) at msdn "Creating and Using a Static Library (C++)". ([url="http://msdn.microsoft.com/en-us/library/ms235627%28v=vs.90%29.aspx"]http://msdn.microsof...v=vs.90%29.aspx[/url])
Question is how can it protect the code, as when I have to link my .lib to .exe, I have to include the [b]headers [/b]for classes to be used by separate .exe and also I can trace into .lib file and see the code.
I am bit confused by "code protection".

Will appreciate any help.
Thanks.
Kaz

Share this post


Link to post
Share on other sites
What do you mean by "protect the code" / "code protection"? what is your goal - to write a library you will distribute to third parties?

Client code needs an interface to work with, this interface is your header files. All libraries need to expose their header files. Typically, all the hard work should be done in your source files, so releasing the headers isn't too much of a problem.

Share this post


Link to post
Share on other sites
It should also be noted that shared libraries and static libraries are two different things. Shared libraries are dynamically (and explicitly) linked in code, where-as static libraries are linked at compile time. Shared libraries have the extensions .DLL(Windows) and .so(Linux). Static libraries have the extensions .lib (Windows) and .a (Linux).

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1318331093' post='4871409']
What do you mean by "protect the code" / "code protection"? what is your goal - to write a library you will distribute to third parties?

Client code needs an interface to work with, this interface is your header files. All libraries need to expose their header files. Typically, all the hard work should be done in your source files, so releasing the headers isn't too much of a problem.
[/quote]

Hi, Yes the goal is to distribute it to third parties.
If I provide the interface headers, I can still trace into headers and implementation files of .lib.
e.g I have a st.lib with class MyClass.h / MyClass.cpp, with methods MyClass.DoThis(), MyClass.GetSomeThing(). Compiled and built
In test.exe, I have included the st.lib, and added header MyClass.h.
now test.exe runs fine, but I can still see implmentation of MyClass.DoThis() and MyClass.GetSomething().
Am I supposed to see that ?

Thanks.

Share this post


Link to post
Share on other sites
[quote name='sfx81' timestamp='1318403362' post='4871761']
[quote name='rip-off' timestamp='1318331093' post='4871409']
What do you mean by "protect the code" / "code protection"? what is your goal - to write a library you will distribute to third parties?

Client code needs an interface to work with, this interface is your header files. All libraries need to expose their header files. Typically, all the hard work should be done in your source files, so releasing the headers isn't too much of a problem.
[/quote]

Hi, Yes the goal is to distribute it to third parties.
If I provide the interface headers, I can still trace into headers and implementation files of .lib.
e.g I have a st.lib with class MyClass.h / MyClass.cpp, with methods MyClass.DoThis(), MyClass.GetSomeThing(). Compiled and built
In test.exe, I have included the st.lib, and added header MyClass.h.
now test.exe runs fine, but I can still see implmentation of MyClass.DoThis() and MyClass.GetSomething().
Am I supposed to see that ?

Thanks.
[/quote]

You should only be able to see the implementation if it in the header file. The lib should be compiled code. Do you have methods implemented in your header file?

Share this post


Link to post
Share on other sites
[quote name='AverageMidget' timestamp='1318404023' post='4871762']
[quote name='sfx81' timestamp='1318403362' post='4871761']
[quote name='rip-off' timestamp='1318331093' post='4871409']
What do you mean by "protect the code" / "code protection"? what is your goal - to write a library you will distribute to third parties?

Client code needs an interface to work with, this interface is your header files. All libraries need to expose their header files. Typically, all the hard work should be done in your source files, so releasing the headers isn't too much of a problem.
[/quote]

Hi, Yes the goal is to distribute it to third parties.
If I provide the interface headers, I can still trace into headers and implementation files of .lib.
e.g I have a st.lib with class MyClass.h / MyClass.cpp, with methods MyClass.DoThis(), MyClass.GetSomeThing(). Compiled and built
In test.exe, I have included the st.lib, and added header MyClass.h.
now test.exe runs fine, but I can still see implmentation of MyClass.DoThis() and MyClass.GetSomething().
Am I supposed to see that ?

Thanks.
[/quote]

You should only be able to see the implementation if it in the header file. The lib should be compiled code. Do you have methods implemented in your header file?
[/quote]

I have Declaration in MyClass.h, implementation in MyClass.cpp

Share this post


Link to post
Share on other sites
[quote name='jonbonazza' timestamp='1318356519' post='4871521']
[color=#1C2837][size=4]...but I can still see implmentation of MyClass.DoThis() and MyClass.GetSomething().
Am I supposed to see that ?[/size][/color]
[/quote]

When you say you can see the implementation of your methods, is that using the debugger on a debug build ?
Also, if you are going to distribute a static library make sure you have versions compiled for different settings (debug/release multithread and single thread).

Share this post


Link to post
Share on other sites
If you only distribute myclass.h and myclass.lib to someone else, they clearly won't be able to view the implementation in myclass.cpp because they don't have that file. All they will get is disassembly.

It's finding it on your PC because of the debug information in myclass.pdb which tells the debugger where to find myclass.cpp on your hard drive.

Having said that even with just the disassembly to look at an experienced programmer could reverse engineer the code. You probably want to make sure you have legal protection when you sell it (i.e. some sort of legally binding contract with the purchaser).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this