Thread: Help Appreciated

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Help Appreciated

    Sorry about the vagueness of the thread title, I didn't want to scare anyone away...

    Ok, I started learning about Linking assembly routines into visual C++ programs via the Custom Build options.

    I think I've declared everything as I should, here's my main C++ source:

    Code:
    #include <iostream> 
    extern "C" _asm_main();
     
    int main (int argc, char* argv[])
    {
    	_asm_main();
    	return 0;
    }
    Now the .asm file, with the declaration of _asm_main:

    Code:
    .386
    .model flat, C
    .code 
     
    _asm_main PROC
    	mov eax, 10
    	ret
    _asm_main ENDP
     
    END
    I'm assembling with TASM 5.0, using the Custom Build command 'C:\TASM\BIN\TASM.EXE $(InputPath)' and output 'extproc.obj' (the assembly file is called extproc.asm).

    I get the infamous LNK1120 (unresolved externals). Here's the complete output, for the record:

    Code:
     
    --------------------Configuration: atest - Win32 Debug--------------------
    Performing Custom Build Step on .\extproc.asm
    Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International
    Assembling file: .\extproc.asm to extproc.OBJ
    Error messages:	None
    Warning messages: None
    Passes:			1
    Remaining memory: 411k
    Linking...
    .\extproc.obj : warning LNK4033: converting object format from OMF to COFF
    main.obj : error LNK2001: unresolved external symbol __asm_main
    Debug/atest.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    atest.exe - 3 error(s), 2 warning(s)
    Help greatly appreciated
    Last edited by cboard_member; 08-01-2005 at 12:16 PM.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >__asm_main
    Well it looks like it's adding a _ to the beginning of the name, so maybe change:
    _asm_main();
    to:
    asm_main();

    Or you could change the asm from:
    _asm_main PROC
    to:
    __asm_main PROC

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Hmm nope I get the same problem.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Hmm nope I get the same problem.
    Same exact error?

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Code:
     
    
    --------------------Configuration: atest - Win32 Debug--------------------
    Linking...
    .\extproc.obj : warning LNK4033: converting object format from OMF to COFF
    main.obj : error LNK2001: unresolved external symbol __asm_main
    Debug/atest.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    
    atest.exe - 2 error(s), 1 warning(s)
    Yeah, pretty much, except the unresolved external symbol is now __asm_main.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  6. #6
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Sneaky suspicion...is that ASM file a part of your project/workspace?

  7. #7
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Yes.

    Isn't vae victus something to do with Caeser?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Your C code needs one less underscore at the start than your equivalent ASM function.

    extern "C" _asm_main();
    unresolved external symbol __asm_main

    > .model flat, C
    Or maybe because you've said it's 'C' here as well, then you should make them both the same.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Nope that made no difference. I've noticed there's a shortage of online material on this subject, it's quite annoying.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  10. #10
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317
    A quick google search and I came up with this website that addresses your problem I think?

    http://www.cs.uakron.edu/~margush/30...Cplusplus.html
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    That's an excellent link.

    >I chose to reassemble with the /Mx option.
    It looks like that might do it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  2. Program Control, HELP appreciated.
    By Astra in forum Windows Programming
    Replies: 7
    Last Post: 01-01-2007, 06:59 AM
  3. Simple question. Help will be appreciated.
    By wickedclownz in forum C++ Programming
    Replies: 2
    Last Post: 06-19-2003, 02:18 AM
  4. C++ Programs -- Any input appreciated
    By Kyoto Oshiro in forum Game Programming
    Replies: 0
    Last Post: 02-27-2002, 11:22 PM
  5. I need help..anything will be appreciated
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2001, 10:55 AM