Author Topic: Problems with Static lib using VC2009  (Read 7245 times)

0 Members and 1 Guest are viewing this topic.

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Problems with Static lib using VC2009
« 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

« Last Edit: May 24, 2010 by energy »
coding: jwasm,masm
hobby: www.scd2003.de

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #1 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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #2 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
Challenge Trophies Won:

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #3 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? 
coding: jwasm,masm
hobby: www.scd2003.de

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #4 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???
 :'( :'(
 
coding: jwasm,masm
hobby: www.scd2003.de

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #5 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
« Last Edit: May 28, 2010 by Jim »
Challenge Trophies Won:

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #6 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?

coding: jwasm,masm
hobby: www.scd2003.de

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #7 on: May 29, 2010 »
You're right, for static libs it's:
Librarian (Bibliotekar)->General -> Ignore All Default Libraries

Jim
Challenge Trophies Won:

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #8 on: May 29, 2010 »
linked with ignoring default lib,
no chance...
wants to have libcmt.lib with main  :'(
coding: jwasm,masm
hobby: www.scd2003.de

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #9 on: May 29, 2010 »
What's the error message?
Jim
Challenge Trophies Won:

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #10 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

coding: jwasm,masm
hobby: www.scd2003.de

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Problems with Static lib using VC2009
« Reply #11 on: May 30, 2010 »
Can you post your LIB file and masm test example for me to test?
« Last Edit: May 30, 2010 by rbz »
Challenge Trophies Won:

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #12 on: May 31, 2010 »
Rbz:
watch PM!   :-*
coding: jwasm,masm
hobby: www.scd2003.de

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
Re: Problems with Static lib using VC2009
« Reply #13 on: June 06, 2010 »
Problem solved with help and a libcleaner tool
by Rbz.
Big thanks to him.... :-*
coding: jwasm,masm
hobby: www.scd2003.de