C ++中的包含库问题 [英] Problem with include libraries in C++

查看:84
本文介绍了C ++中的包含库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...
我有一个小问题:
假设要包含一些库,例如:"Parentlib/test1.h","Parentlib/test2.h"等.
如何以某种方式定义"Parentlib",以便"test1.h"和"test2.h"正常工作?

Hello everybody...
I have a little problem:
Suppose you want include some libraries For example: "Parentlib/test1.h" , "Parentlib/test2.h" and so on.
How can i define "Parentlib" somehow so "test1.h" and "test2.h" work? How that is possible?

推荐答案

可能正在寻找#pragma comment(lib,...) [
It''s possible that you are looking for #pragma comment( lib, ... )[^]

if the lib file required by the headers is called Parentlib.lib you can add
#pragma comment( lib, "Parentlib" )


到包含您的主要功能的文件.确保链接器也知道在哪里可以找到lib文件.

最好的问候
Espen Harlinn


to the file containing your main function. Make sure that the linker knows where to find the lib file too.

Best regards
Espen Harlinn


这些是头文件,而不是库本身.对于库,您应该具有C或C ++的源文件.如果源不可用,则应提供目标文件或库文件.

另外,您尝试使用的库有一个变化,该库不是通过静态库文件提供的,而是作为称为共享库动态链接库的可执行文件提供的>.在这种情况下,您还将在运行时需要此库.链接该库的方法可以不同.它可以是定义文件,一个特殊的静态链接库,其中包含绑定代码,并且被链接器使用(请参见下文)等.

如果提供了源代码,则应将其包括在编译中.如果提供了目标文件或库文件,则应在链接器的参数中引用.在这两种情况下,都可以将其添加到生成文件和/或项目文件中(例如,MSBuild接受的文件).如果使用的是IDE,则可能会找到适当的选项,这些选项使您可以在项目和/或解决方案中添加库.

您没有共享正在使用的开发环境,因此请自行查找.这不是最大的问题.更让我担心的是,从您的问题来看,我怀疑您不太清楚软件构建的编译和链接阶段.这是您可能需要接受一些教育的地方:

http://en.wikipedia.org/wiki/Compiler [ http://en.wikipedia.org/wiki/Compiled_language [ http://en.wikipedia.org/wiki/Linker_%28computing%29 [ ^ ],
http://en.wikipedia.org/wiki/Include_file [ http://en.wikipedia.org/wiki/Object_file [ http://en.wikipedia.org/wiki/Dynamic-link_library [
Those are header files, not the library itself. For a library, you should have source files in C or C++. If the source is not available, you should be provided object files or library file(s).

Also, there is a change that you are trying to use a library which is supplied not through the static library file, bit as an executable file called shared library or dynamic-link library. In this case, you will also need this library during run-time. The methods of linking this library can be different. It can be definition file, a special static link library containing binding code and being used by a linker (please see below) and more.

If you are given the source code, you should include it in your compilation. If you are given object or library files, you should reference the in the parameter of your linker. In both cases, it can be added to your make file and/or your project file (for example, the files accepted by MSBuild). If you are using some IDE, you will probably find appropriate options which let you to add the library in your project(s) and/or solution.

You did not share what development environment you are using, so find out it by yourself. This is not the biggest problem. What concerns me more, from your question I suspect you don''t clearly understand compilation and linking phases of the software builds. This is where you may need some education:

http://en.wikipedia.org/wiki/Compiler[^],
http://en.wikipedia.org/wiki/Compiled_language[^],
http://en.wikipedia.org/wiki/Linker_%28computing%29[^],
http://en.wikipedia.org/wiki/Include_file[^],
http://en.wikipedia.org/wiki/Object_file[^],
http://en.wikipedia.org/wiki/Dynamic-link_library[^].

—SA


这篇关于C ++中的包含库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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