linker error: undefined symbol _sum in module my.c

user3575428 picture user3575428 · Apr 26, 2014 · Viewed 19.9k times · Source

I am getting following error when I add user defined method in library using turbo c linker error: undefined symbol _sum in module my.c I followed all steps properly:

 // 1. create addition.c containing function definatio and compile it

addition.c:

 addition(int i, int j)
  {
  int total;
 total = i + j;
 return total;
 }

Step 2:

Compile addition.c file by using Alt + F9 keys (in turbo C) addition.obj file would be created which is the compiled form of addition.c file.

Step 3: Add it to library using tlib

c:\> tlib math.lib + c:\ addition.obj

Means adding c:\addition.obj file in the math library.

Step 4: Created a file addition.h & declare prototype of addition() function like below.

 int addition (int i, int j);

Now addition.h file containing prototype of function addition.

# include <stdio.h>
     // Including our user defined function.
     # include “c:\\addition.h”     
   int main ()
   {
   int total;
   // calling function from library
   total = addition (10, 20); 
   printf ("Total = %d \n", total);
    }

Answer

SKabir picture SKabir · Mar 14, 2016

While writtig this command you need to specify full path of Lib and your module u want to add to library. Just try it ! e.g.

Tlib d:\turboc\Lib\CS.lib + d:\turboc\demo.obj