Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove main function from static library

Tags:

c++

windows

Much of my code depends on a proprietary Windows library in .lib format (static library). Lets call it prop.lib.

The library works such that I make a new shared library that links to prop.lib. I can then run my code through prop.exe (another program that loads my shared library and runs my code).

I want to create an executable that runs on it's own, but since prop.lib includes a main function, I get a linker error.

Is it somehow possible to remove the main function from the lib or create another entry point?

I use Visual Studio 2005.

EDIT: As of now I do not have the source code for prop.lib.

like image 840
sighol Avatar asked Oct 20 '22 15:10

sighol


1 Answers

You should realize that this is rather low level task.

  1. Work around: If you have acces to build configuration to your executable you can specify linker option /ENTRY in your executable build.

  2. Microsoft's editbin doesn't allow to perform such modification. So it seems that there is not exist official method to "hack" your *.obj files from Microsoft

  3. Try to view in object files in your static library with lib /list staticlib.lib If you're lucky and you have main.obj in separate object files,then just /remove that object file

  4. If 3 doesn't help try It yourself to write application to edit symbols in COFF files. https://msdn.microsoft.com/en-us/windows/hardware/gg463119.aspx

From start of the object file pass +8bytes, read 4 bytes. It will be offset to table with "18 bytes structures with names. (if all names are then 8 bytes long)". Edit needed names with padding residual "name" bytes with zeros. I never try to work with COFF. I can't find anything like COFF editor in the web.

like image 157
Konstantin Burlachenko Avatar answered Oct 23 '22 00:10

Konstantin Burlachenko