链接器错误:模块my.c中未定义符号_sum [英] linker error: undefined symbol _sum in module my.c
问题描述
当我使用Turbo C在库中添加用户定义的方法时,出现以下错误
链接器错误:undefined symbol _sum in module my.c
我正确地遵循了所有步骤:
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.c:
addition(int i, int j)
{
int total;
total = i + j;
return total;
}
第2步:
使用Alt + F9
键(在Turbo C中)编译addition.c
文件
将创建addition.obj
文件,这是addition.c
文件的编译形式.
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.
第3步:
使用tlib
c:\> tlib math.lib + c:\ addition.obj
表示在数学库中添加c:\addition.obj
文件.
Means adding c:\addition.obj
file in the math library.
第4步:
创建文件addition.h
&声明addition()
函数的原型,如下所示.
Step 4:
Created a file addition.h
& declare prototype of addition()
function like below.
int addition (int i, int j);
现在包含功能addition
原型的addition.h
文件.
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);
}
推荐答案
在编写此命令时,您需要指定Lib的完整路径以及您要添加到库中的模块. 去尝试一下 ! 例如
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
Tlib d:\turboc\Lib\CS.lib + d:\turboc\demo.obj
这篇关于链接器错误:模块my.c中未定义符号_sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!