Redian新闻
>
怎样增加C语言的库函数
avatar
怎样增加C语言的库函数# Computation - 科学计算
g*s
1
我自己的一个函数需要以后经常使用,我想把它做成一个库函数的形式。
我先写了一个“a.C"文件里面是我经常用的那个函数,又写了一个“a.h"文件,这个头文
件中只是那个函数的声明。
然后我把“a.C" 和“a.h"文件都存在了当前目录下。我在我的应用程序中一开始就写上
#include "a.h"
为什么在编译时老是显示错误:找不到那个我写在“a.C"中的函数。
可是当我直接写
#include "a.C"
就得到了我要的结果。可是我不想这样做,我想include头文件,而不是直接include那个
函数。我想要做得就像只include math.h 就可以使用 sqrt() 一样。
大家能不能给我推荐一本这方面的专业书,那些基本的C语言书都没详细的写这些内容。
我甚至查不到我把“a.C"和"a.h"都存在当前目录下对不对。
avatar
f*r
2
你的问题出在编译上
你需要把a.C文件编译成目标代码才行
soln1:
g++ main.C a.C
soln2:
g++ -c a.C
g++ main.C a.o
soln3:
write a Makefile
soln4:
make a library of your a.C
suppose your library file is liba.a
then
g++ main.C -la
soln4实际上和sqrt的方法是一样的,只是-lm,(链接数学库,在
很多系统上是可以省略的)





【在 g***s 的大作中提到】
: 我自己的一个函数需要以后经常使用,我想把它做成一个库函数的形式。
: 我先写了一个“a.C"文件里面是我经常用的那个函数,又写了一个“a.h"文件,这个头文
: 件中只是那个函数的声明。
: 然后我把“a.C" 和“a.h"文件都存在了当前目录下。我在我的应用程序中一开始就写上
: #include "a.h"
: 为什么在编译时老是显示错误:找不到那个我写在“a.C"中的函数。
: 可是当我直接写
: #include "a.C"
: 就得到了我要的结果。可是我不想这样做,我想include头文件,而不是直接include那个
: 函数。我想要做得就像只include math.h 就可以使用 sqrt() 一样。

avatar
g*s
3
Thank you.
Unfortunately, I use Turbo C under MS-Dos system. I do not use unix.
Can you teach me how to do it under MS-Dos system?

【在 f********r 的大作中提到】
: 你的问题出在编译上
: 你需要把a.C文件编译成目标代码才行
: soln1:
: g++ main.C a.C
: soln2:
: g++ -c a.C
: g++ main.C a.o
: soln3:
: write a Makefile
: soln4:

avatar
f*r
4
usually I don't care which enviroment we should use
but turbo C is way out of date.
better change your enviroment to some modern one.
Dev-c++ is free and shipped with gcc.
I recommend you take some time to learn something new.
For now a days, I can't imagine to do programing in turbo c,
now syntax highlight, now autocompletion,and under Ms-dos.

【在 g***s 的大作中提到】
: Thank you.
: Unfortunately, I use Turbo C under MS-Dos system. I do not use unix.
: Can you teach me how to do it under MS-Dos system?

avatar
f*r
5
http://www.bloodshed.net/dev/devcpp.html
从这里可以下载

【在 f********r 的大作中提到】
: usually I don't care which enviroment we should use
: but turbo C is way out of date.
: better change your enviroment to some modern one.
: Dev-c++ is free and shipped with gcc.
: I recommend you take some time to learn something new.
: For now a days, I can't imagine to do programing in turbo c,
: now syntax highlight, now autocompletion,and under Ms-dos.

avatar
a*e
6
For Visual C++, there is a nmake.
There must be similar thing for Turbo C.

【在 g***s 的大作中提到】
: Thank you.
: Unfortunately, I use Turbo C under MS-Dos system. I do not use unix.
: Can you teach me how to do it under MS-Dos system?

avatar
f*r
7
if you really want to use turbo C
you need to create a project.
suppose you have three files
main.c a.c a.h
I think your project file need to include main.c and a.c
then you choose menu,make
it will create the exe file for you.
google project turbo c for more detail

【在 g***s 的大作中提到】
: Thank you.
: Unfortunately, I use Turbo C under MS-Dos system. I do not use unix.
: Can you teach me how to do it under MS-Dos system?

avatar
g*s
8
I have downloaded Dev-C++ and installed it.
Thank you very much.
I will read some new books about C.
I studied C in 1997 in China and did not study computer language(except Matlab
) for 8 years.

【在 f********r 的大作中提到】
: if you really want to use turbo C
: you need to create a project.
: suppose you have three files
: main.c a.c a.h
: I think your project file need to include main.c and a.c
: then you choose menu,make
: it will create the exe file for you.
: google project turbo c for more detail

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。