Compiling C with external Assembly procedure problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Compiling C with external Assembly procedure problem

Zorro26Zorro26 Posts: 21Member

I'm using Turbo c++ 4.0, and get this error:
"Linker error: Undefined symbol _Add_Ext in module ..PROJECTSADD.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:
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.


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

void main(void)
Before adding third = %d",third);
Add_Ext(); // This calls the assembly
// program that will add
// externals.
After adding third = %d",third);
}// 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 since
I managed to compile and run a simple "Hello World" program.

Thanks in advance for your help.


  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    You need to add the created object ADD_EXT.obj file to the list of dependencies. I don't know exactly how to do that with Turbo c++, but you have to ensure the ADD_EXT.obj file gets passed on to the linker.
    Best Regards,

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.