Mail Archives: djgpp/1999/09/18/05:31:18
On 17 Sep 99, Bart Trzynadlowski was found to have commented thusly:
> Hi,
> Ive been tearing my hair out trying to get extern to work in my
> DJGPP-compiled programs. What I want to do is have the program call an
> assembly subroutine. I declare it with extern but I can't even compile
> the program because it complains about an undefined reference. I read
> the FAQ and the docs but nothing described my situation. I will be using
> NASM externally to assemble the module I need into a .O file, but its
> not NASM thats involved, its GCC itself.
>
> Thanks,
>
> Bart Trzynadlowski
Keep in mind the differences between the various qualifiers.
The qualifier 'extern' informs your translation unit (source file) that a
global is defined elsewhere and so you are not *DEFINING* it within your
translation unit. If your translation unit is a C source, references to
globals (either variables or functions) tend to be pre-pended with an
underscore. If your C source references the variable:
extern int xcounter;
then your assembly source should define a global called
global _xcounter
Now note the use of the qualifier 'global', used by NASM. NASM manual clearly
explains the difference between 'extern' and 'global', much like the difference
between IMPORT and EXPORT qualifiers, resp., using in making Windows libraries,
if the analogy is not strained. The NASM manual says that:
global _myvariable
both defines the variable and marks it as available for referencing by other
translated units (object files), whereas:
extern _myvariable
says I will use this variable, but don't set aside a place for it, because that
has been set aside elsewhere.
Check those two things:
(1) use of underscores properly, especially if the sources are references
between C-coded and assembly-coded files
(2) clearing up the confusion between the use of 'global' and 'extern'
Mitch Halloran
Research (Bio)chemist
Duzen Laboratories Group
Ankara TURKEY
- Raw text -