0

I have a class in project Utils as follows:

Maths.h

class __declspec(dllexport) Maths
{
public:
  static const double c_epsilon;

  ...
}

Maths.cpp

const double Maths::c_epsilon = DBL_EPSILON;

I then have (many) other projects that use this class (and use the c_epsilon constant).

Almost all other projects build and link without issue... but a couple fail with the error:

LNK2001 unresolved external symbol "__declspec(dllimport) public: static double const Maths::c_epsilon" (__imp_?c_epsilon@Maths@@2NB)

The two failing projects are both Google Test projects and other than producing an executable (instead of a DLL) appear to be set up the same as all other projects.

The failing projects definitely do specify the Utils.lib file.

I can only imagine this is a project setting issue (as other projects are fine), but I can't find any settings that differ that resolve the issue.

grae22
  • 104
  • 11

1 Answers1

1

Turns out the problematic projects specified the output folder, $(OutDir), as a path in which to find additional dependencies. This is problematic as at this point in the build the output folder still contains the 'old' lib files which are copied as a post-build step (a process that should probably be reviewed).

The 'old' lib files were from a build where the constants weren't actually declared as 'const' (merely static) - this had been changed, hence the resulting unresolved external symbol error.

grae22
  • 104
  • 11