Question

Trying to understand how to link a function that is defined in a struct, the function is in the assembly code, and am trying to call it from c. I think am missing a step cause when I call the function, I get an unresolved external symbol...

;Assembly.asm
.686p
.mmx
.xmm
.model flat

include Definitions.inc

.code

?Initialize@Foo@@SIXPAUFee@@@Z proc
    jmp $
?Initialize@Foo@@SIXPAUFee@@@Z endp

end



//CFile.c
struct Fee
{
   signed long id; 
}

struct Foo
{
   static void Initialize(Fee *);
}


int startup(Fee * init)
{
  Foo::Initialize(init); //<-- This is unresolved
  return 0;
}
Was it helpful?

Solution

Your assembly code defines a function whose decorated name decodes to

public: static void __fastcall Foo::InitializeCurrentCpu(struct Fee *)

As obtained through the undname.exe utility. Foo::InitializeCurrentCpu() won't be a match for Foo::Initialize(), the name doesn't match. Nor does the calling convention.

Write this code in C++ first and look at the .map file for the correct decorated name. Or declare the function with extern "C" to suppress C++ decoration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top