Page 1 of 1

MASM

Posted: Wed Oct 19, 2016 12:10 pm
by Ycep
And there it goes again... I have "unresolved external symbol" for my void PitIrq(void), which I have recently put into .ASM file...
pic.asm:

Code: Select all

PUBLIC PitIrq
EXTERNDEF ticks:NEAR
.586
.MODEL FLAT, C
.CODE
PitIrq PROC
	inc dword ptr[ticks]
	pusha
	mov al, 20h
	movzx dx, al
	out dx, al
	popa
	ret
PitIrq ENDP

END
And:

Code: Select all

extern "C"
{
	void PitIrq();
}

Re: MASM

Posted: Wed Oct 19, 2016 12:30 pm
by Love4Boobies
It's hard to guess without telling us what compiler or options you're using to compile or even the symbol's name (you only tells us where it comes from). Without that information, my guess is that you need to rename your function to _PitIrq inside the assembly file.

Re: MASM

Posted: Wed Oct 19, 2016 12:46 pm
by Ycep

Code: Select all

error LNK2019: unresolved external symbol _PitIrq referenced in function "bool __cdecl PitInit(void)" (?PitInit@@YA_NXZ)
I have tried putting underscore already.
When title is Macro Assembly, I thought it would be default to compiler to be Microsoft Visual Studio.

Through; Thanks for the reply :)

Re: MASM

Posted: Wed Oct 19, 2016 1:18 pm
by simeonz
Not sure what it could be, but you could try "dumpbin /SYMBOLS" on the assembled and compiled files and see if that gives any hints.

Re: MASM

Posted: Wed Oct 19, 2016 1:38 pm
by Ycep
How do you mean? :-s

Re: MASM

Posted: Wed Oct 19, 2016 2:19 pm
by iansjack
You sure you have included the object file in the list of files to be linked?

Re: MASM

Posted: Wed Oct 19, 2016 7:04 pm
by Love4Boobies
Be sure to add the underscore both to the procedure's name and to the public declaration.

Re: MASM

Posted: Wed Oct 19, 2016 7:53 pm
by simeonz
The following commands are successful:

Code: Select all

ml /c pic.asm
cl /c test.cpp
link /NODEFAULTLIB /ENTRY:test /SUBSYSTEM:NATIVE /OUT:test.sys test.obj pic.obj
The language model directive in the masm file ("C" in this case) should set the naming convention for the assembler symbols to underscore. This matches the naming convention for extern "C" and can be verified with dumpbin:

Code: Select all

dumpbin /symbols pic.obj
dumpbin /symbols test.obj
So either it is complaining for a different symbol, or indeed an object file is missing from the link line. My modified source files:

test.cpp:

Code: Select all

extern "C"
{
  void PitIrq();

  void test()
  {
    PitIrq();
  }
  
  void *ticks = 0;
}
pic.asm:

Code: Select all

PUBLIC PitIrq
.586
.MODEL FLAT, C
EXTERNDEF ticks:NEAR
.CODE
PitIrq PROC
   inc dword ptr[ticks]
   pusha
   mov al, 20h
   movzx dx, al
   out dx, al
   popa
   ret
PitIrq ENDP

END

Re: MASM

Posted: Thu Oct 20, 2016 5:26 am
by Ycep
iansjack wrote:You sure you have included the object file in the list of files to be linked?
Doesn't MSVC IDE does it automatically?
Love4Boobies wrote:Be sure to add the underscore both to the procedure's name and to the public declaration.
I have added underscores in the PUBLIC declaration as well.
@simeonz : :evil: What did I done to deserve this :-({|= ...

Maybe this could help:

Code: Select all

extern "C"
{
	void PitIrq();
}
bool PitInit()
{
	memset((uint*)ticks,0,4);
	setvect(0x20, PitIrq);
	PitCounter(40);
	return true;
}
Remember: "unreferenced _PitIrq() in PitInit()"
(Putting underscores in .ASM won't work)

Re: MASM

Posted: Thu Oct 20, 2016 8:24 am
by simeonz
May be your asm file does not participate in the build.
Apparently some VS targets (including masm) are disabled by default for new projects and have to be enabled on a per-project basis from Project->Build Customizations. Take a look here.

Re: MASM

Posted: Thu Oct 20, 2016 8:51 am
by Ycep
I already did it for my past .asm files...
Hmmm, this seems that only one thing is left to me;
Using inline assembly... :( .

Re: MASM

Posted: Thu Oct 20, 2016 9:03 am
by iansjack
Lukand wrote:
iansjack wrote:You sure you have included the object file in the list of files to be linked?
Doesn't MSVC IDE does it automatically?
I would hope that you know the toolset that you are using better than I do. It's always a mistake to assume rather than know.

Try the command-line commands given above; that should help to isolate whether the problem is which your IDE or your source files.

Also note that, in the latest source code you show, you are not calling PitIrq as a function.

Re: MASM

Posted: Thu Oct 20, 2016 12:25 pm
by Ycep
Damn it...
Do you know guys what was the problem in it?
I named them with same names (pic.asm and pic.cpp)
I renamed pic.asm to pit.asm and now it works. Woohoo!
:o