我上课有困难
Shape
从shapetester.cpp中的shape.dll(另一个.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的位置)
属性& gt;配置属性& g/c+c++gt;附加目录(指向形状h的位置)