Hi,

I hope that someone here can help.

I have a simple MASM (Microsoft Assembler) program that tries to call _printf, but I can't get it to compile (actually link) successfully under MASM (the one that comes with VS 2008).

Here's the source:


PUBLIC  _main
EXTRN  _printf:PROC


.386
.MODEL FLAT


.DATA
message                db      'Hello, World', 10, 0


.CODE
_main PROC


        ; display test message string
        mov              eax, OFFSET message
        push            eax
        call    _printf
        add              esp, 4
_main ENDP
        END


This is what I'm getting when I try to assemble and link it:

[
/OUT:"C:\HelloWorld1\HelloWrd\Debug\HelloWrd.exe" /INCREMENTAL:NO /
MANIFEST /MANIFESTFILE:"Debug\HelloWrd.exe.intermediate.manifest" /
MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:
\HelloWorld1\HelloWrd\Debug\HelloWrd.pdb" /SUBSYSTEM:CONSOLE /
DYNAMICBASE:NO kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
odbc32.lib odbccp32.lib


".\Debug\HelloWorld.obj"
]
Creating command line "link.exe @c:\HelloWorld1\HelloWrd\Debug
\RSP0000B06722572.rsp /NOLOGO /ERRORREPORT:PROMPT"
Output Window      Assembling...
Assembling: .\HelloWorld.asm
Linking...
HelloWorld.obj : fatal error LNK1190: invalid fixup found, type 0x0002
Results      Build log was saved at "file://c:\HelloWorld1\HelloWrd
\Debug\BuildLog.htm"
HelloWrd - 1 error(s), 0 warning(s)

Can anyone tell why this is happening, and how to resolve this
problem?

I've been googling (and trying different things) for days, and can't find a clear explanation of what is causing that "LNK1190: invalid fixup found, type 0x0002" linker error.


Thanks,
Jim


Posted on 2009-05-10 14:54:20 by ohaya
Hi,

Although it's not exactly related, I found this:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101060&wa=wsignin1.0

When I run dumpbin on the obj, I get:


File Type: COFF OBJECT

RELOCATIONS #1
                                                Symbol    Symbol
Offset    Type              Applied To        Index    Name
--------  ----------------  -----------------  --------  ------
00000001  DIR32                      00000000        8  message
00000008  REL16                          0000        7  _printf

  Summary

          E .data
          6C .debug$S
          D .text


I don't fully understand the info in the link above (e.g., "if you look at the relocations you will see that this should really never been assembled..."), but maybe someone here does, and I'm hoping that dumpbin above may indicate why I get that LNK1190?

Thanks,
Jim
Posted on 2009-05-10 23:19:51 by ohaya
Hi,

I just found this:

http://www.microsoft.com/msj/0797/hood0797.aspx

which explains the Dumpbin output, and mentions "REL32", whereas my Dumpbin output has "REL16".

Could that be why I'm getting the link error, i.e., should the _printf be a REL32? 

If so, what do I have to do in the original .ASM source to get that to be like that?

Thanks,
Jim
Posted on 2009-05-10 23:27:31 by ohaya
this will work:
.686 
.MODEL FLAT, C
option casemap:none
printf proto c :vararg
getchar proto c

.DATA
message db 'Hello, World',13,10,0

.CODE
main PROC
invoke printf,OFFSET message
invoke getchar
ret
main ENDP
END


1. don't put any declarations before processor/model directives
2. be sure to specify default language
3. add msvcrt.lib or libcmt.lib to linker if its not already added

Posted on 2009-05-11 09:53:50 by drizz