Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: energy on May 24, 2010

Title: Problems with Static lib using VC2009
Post by: energy on May 24, 2010
Hi!
for me as non C++ Programmer, there is a small problem
with a static lib using vc2009.

I compiled the lib with VS2009 without precomiled header.
 
the Lib runs under Purebasic without problems,
but when i compile with MASM i get the following error:

LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
LibV2M.exe : fatal error LNK1120: 1 unresolved externals

I think its an project options problem.
 Anybody an idea???

Thanx in advance...
eNeRGy

Title: Re: Problems with Static lib using VC2009
Post by: Clyde on May 24, 2010
I hope my knowledge of C adventures can help you with this dude.
There is probably something else that the library uses for the entry point, usually in a win32 program you'd use:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//code in here.
}

if you go to the project settings in Linker - > Advanced, you should see Entry Point, in there needs to be what the library is using for it's main, for the tinptc lib it's crtMainStartup that needs to go in there.
Title: Re: Problems with Static lib using VC2009
Post by: Jim on May 24, 2010
The LIBCMT has code in it that looks like this

WinMainCrtStartup()
{
  ...
  main(argc, argv);
}

The linker will automatically arrange for WinMainCrtStartup to be the entry point for your app.  You can either override that in the linker, or you can have your asm code have an entry point that looks like
_main:
 ...
 ret

Jim
Title: Re: Problems with Static lib using VC2009
Post by: energy on May 24, 2010
Thanx Clyde,Jim for yur answers.  :cheers:

I know to work with main as entrypoint, thats running fine.

but how can i deactivate in VC9.0 static lib project that this entrypoint will be ignored and that i can use any entrypoint? 
Title: Re: Problems with Static lib using VC2009
Post by: energy on May 28, 2010
Tried to link the static lib now on another PC
with an MASM Program where no Visual Studio is installed.

Now linker requires the libcmt.lib !
Where hell i can deaktivate to use libcmt.lib for building
the static lib in Visual Studio???
 :'( :'(
 
Title: Re: Problems with Static lib using VC2009
Post by: Jim on May 28, 2010
In the linker options choose Ignore Default Libraries (I think the command line for this is /NODEFAULTLIB)

Then, as Clyde says:
if you go to the project settings in Linker - > Advanced, you should see Entry Point

Set it to
_main
I think the command line for this is /ENTRY:_main

Then make the entry point in your asm be
_main:

Jim

<edit> wrongly assumed you're trying to use libptc as well
Title: Re: Problems with Static lib using VC2009
Post by: energy on May 29, 2010
Jim:
Quote
Set it to
_main
I think the command line for this is /ENTRY:_main

Then make the entry point in your asm be
_main:

Thats running well.


Quote
In the linker options choose Ignore Default Libraries (I think the command line for this is /NODEFAULTLIB)

Then, as Clyde says:
if you go to the project settings in Linker - > Advanced, you should see Entry Point

I cant find Linkersettings in my Project. Addapted a Picture.
Perhaps in case of the project is a static lib?

Title: Re: Problems with Static lib using VC2009
Post by: Jim on May 29, 2010
You're right, for static libs it's:
Librarian (Bibliotekar)->General -> Ignore All Default Libraries

Jim
Title: Re: Problems with Static lib using VC2009
Post by: energy on May 29, 2010
linked with ignoring default lib,
no chance...
wants to have libcmt.lib with main  :'(
Title: Re: Problems with Static lib using VC2009
Post by: Jim on May 29, 2010
What's the error message?
Jim
Title: Re: Problems with Static lib using VC2009
Post by: energy on May 29, 2010
same as before:
Quote
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
LibV2M.exe : fatal error LNK1120: 1 unresolved externals

Title: Re: Problems with Static lib using VC2009
Post by: Rbz on May 30, 2010
Can you post your LIB file and masm test example for me to test?
Title: Re: Problems with Static lib using VC2009
Post by: energy on May 31, 2010
Rbz:
watch PM!   :-*
Title: Re: Problems with Static lib using VC2009
Post by: energy on June 06, 2010
Problem solved with help and a libcleaner tool
by Rbz.
Big thanks to him.... :-*