CPP,头文件到dll库 [英] CPP, Header files in to dll libraries

查看:79
本文介绍了CPP,头文件到dll库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些cpp文件和c ++库的大量头文件,所以我可以在VS Projects中引用它们,但每次我必须添加所有文件(差不多50个)开头,Isnt有什么简单的方法在.dll中编译c ++的所有标题并仅引用一个文件。

I have these cpp files and a lot of header files for c++ libraries, so i can reference them in a VS Projects, but everytime i have to add all of files (almost 50) to start with, Isnt there any easy way to compile all of headers of c++ in a .dll and reference only one file.

推荐答案

修改后的答案。



如果你想创建一个Win32 DLL并拥有.h和.cpp文件,你应该可以使用这个演练来完成它:



演练:创建和使用动态链接库(C ++ [ ^ ]



如果你然后想要从.Net托管代码(c#或VB)访问这个Win32非托管DLL中的方法,你需要使用 Platform Invoke (PInvoke)。



本教程为您提供了一个起点:

平台调用教程 [ ^ ]



这个网站为您提供标准Win32方法及其.Net签名的示例。

它可以作为参考。

http://pinvoke.net/ [ ^ ]





对于误会很抱歉,但这个问题对我来说并不是很清楚。



======================================== ==================



以下答案是将.h和.lib文件包含到项目中,没有创建DLL。



如果你只有头文件和编译的lib文件,你可以将所有的头文件放在一个目录,Include和lib文件中另一个,图书馆。



然后你可以将这些目录添加到你的项目或VS IDE(如果你一直使用它们)



1.添加到项目

打开项目的属性。

1.a.转到配置属性 - > C / C ++ - >一般

将您的Include目录添加到属性'Additional Include Directories'。

1.b.转到配置属性 - >链接器 - >输入

将您的Library目录添加到属性'Additional Dependencies'。





2.添加到视觉工作室



Go菜单项工具 - >选项 - >项目和解决方案 - > VC ++目录并在那里添加你的目录。

这似乎只能在VS 2005之前工作。
Revised answer.

If you want to create a Win32 DLL and have the .h and .cpp files you should be able to do it using this walkthrough:

Walkthrough: Creating and Using a Dynamic Link Library (C++[^]

If you then want to access the methods in this Win32 unmanaged DLL from .Net managed code (c# or VB), you need to use Platform Invoke (PInvoke).

This tutorial gives you a starting point:
Platform Invoke Tutorial[^]

This web site gives you examples of standard Win32 methods and their .Net signatures.
It can be helpful as a reference.
http://pinvoke.net/[^]


Sorry for the misunderstanding, but the question was not crystal clear to me.

==========================================================

The answer below is for including .h and .lib files into a project, not creating a DLL.

If you only have header files and compiled lib files, you can put all your header files in one directory, Include, and the lib files in another, Library.

Then you can either add these directories to your project or to VS IDE (if you use them all the time)

1. Add to the project
Open the properties for the project.
1.a. Go to Configuration Properties -> C/C++ -> General
Add your Include directory to the property 'Additional Include Directories'.
1.b. Go to Configuration Properties -> Linker -> Input
Add your Library directory to the property 'Additional Dependencies'.


2. Add to Visual Studio

Go menu item Tools -> Options -> Projects and Solutions -> VC++ Directories and add your directories there.
This seems only to work prior to VS 2005, though.


是的,这就是库的全部内容。您可以创建静态库(.olb)或动态加载库(.dll)。使用静态库时,链接器会尝试通过包含所需函数的实际代码来解析所有外部引用。动态链接库始终包含构建它们时放在一起的所有代码。它们在加载时附加到您的进程,这使您的.exe文件保持舒适和小。



您要使用哪个库取决于您的要求。 DLL需要与.exe文件一起分发和安装。但它们的优点是可能在几个应用程序之间共享,您可以在以后交换它们以修复错误或扩展功能。



静态库有点容易处理并最终合并到您的应用程序的.exe文件中。
Yes, that is what a library is all about. You can either create a static library (.olb) or a dynamic load library (.dll). When using a static library, the linker tries to resolve all external references by including the actual code for the functions that are needed. Dynamic link libraries always contain all the code that was put together when building them. They are attached to your process at load time, which keeps your .exe file snug and small.

Which one of the libraries you want to use depends on your requirements. DLLs need to be distributed and installed together with your .exe file. But they have the advantage of being possibly shared between several of your applications and you can later exchange them for bug fixing or extending the functionality.

A static library is somewhat easier to handle and will finally be incorporated into the .exe file of your application.


这篇关于CPP,头文件到dll库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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