Author Topic: NASM -f OBJ -f COFF problems  (Read 13156 times)

nobody

  • Guest
NASM -f OBJ -f COFF problems
« on: August 03, 2005, 10:24:10 PM »
I've been building asm code using the following command line to much success.

nasm -f OBJ someFile.asm

The resulting .o file is linked using ALINK.  The following command line is traditionally used.

alink -c -oPE -subsys gui someFile.o

The resulting .exe file works quite happilly.  If you aren't familiar with alink, the ?-c? enables case sensitivity, the ?-oPE? enables Windows Portable Executable output style, and ?-subsys gui? causes a win32 executable to be produced.

All has been good so far.  But lately i've been attempting to take ALINK out of the chain and use MS Visual Studio C++ 6.0 instead.

To keep VCPP happy, i have been using the following command line

nasm -f coff someFile.asm

which, for the most part, appears to work just fine.  except for one thing.  i can't get api functions to import correctly.  the syntax i've been using is

EXTERN MessageBoxA
IMPORT MessageBoxA User32.dll

This compiles fine under -fOBJ, but causes an error under COFF.  This is the error.

5: error: parser: instruction expected

I can take the import instruction out, and it compiles fine in nasm.  But C++ reports "Unresolved external MessageBoxA"

I'm not sure if this is a decoration issue, or a syntax issue with nasm.  Shouldn't I still use import under coff?  Why doesn't the parser like it?

nobody

  • Guest
Re: NASM -f OBJ -f COFF problems
« Reply #1 on: August 03, 2005, 10:26:20 PM »
If you prefer to see things in context, this is an example of a program that compiles under OBJ but not under COFF because of the imports.

http://www.geocities.com/kivinkujata/win32test.asm

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: NASM -f OBJ -f COFF problems
« Reply #2 on: August 03, 2005, 11:05:45 PM »
"-f coff" is for djgpp. For MS-coff, use "-f win32". (they're *almost* the same)

"import" is a format-specific directive, good only in "-f obj" format.

I don't think Alink is too good at MS-coff. Maybe try the linker that came with VC++? I think you'll also need to link against a library to have it work.

You might also look into the "-X" switch - added to put error messages in a form VS likes 'em.

Best,
Frank

nobody

  • Guest
Re: NASM -f OBJ -f COFF problems
« Reply #3 on: August 05, 2005, 03:18:32 AM »
Frank,

I intended to hop on and clarify... I've tried both forms of COFF, -f coff and -f win32, both give the same results...

If what you say is true, i guess it isn't suprising that "import" doesn't work outside of "obj" format.  The question at hand is, what replaces it? If anything?  If I'm getting unresolved externals, it's either got to be a lack of import or a decoration mismatch.

With MessageBoxA as an example, i've tried a number of solutions, all produce an unresolved external.  There's no linker errors at all (these were corrected by using either coff instead of obj)

I've tried the following

extern _MessageBoxA
extern MessageBoxA

NASM compiles a-ok, but VCpp chokes on it.