3

We have the following setup;

A dynamic library (compiled with /MD). It depends on;

  • another dynamic library (compiled with /MD)
  • a static library (compiled with /MD)

This produces the following linker error;

my_static_library.lib(my_object_file.obj) : error LNK2005:
"public: class std::_Vector_const_iterator<class std::_Vector_val<struct std::_Simple_types<double> > > __thiscall std::vector<double, class std::allocator<double> >::begin(void)const
"(?begin@?vector@NV?$allocator@N@std@@@std@@BE?AV$?_Vector_const_iterator$?_Vector_vald@U?_Simple_types@N@std@@@std@@@2@XZ already defined in another_dynamic_library.dll

Using Dependency Walker we see that another_dynamic_library does export std::vector but we cannot change this component.

Using dumpbin we see that static_library.lib also contain a symbol to std::vector.

Viewing the source code for my_object_file.obj (static_library), std::vector is used as a private member of a class. The class has an include guarde and is located inside a namespace. There are no global variables, no static variables or usage of extern.

We assume the problem is that VS2012 does not know which instance of std::vector to use.

What is the recommended way of solving this issue?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
LarsA
  • 595
  • 2
  • 6
  • 14

0 Answers0