From: Jacky Luk on
Hi, I have a project for a debugger which I want to recompile
***in file emu1_module1.asm, I have

PUBLIC main_IT
main_IT instr_properties <<0, 0, 0>, 0, 0> ;NN_null

***in file emu1.inc, I have

main_IT equ ?main_IT@@3PAUinstr_properties@@A

***in file winNT_x86_emulator.cpp, I have

extern instr_properties main_IT[];

and

int Main(HINSTANCE hInstance, DWORD reason, DWORD reserved)
{int instr_num, i;

if (reason == DLL_PROCESS_ATTACH)
{indexed_IT = (instr_properties*)LocalAlloc(LPTR, sizeof(instr_properties)
* NN_last);
instr_num = (sizeof(instructions_associate) / sizeof(sDEFAULT)) / 2;

for (i = 1; i < instr_num; i++)
{memcpy(&indexed_IT[instructions_associate[i * 2]],
&main_IT[instructions_associate[i * 2 + 1]],
sizeof(instr_properties));}}

return true;}


The result...
emu86 error LNK2001: unresolved external symbol "struct instr_properties *
main_IT" (?main_IT@@3PAUinstr_properties@@A)



Thanks for any hints
Jack




From: Jacky Luk on
Hi, seems like VC++ 6 cannot process assembly files. Does the VC++ compiler
set include any assembler(s)?
Thanks
Jack

"Jacky Luk" <jl(a)knight.com> ýýýgýýlýýsýD:OIafsUYcFHA.1404(a)TK2MSFTNGP09.phx.gbl...
> Hi, I have a project for a debugger which I want to recompile
> ***in file emu1_module1.asm, I have
>
> PUBLIC main_IT
> main_IT instr_properties <<0, 0, 0>, 0, 0> ;NN_null
>
> ***in file emu1.inc, I have
>
> main_IT equ ?main_IT@@3PAUinstr_properties@@A
>
> ***in file winNT_x86_emulator.cpp, I have
>
> extern instr_properties main_IT[];
>
> and
>
> int Main(HINSTANCE hInstance, DWORD reason, DWORD reserved)
> {int instr_num, i;
>
> if (reason == DLL_PROCESS_ATTACH)
> {indexed_IT = (instr_properties*)LocalAlloc(LPTR,
> sizeof(instr_properties) * NN_last);
> instr_num = (sizeof(instructions_associate) / sizeof(sDEFAULT)) / 2;
>
> for (i = 1; i < instr_num; i++)
> {memcpy(&indexed_IT[instructions_associate[i * 2]],
> &main_IT[instructions_associate[i * 2 + 1]],
> sizeof(instr_properties));}}
>
> return true;}
>
>
> The result...
> emu86 error LNK2001: unresolved external symbol "struct instr_properties *
> main_IT" (?main_IT@@3PAUinstr_properties@@A)
>
>
>
> Thanks for any hints
> Jack
>
>
>
>


From: Victor Bazarov on
Jacky Luk wrote:
> Hi, I have a project for a debugger which I want to recompile
> ***in file emu1_module1.asm, I have
>
> PUBLIC main_IT
> main_IT instr_properties <<0, 0, 0>, 0, 0> ;NN_null

Is this a declaration? My MASM is rather rusty... Is this supposed to
make 'main_IT' external? If so, the name of the symbol is "main_IT",
literally. You should consider making it '_main_IT' (notice the leading
underscore).

> ***in file emu1.inc, I have
>
> main_IT equ ?main_IT@@3PAUinstr_properties@@A

This is a definition of 'main_IT' and its initialisation to an address,
IIRC. You should probably again consider renaming it to '_main_IT'.

> ***in file winNT_x86_emulator.cpp, I have
>
> extern instr_properties main_IT[];

This is a declaration of 'main_IT'. Since you didn't give it "C" linkage,
the compiler will try to stuff all the type information into that, and you
get a mangled name (probably the one that the linker flags as unresolved,
'?main_IT@@3PAUinstr_properties@@A'). You should do

extern "C" instr_properties *main_IT;

here. This will generate '_main_IT' name to be resolved.

>
> and
>
> int Main(HINSTANCE hInstance, DWORD reason, DWORD reserved)
> {int instr_num, i;
>
> if (reason == DLL_PROCESS_ATTACH)
> {indexed_IT = (instr_properties*)LocalAlloc(LPTR, sizeof(instr_properties)
> * NN_last);
> instr_num = (sizeof(instructions_associate) / sizeof(sDEFAULT)) / 2;
>
> for (i = 1; i < instr_num; i++)
> {memcpy(&indexed_IT[instructions_associate[i * 2]],
> &main_IT[instructions_associate[i * 2 + 1]],
> sizeof(instr_properties));}}
>
> return true;}
>
>
> The result...
> emu86 error LNK2001: unresolved external symbol "struct instr_properties *
> main_IT" (?main_IT@@3PAUinstr_properties@@A)

See my recommendations above.

V
From: Carl Daniel [VC++ MVP] on
Jacky Luk wrote:
> Hi, I have a project for a debugger which I want to recompile
> ***in file emu1_module1.asm, I have
>
> PUBLIC main_IT
> main_IT instr_properties <<0, 0, 0>, 0, 0> ;NN_null
>
> ***in file emu1.inc, I have
>
> main_IT equ ?main_IT@@3PAUinstr_properties@@A
>
> ***in file winNT_x86_emulator.cpp, I have
>
> extern instr_properties main_IT[];
>
> and
>
> int Main(HINSTANCE hInstance, DWORD reason, DWORD reserved)
> {int instr_num, i;
>
> if (reason == DLL_PROCESS_ATTACH)
> {indexed_IT = (instr_properties*)LocalAlloc(LPTR,
> sizeof(instr_properties) * NN_last);
> instr_num = (sizeof(instructions_associate) / sizeof(sDEFAULT)) / 2;
>
> for (i = 1; i < instr_num; i++)
> {memcpy(&indexed_IT[instructions_associate[i * 2]],
> &main_IT[instructions_associate[i * 2 + 1]],
> sizeof(instr_properties));}}
>
> return true;}
>
>
> The result...
> emu86 error LNK2001: unresolved external symbol "struct
> instr_properties * main_IT" (?main_IT@@3PAUinstr_properties@@A)

The error is telling you plainly what's wrong: The compiler emitted a
reference to ?main_IT@@3PAUinstr_properties@@A while your assembly module
defined a public symbol named main_IT.

The use of the equ directive doesn't do anything like what you're trying to
do and is not helpful in this situation. Rather, what you need to do is
simple: Remove all mention of the mangaled C++ symbol from your .asm file,
and change your .cpp file to read

extern "C" instr_properties main_IT[];

-cd