【发布时间】:2018-05-20 18:46:44
【问题描述】:
我无法在我的 ShapeTester.cpp(另一个 .dll 项目)中使用我的 Shape.dll 中的 Shape 类。
//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 的位置)
【问题讨论】:
-
请逐字发布您收到的编译器/链接器错误。在没有看到错误的情况下,除了猜测之外,您还指望我们做什么?
-
我按字面意思表示无法解析符号“形状”
-
没有发布错误消息逐字。这只是发布您的 interpreted 版本的错误消息。只需发布原始版本即可。