使用C创建一个静态库 [英] using C to create a Static lib

查看:55
本文介绍了使用C创建一个静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




大家好,

最近我尝试使用MS VC ++创建静态库。


以下是我的代码的一些摘录:

********* MyFirstStaticLib.c ****************** *


#include< stdlib.h>

#include< string.h>


int getA(int a,int b){

....


}


int getB(int a,int b){

....


}


******* *********************************


两个函数''getA ''和''getB''将在我的其他程序中使用。


我编译了我的其他程序......我总是得到__ cdecl int getA()错误

相同的''getB''功能。


任何人都知道原因吗?


谢谢。



Hi all,
Recently I have tried to create a static lib using MS VC++.

The following are some of the excerpt of my codes:
********* MyFirstStaticLib.c *******************

#include <stdlib.h>
#include <string.h>

int getA(int a, int b){
....

}

int getB(int a, int b){
....

}

****************************************

Both function ''getA'' and ''getB'' will be used in my other program.

I compiling my other program... I alway got "__cdecl int getA()" errors
same fot ''getB'' function.

Anyone know the cause?

Thanks.

推荐答案

Ralph< RA *** @ cwazy.REMOVETHIS.co.uk>写道:
Ralph <RA***@cwazy.REMOVETHIS.co.uk> wrote:
最近我尝试使用MS VC ++创建一个静态库。


请注意,创建库是特定于系统的,因此

偏离主题。但是......

我的其他程序中都会使用''getA''和''getB'这两个函数。

我编译了我的其他程序......我总是得到__ cdecl int getA()错误
同样的''getB''功能。

任何人都知道原因吗?
Recently I have tried to create a static lib using MS VC++.
Note that creating libraries is system-specific, and therefore
off-topic. However...
Both function ''getA'' and ''getB'' will be used in my other program.

I compiling my other program... I alway got "__cdecl int getA()" errors
same fot ''getB'' function.

Anyone know the cause?




....你可能会检查您正在编译(库和使用它的

程序)在C模式下,而不是C ++。同上链接和/或

图书馆收藏。


Richard



....you might check that you are compiling (both the library and the
program which uses it) in C mode, not as C++. Ditto for linking and/or
library-collecting.

Richard


rl *@hoekstra-uitgeverij.nl (Richard Bos)在留言中写道:< 40 ************* *** @ news.individual.net> ...


< OT>
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<40****************@news.individual.net>...

<OT>
Ralph< RA *** @ cwazy .REMOVETHIS.co.uk>写道:
Ralph <RA***@cwazy.REMOVETHIS.co.uk> wrote:
最近我尝试使用MS VC ++创建静态库。
Recently I have tried to create a static lib using MS VC++.



请注意,创建库是系统特定的,因此
偏离主题。但是......



Note that creating libraries is system-specific, and therefore
off-topic. However...

我的其他程序中将使用'getA'和'getB'这两个函数。

我编译了我的其他程序......我总是得到__ cdecl int getA()错误
同样的''getB''功能。

任何人都知道原因吗?
Both function ''getA'' and ''getB'' will be used in my other program.

I compiling my other program... I alway got "__cdecl int getA()" errors
same fot ''getB'' function.

Anyone know the cause?



...你可能会检查你是在编译(库和使用它的
程序在C模式下,而不是C ++。同上链接和/或
图书馆收藏。

理查德



...you might check that you are compiling (both the library and the
program which uses it) in C mode, not as C++. Ditto for linking and/or
library-collecting.

Richard




1.你需要做更多关于创建图书馆的阅读。


2.不要使用像getA这样的函数名称。 A表示A。不会让

你的功能名称是唯一的。大多数MS库函数

实现了两个版本,一个附加A(对于Ascii)

,另一个附加W(对于Wide char / Unicode)。


3.实现库时,请始终指定调用

约定。 MS VC有__cdecl,__ stdcall和__fastcall。

一般来说你应该使用__stdcall但默认是__cdecl。

有编译器选项(/ Gz,/ Gd)来指定

约定用作默认值。


4.使用头文件分发你的库。


5。在这里发布简短但完整的信息。 __ cdecl int getA()似乎并不是b / b
是完整的错误信息。


< / OT>



1. You need to do more reading about creating libraries.

2. Do not use functions names like "getA". The "A" won''t make
your function name unique. Most of the MS library functions
are implemented in two versions, one appended with A (for Ascii)
and the other appended with W (for Wide char/Unicode).

3. When you implement a library, always specify the calling
convention. MS VC has __cdecl, __stdcall and __fastcall.
Generallly you should use __stdcall but the default is __cdecl.
There are compiler options (/Gz, /Gd) to specify which
convention to use as the default.

4. Distribute your library with a headerfile.

5. Post brief but complete information on here. It does not seem
that "__cdecl int getA()" is the complete error message.

</OT>


In< a5 ******** ******************@posting.google.com> k_*****@yahoo.com (kal)写道:
In <a5**************************@posting.google.com > k_*****@yahoo.com (kal) writes:
< OT>
< snip>< / OT>
<OT> <snip></OT>




如果您的帖子偏离主题从一端到另一端,则前置

[OT]标记到主题行。


Dan

-

Dan Pop

DESY Zeuthen,RZ集团

电子邮件: Da ***** @ ifh.de


这篇关于使用C创建一个静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆