Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5428
Number of posts: 16943

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Compiling C with external Assembly function problem Posted by Zorro26 on 9 Jul 2010 at 12:05 AM
Hi,

I'm using Turbo c++ 4.0, and get this error:
"Linker error: Undefined symbol _Add_Ext in module ..\PROJECTS\ADD.C in
module ADD.OBJ"

This are the steps I've done before compilation (and please correct me):
1) compiling the Assembly code file ADD_EXT.ASM with MASM 6.11:
masm ADD_EXT.ASM
I didn't do the linking so i had ADD_EXT.OBJ
This is the Assembly code:
   ; Listing 2.7. The MASM portion of an external example.

.MODEL MEDIUM     ; This tells the procedure to use the
                  ; MEDIUM memory model.

EXTRN first:WORD,second:WORD,third:WORD

.CODE             ; This is the beginning of the code.

_Add_Ext PROC FAR  ; The procedure is type FAR.
mov AX,first      ; This moves the first number into the
         		  ; accumulator.
add AX,second     ; This adds the second number to the
		          ; accumulator.
mov third,AX      ; This stores the result back into
		          ; third.

_Add_Ext ENDP      ; This procedure ends here.

END               ; This is the end of the code segment.


2) This is the C ADD.C code
   // Listing 2.6 The C portion of an external example.

#include <stdio.h>

int first=1,second=2,third=0;  // These are the integers with
			       // which we want to work.
extern Add_Ext();

void main(void)
{
  printf("\nBefore adding third = %d",third);
  Add_Ext();                   // This calls the assembly
			       // program that will add
			       // externals.
  printf("\nAfter adding third = %d",third);
  getchar();
}// end main
   


3) Compiling the ADD.C file and getting the error I mentioned.
The ADD_EXT.OBJ and ADD_EXT.ASM are in the same directory.
There isn't any problem with the #include <stdio.h> since
I managed to compile and run a simple "Hello World" program.

Thanks in advance for your help.









 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.