不能使用隐式链接.dll中的类
Cant use a class from an implicitly linked .dll
我在ShapeTester中使用Shape.dll中的类Shape
时遇到问题.cpp(另一个.dll项目。
//Shape.h
#ifdef SHAPE_EXPORTS
#define SHAPE_API __declspec(dllexport)
class SHAPE_API Shape
{
public:
Shape();
Shape(int sides, int sideLength, int apothem);
~Shape();
int Perimeter();
double Area();
private:
int sides;
int sideLength;
int apothem;
};
#endif
------------------------------------------------------------
//Shape.cpp
#include "stdafx.h"
#include "Shape.h"
Shape::Shape() : sides(0), sideLength(0), apothem(0)
{
}
Shape::Shape(int sides, int sideLength, int apothem) : sides(sides), sideLength(sideLength), apothem(apothem)
{
}
Shape::~Shape()
{
}
double Shape::Area()
{
//implementation
}
int Shape::Perimeter()
{
//implementation
}
-----------------------------------------------------------
//ShapeTester.cpp (this is in another DLL project)
#include "stdafx.h"
#include "ShapesTester.h"
#include "Shape.h"
bool ShapesTester::Test()
{
Shape myShape = Shape(3, 9, 5); // error here; cant resolve symbol Shape
return myShape.Area() == 67.5;
}
我在预处理器指令中包含SHAPE_EXPORT,我可以得到.dll,.lib
属性>配置 链接器>输入>属性>将其他依赖项设置为 Shape.lib
属性>配置 链接器>属性>常规>其他库目录(指向 Shape.Lib 的位置(
属性>配置 属性> C/C++> 其他包含目录(指向 Shape.h 的位置(
你的Shape
类应该在#ifdef
块之外,而不是在块内。 除非定义了SHAPE_EXPORT
符号,否则代码不会声明Shape
类。
你想做的是
#ifdef SHAPE_EXPORTS
#define SHAPE_API __declspec(dllexport)
#else
#define SHAPE_API __declspec(dllimport)
#endif
class SHAPE_API Shape
// etc
相关文章:
- C++ 在 CentOS7 中与 g++ 的 DLL 链接后未声明的函数
- DLL 链接静态库 - 未使用函数中未解析的链接器符号
- 尝试针对 dll 链接时未解析的外部
- C 延迟负载DLL链接器错误
- QT应用程序与使用QT制造的DLL链接时崩溃
- Visual Studios 9 Dll链接不一致
- Windows DLL 链接器错误与模板类
- GLPK OpenBLAS 运行时 dll 链接错误
- 隐式 DLL 链接和类内部函数
- 将 c# asp.net Web 应用程序与C++ dll 链接时,是在服务器或客户端上运行的 dll 代码
- 将 mingw dll 与 Windows DLL 链接起来
- C++/CLI DLL 链接器问题
- 从另一个 dll 链接动态 dll 会导致错误
- 为什么隐式DLL链接需要相关的Lib文件,而显式链接不需要
- visual studio 2010中的dll链接错误
- 从dll链接静态成员
- Visual Studio 2015 OpenGL freeg鲁特.dll链接器错误
- C++ 一个解决方案两个项目(EXE & DLL)链接错误
- 与 DLL 链接时"multiple definition of `atexit'"
- 使DLL链接不一致