MASM

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

MASM

Post 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();
}
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: MASM

Post 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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: MASM

Post 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 :)
simeonz
Member
Member
Posts: 360
Joined: Fri Aug 19, 2016 10:28 pm

Re: MASM

Post 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.
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: MASM

Post by Ycep »

How do you mean? :-s
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: MASM

Post by iansjack »

You sure you have included the object file in the list of files to be linked?
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: MASM

Post by Love4Boobies »

Be sure to add the underscore both to the procedure's name and to the public declaration.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
simeonz
Member
Member
Posts: 360
Joined: Fri Aug 19, 2016 10:28 pm

Re: MASM

Post 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
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: MASM

Post 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)
simeonz
Member
Member
Posts: 360
Joined: Fri Aug 19, 2016 10:28 pm

Re: MASM

Post 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.
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: MASM

Post 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... :( .
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: MASM

Post 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.
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: MASM

Post 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
Post Reply