把一些重要的代码编译成Lib或者dll
2011-05-13 16:41
344 查看
1. 对于一些重要代码 可以编译成dll或者lib, 然后提供给其他人使用和自己使用
1.1 lib 在VS2008中很简单, 就是创建一个Win32 DLL或者其他的DLL工程, 在
Property | Configuration Properties | General | Configuaration Type 中选择Static Library(.lib)
编译即可生成lib
对于使用者, 包含对应的头文件(函数, 类等声明),
在对应的地方输入类似下面的语句或者在对应的位置设置lib 就可以了.
#ifdef _DEBUG
#pragma comment(lib, "../Debug Static/ThreadPool.lib");
#else
#pragma comment(lib, "../Release Static/ThreadPool.lib");
#endif
得到lib后, 使用者连接lib时有时会报一堆连接错误, 这是lib的工程选项与使用者的工程选项不一致造成的
主要选项有:
a. Property | Configuration Properties | C/C++ | Code Generation | Rumtime Library 你可以根据情况选择对应的选项,
b. Property | Configuration Properties | General | Use of MFC 你可以根据需要选择对应的选项
由于生成lib时工程是Win32 Lib (本人比较喜欢这个), 所以默认选项就是 Use Standard Windows Libraries
但在Win32 Lib中也可以使用MFC的一些类的 例如CString, 那你就要选择Use MFC in a Shared DLL或者Use MFC in a Static DLL了
当你选择了这个的时候, a选项可能会有问题, b选项选择了MFC, a选项必须选MD了 (不能选MT).
1.2 对于dll
导出类:
// point.h文件
#pragma once
#ifdef DLL_FILE
class _declspec(dllexport) point //导出类point(DLL要导出类)
#else
class _declspec(dllimport) point //导入类point(使用者要导入类)
#endif
{
public:
float y;
float x;
point();
point(float x_coordinate,float y_coordinate );
};
// point.cpp文件
#define DLL_FILE
#include "point.h"
使用者只要包含对应的头文件和下面这些, 还有运行的时候需要对应的dll文件.
#ifdef _DEBUG
#pragma comment(lib, "../Debug Static/ThreadPool.lib");
#else
#pragma comment(lib, "../Release Static/ThreadPool.lib");
#endif
1.1 lib 在VS2008中很简单, 就是创建一个Win32 DLL或者其他的DLL工程, 在
Property | Configuration Properties | General | Configuaration Type 中选择Static Library(.lib)
编译即可生成lib
对于使用者, 包含对应的头文件(函数, 类等声明),
在对应的地方输入类似下面的语句或者在对应的位置设置lib 就可以了.
#ifdef _DEBUG
#pragma comment(lib, "../Debug Static/ThreadPool.lib");
#else
#pragma comment(lib, "../Release Static/ThreadPool.lib");
#endif
得到lib后, 使用者连接lib时有时会报一堆连接错误, 这是lib的工程选项与使用者的工程选项不一致造成的
主要选项有:
a. Property | Configuration Properties | C/C++ | Code Generation | Rumtime Library 你可以根据情况选择对应的选项,
b. Property | Configuration Properties | General | Use of MFC 你可以根据需要选择对应的选项
由于生成lib时工程是Win32 Lib (本人比较喜欢这个), 所以默认选项就是 Use Standard Windows Libraries
但在Win32 Lib中也可以使用MFC的一些类的 例如CString, 那你就要选择Use MFC in a Shared DLL或者Use MFC in a Static DLL了
当你选择了这个的时候, a选项可能会有问题, b选项选择了MFC, a选项必须选MD了 (不能选MT).
1.2 对于dll
导出类:
// point.h文件
#pragma once
#ifdef DLL_FILE
class _declspec(dllexport) point //导出类point(DLL要导出类)
#else
class _declspec(dllimport) point //导入类point(使用者要导入类)
#endif
{
public:
float y;
float x;
point();
point(float x_coordinate,float y_coordinate );
};
// point.cpp文件
#define DLL_FILE
#include "point.h"
使用者只要包含对应的头文件和下面这些, 还有运行的时候需要对应的dll文件.
#ifdef _DEBUG
#pragma comment(lib, "../Debug Static/ThreadPool.lib");
#else
#pragma comment(lib, "../Release Static/ThreadPool.lib");
#endif
相关文章推荐
- VC编译\链接\运行:包含文件、包含库lib、包含动态库dll的一些问题
- 编译2010年x264最新的代码供VC编译使用DLL与LIB
- 编译过程的一些小知识——LIB与DLL的区别
- 一些代码编译后的指令,捉虫很有用
- 利用Visual Studio 自带工具查询lib 或者 dll 文件是32位还是64位
- MTK当修改一些代码时,使用什么编译命令可以最有效率
- C++与matlab用dll或者Lib的方式混编方法
- VC2005编译SQLite,生成WINCE上使用的DLL和Lib
- MTD/MT/MDD/MD以及LIB/DLL之间的一些联系和问题
- GPU(CUDA)学习日记(二)--------VS2010不同工程之间调用DLL或者LIB
- Lib Dll在VS2008下的编译和使用-持续更新,欢迎拍砖
- vs2010编译某个工程提示缺少lib或者头文件 vs2010的配置中的生成事件
- MTD/MT/MDD/MD以及LIB/DLL之间的一些联系和问题
- Andorid中一些重要的代码片段
- C++与matlab用dll或者Lib的方式混编方法
- VC++编译错误: Nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12已经在dllmain.obj 中定义
- VS2005中编译dll未生产lib的原因及解决方法
- C或C++编译成lib或dll时修饰符extern C及相关的浅析
- Part2. 使用Visual Studio把C代码编译成.dll文件
- 编写S-Function,创建Simulink模型并生成C++代码,编译生成可调用的动态库dll(From Simulink model to DLL A tutorial)