NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: bohunter11 on August 07, 2010, 10:31:23 PM

Title: EXTERN var
Post by: bohunter11 on August 07, 2010, 10:31:23 PM
I'm not able to get my program to link using EXTERN var.

EXTERN p

...
mov edx, [p]
...

unresolved external p

p == defined in my cpp file.

This is a single program.

Thank You
Bo Hunter
Title: Re: EXTERN var
Post by: bohunter11 on August 07, 2010, 11:06:44 PM
Well, I was able to get it to link. I don't understand though.
in the asm

EXTERN _p

...
mov edx, [_p]
...

in the cpp file

extern "C" char* p;

and it linked.


Thank You
Bo Hunter
Title: Re: EXTERN var
Post by: Frank Kotler on August 07, 2010, 11:12:55 PM
You don't mention what tools other than Nasm are involved (calling this stuff "portable" or "standardized" is... optimistic). Gnu C(++ ?) uses just "p", most other systems use "_p", Watcom uses "p_", I believe. You can alter your source to suit, but Nasm provides a feature which will allow you to assemble one source file for multiple Cs. You probably want, on the command line to Nasm, "--prefix _" for your case ("--postfix _" for Watcom tools).

The "++" introduces another complexity. C++ "decorates" (mutilates) external names to indicate "type" (how many parameters, etc.). This too varies from toolset to toolset. I believe the way to get around this is to add "C" (with the quotes, I think) where you define "p" in your .cpp file.

Hope this helps - I'm not very experienced with C, and less so with C++.

Best,
Frank

P.S. I see you figured this out... good!