Solved

Linker errors in DLL that uses a static library that has a class with static member functions

Posted on 2016-11-01
1
54 Views
Last Modified: 2016-11-15
I am using
  VS2013 Professional C++
  Windows 7 Pro 64 bit.

I have a a library project that has two classes. Once class has all the member functions declared as virtual. The other class has its member functions declared as static. The library compiles with no errors. When I try to use the library in one of my DLL's, I can use the class that declares the functions as virtual, but I get an unresolved external linker error when I try to use the class with static functions. I own the code that has the virtual member functions, but another group in the company owns the class that has static member functions, so I cannot change it (at least not without a lot of internal effort). Any ideas how to fix this?
0
Comment
Question by:BrianDumas
1 Comment
 
LVL 33

Accepted Solution

by:
sarabande earned 500 total points
ID: 41870515
if you get unresolved externals by linker, the functions called by your code are not contained by the library you link against.

there are a few possibilities what has been wrong.

The library with the class modules was not compiled with the same Compiler or same compiler options or specifiers. for example,  import specifier __declspec(dllimport) which were set in the header files would change the internal name and your project wouldn't find the symbols in the library. You may open the library file with the hex editor of Visual Studio and search for the names missing. if there is a naming problem you should find out. if the names do not exist at all in the library, you may check if you really got the library of a library project and not an import library of a dll. if the project is ok, check whether the cpp file where the static functions were implemented really was added to the library build. if the class was a template class or the functions were template functions, the missing symbols are because template functions are compiled only if you provide a concrete type. that means in the cpp where the static functions were implemented, you need an instantiation for each template type you need in your project.  as this rarely is acceptable, the only way out, is to implement any template code as inline in the header file. then you would not need the library for those functions but by including the header, the functions were built with your project.

Sara
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question