Makefile时连接库文件的问题

软件和网站开发以及相关技术探讨
回复
weihua2008
帖子: 448
注册时间: 2008-07-10 15:08

Makefile时连接库文件的问题

#1

帖子 weihua2008 » 2008-09-10 15:32

上次发帖就是想问这个问题,由于我一时疏忽,对于sin(12.12)撒出现负值?转不过弯来(是弧度不是度)
各路神仙竞相指招,
对于sin函数为啥有负值,给我上了生动的一课!
结果就没有一个人说我应该在写Makefile时如何加载连接库
我再次提出这个问题,希望指教,用sin函数试试,因为在编译时要连接库
-lm
结果把-lm放哪都不合适,
/***********************test.h
#ifndef _TEST_H__
#define _TEST_H__
void function();
#endif
*****************************************
test.c
#include<stdio.h>
#include"test.h"
void function()
{
double i=sin(12.12);
printf("%f\n",i);
}
***********************************************
#include<stdio.h>
int main()
{
function();
return 0;
}
**********************************
Makefile
main:main.o test.o
gcc -o $@$^
main.o:main.c test.h
gcc -c $<
test.o:test.c test.h
gcc -lm -c $<
clean:
rm *.o
********************
用-lm或者库的绝对路径放哪都不行
望指教
头像
lyre
帖子: 77
注册时间: 2005-06-28 18:08

#2

帖子 lyre » 2008-09-16 21:37

/***********************test.h
#ifndef _TEST_H__
#define _TEST_H__
void function();
#endif
*****************************************
test.c
#include<stdio.h>
#include<math.h>
#include"test.h"
void function()
{
double i=sin(12.12);
printf("%f\n",i);
}
***********************************************
#include<stdio.h>
int main()
{
function();
return 0;
}
**********************************
Makefile
main:main.o test.o -lm
gcc -o $@$^
main.o:main.c test.h
gcc -c $<
test.o:test.c test.h
gcc -c $<
clean:
rm *.o
********************
weihua2008
帖子: 448
注册时间: 2008-07-10 15:08

#3

帖子 weihua2008 » 2008-09-17 10:45

lyre
非常感谢!
回复