static libary problem

Started by
5 comments, last by Sneftel 16 years, 2 months ago
How can I stop people useing functions and varibles I don't want them to (eg those that I didn't put in the libary header file)? is there a keyword or something I need to use to stop them being used from outside the libary?
Advertisement
You can use tools such as strip to remove symbols you wish to remain unused from your object files.

For instance, strip -s -K foo -K bar -o sobjfile objfile should remove all symbols except foo and bar from objfile, and write the result to sobjfile.
Few problems I see with that:

1- I only have XP :(

2- If it strips the symbals from the object files before the linker makes the libary doesn't that stop my own functions accesssing those functions and varibles across diffrent source files? eg 3 or so of my files access a funstion in d3d_base.cpp but I don't want that function available outside the libary. (exspecialy since the name of it makes it quite likly someone will find it without even meaning too lol)
Quote:Original post by Sync Views
Few problems I see with that:

1- I only have XP :(


I believe installing Cygwin is the solution to that problem.
Quote:Original post by Quanta_StarFire
Quote:Original post by Sync Views
Few problems I see with that:

1- I only have XP :(


I believe installing Cygwin is the solution to that problem.

Not if he's not using GCC for compilation. (EDIT: huh, I may be wrong about that. Does Cygwin GCC output COFF?)

Sync Views, it really depends on what it is the functions and variables are in. It's unusual to ship OBJ files, so I'm going to assume that's not what you're trying to do. What are you releasing? Static library? Dynamic library? Application? Note that there is absolutely zero things you can do to deter a determined hacker from using the executable code that's been provided, protection or no protection.

EDIT: Heh, just read the subject line. For static libraries, there's little you can do without obfuscating the source code, because the object files the library contains are not yet linked to each other; stripping the symbols will prevent them from being able to do so. Building a DLL, in contrast, allows you to specify exactly which functions are available to be called, and you can choose not to include other symbols in the library. Of course, that merely makes it harder to do. Again, there's no way to do this 100%.

[Edited by - Sneftel on February 18, 2008 12:49:55 PM]
I'm releasing a static libary.

I just want to protect my varibles enough that people won't do stuff like "extern int align" and have problems because the linker links it with the align varible I'm useing for drawing text etc without them realising it did that.

Same goes for functions. Ones like "void input_update()" which just handel internal stuff so are completly useless to everything outside my libary but again have a name someone useing my libary might try to use.
Quote:Original post by Sync Views
I'm releasing a static libary.

I just want to protect my varibles enough that people won't do stuff like "extern int align" and have problems because the linker links it with the align varible I'm useing for drawing text etc without them realising it did that.

Same goes for functions. Ones like "void input_update()" which just handel internal stuff so are completly useless to everything outside my libary but again have a name someone useing my libary might try to use.

Ah, I see. Namespaces and static functions/variables* can help with that, as can simply using a unique prefix for all your global functions and variables. It's unlikely that the problem would be hidden, because the linker will complain about multiply defined symbols, but if you're worried then those techniques should be more than sufficient.

(*) Note that static, here, means something completely different than when you encounter it in a class definition. Thanks a lot, Bjarne.

This topic is closed to new replies.

Advertisement