Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem defining extern variable

Status
Not open for further replies.

aryajur

Programmer
Jul 2, 2003
45
0
0
US
Hello,
I am using an Assembly module to link with a Visual C++ program. I have defined a variable in the CPP file in the global scope as

extern "C" int i;

and then I am using this _i variable in my assembly file. But when I build the project I get the following error message:

Compiling...
callCVarInAssem.cpp
Linking...
callCVarInAssem.obj : error LNK2001: unresolved external symbol _i
CVarInAssem.obj : error LNK2001: unresolved external symbol _i
Debug/Cmixassembly.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Cmixassembly.exe - 3 error(s), 0 warning(s)

BUT if I declare the variable i as follows:

extern "C" { int i; }

It works perfect !!! Whats the problem?? Why r the curly brackets so important, please any help would be appreciated.
 
The syntax without brackets works for variables defined in Assembly. It also works for functions whether the functions are present in CPP file or in the Assembly file it doesn't matter. Any help would be appreciated.
 
When you compile your asm you should get a .obj file. You shouls link with that .obj file.

Ion Filipski
1c.bmp
 
Well thats what I am doing and so am able to run the code ! But my question was why the syntax of the '{}' in C++ creating the problem. What are the proper syntax of defining external variables and referencing external variables ??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top