将.lib中的函数放在命名空间中? [英] Placing functions from .lib in a namespace?

查看:76
本文介绍了将.lib中的函数放在命名空间中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。


对于我的应用程序,我使用的是第三方库,它是作为

库文件(.lib)提供的以及一个关联的头文件,用于原型化库中定义的函数
。重要的是库已经编译好了。


现在,这个库只定义函数,它们在

全局命名空间中声明。由于这是相当丑陋和不方便,我想

将这些函数放在他们自己的命名空间中。


是否可以更改这些函数的完全限定名称函数如果他们已经编译好了,或者是否有其他方法可以在他们自己的命名空间中获得这些

函数?


谢谢,

Leon。

解决方案

Leon写道:

大家好。

对于我的应用程序我正在使用第三方库作为库文件(.lib)和相关的头文件提供原型来定义的函数
图书馆。重要的是库已经编译好了。

现在,这个库只定义了函数,它们在
全局命名空间中声明。由于这是相当丑陋和不方便,我想将这些功能放在他们自己的命名空间中。

如果他们'可以改变这些功能的完全限定名称'已经编译了,或者是否有其他方法可以在自己的命名空间中获得这些功能?




我通常已经得到了这个:


名称空间Acme

{

#include" acme_headers.h"

}


Acme :: func();


如果这不起作用,试试:


命名空间Acme

{

#include" acme_headers.h"

}


使用命名空间Acme;


func();


当然,它只是一个创可贴,但至少它是''明确的。


Jeff Schwab写道:


Leon写道:

你好所有。

我的应用程序我正在使用第三方库作为库文件(.lib)和相关的头文件提供,以对库中定义的函数进行原型化。重要的是库已经编译好了。

现在,这个库只定义了函数,它们在
全局命名空间中声明。由于这是相当丑陋和不方便,我想将这些功能放在他们自己的命名空间中。

如果他们'可以改变这些功能的完全限定名称'已经编译过,或者是否有其他方法可以在自己的命名空间中获得这些功能?



我通常已经忘记了:

命名空间Acme
{
#include" acme_headers.h"
}
Acme :: func();
如果这不起作用,请尝试:

名称空间Acme
{
#include" acme_headers.h"
}
使用名称空间Acme;

func();

它当然只是一个创可贴,但至少它是明确的。




不能工作。 Acme :: func是一个与:: func不同的函数。图书馆

定义''extern'C" func",所以调用Acme :: func不会链接。


即使你可以重新编译库,这可能也不会工作:
$ b包含

命名空间声明中的任何标准标题的程序的$ b行为是未定义的,并且很可能是

" acme_headers.h"就是这样。


-


Pete Becker

Dinkumware,Ltd。( http://www.dinkumware.com


Leon写道:


大家好。

对于我的应用程序,我正在使用第三方库作为
库提供文件(.lib)和相关的头文件,用于原型化库中定义的函数。重要的是库已经编译好了。

现在,这个库只定义了函数,它们在
全局命名空间中声明。由于这是相当丑陋和不方便,我想将这些功能放在他们自己的命名空间中。

如果他们'可以改变这些功能的完全限定名称'已经编译过,或者是否有其他方法可以在自己的命名空间中获得这些功能?




Nope。但是,如果你喜欢繁忙的工作,你可以在命名空间中编写包装函数

来调用库中的全局函数。但是你确实没有完成任何事情:全局变量仍然是全球性的。

不要打架图书馆。按照它的写法使用它,或者重写它。


-


Pete Becker

Dinkumware,Ltd。( http://www.dinkumware.com


Hi all.

For my application I''m using a third-party library which is supplied as a
library file (.lib) and an associated header file to prototype the functions
defined in the library. Important is that the library is already compiled.

Now, this library defines only functions, and they are declared in the
global namespace. Since this is rather ugly and inconvenient, I want to
place these functions in their own namespace.

Is it possible to change the fully qualified names of these functions if
they''re already compiled, or maybe is there another way to get these
functions in their own namespace?

Thanks,
Leon.

解决方案

Leon wrote:

Hi all.

For my application I''m using a third-party library which is supplied as a
library file (.lib) and an associated header file to prototype the functions
defined in the library. Important is that the library is already compiled.

Now, this library defines only functions, and they are declared in the
global namespace. Since this is rather ugly and inconvenient, I want to
place these functions in their own namespace.

Is it possible to change the fully qualified names of these functions if
they''re already compiled, or maybe is there another way to get these
functions in their own namespace?



I''ve usually gotten away with this:

namespace Acme
{
#include "acme_headers.h"
}

Acme::func( );

If that doesn''t work, try:

namespace Acme
{
#include "acme_headers.h"
}

using namespace Acme;

func( );

It''s just a band-aid, of course, but at least it''s explicit.


Jeff Schwab wrote:


Leon wrote:

Hi all.

For my application I''m using a third-party library which is supplied as a
library file (.lib) and an associated header file to prototype the functions
defined in the library. Important is that the library is already compiled.

Now, this library defines only functions, and they are declared in the
global namespace. Since this is rather ugly and inconvenient, I want to
place these functions in their own namespace.

Is it possible to change the fully qualified names of these functions if
they''re already compiled, or maybe is there another way to get these
functions in their own namespace?



I''ve usually gotten away with this:

namespace Acme
{
#include "acme_headers.h"
}

Acme::func( );

If that doesn''t work, try:

namespace Acme
{
#include "acme_headers.h"
}

using namespace Acme;

func( );

It''s just a band-aid, of course, but at least it''s explicit.



Can''t work. Acme::func is a different function from ::func. The library
defines ''extern "C" func", so calls to Acme::func won''t link.

Even if you can recompile the library this probably won''t work: the
behavior of a program that includes any standard headers inside a
namespace declaration is undefined, and chances are good that
"acme_headers.h" will do just that.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)


Leon wrote:


Hi all.

For my application I''m using a third-party library which is supplied as a
library file (.lib) and an associated header file to prototype the functions
defined in the library. Important is that the library is already compiled.

Now, this library defines only functions, and they are declared in the
global namespace. Since this is rather ugly and inconvenient, I want to
place these functions in their own namespace.

Is it possible to change the fully qualified names of these functions if
they''re already compiled, or maybe is there another way to get these
functions in their own namespace?



Nope. If you like busywork, though, you could write wrapper functions
inside a namespace that call the global ones in the library. But you
really haven''t accomplished anything: the globals are still global.
Don''t fight the library. Use it the way it''s written, or rewrite it.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)


这篇关于将.lib中的函数放在命名空间中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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