Solved

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

Posted on 2016-11-01
1
19 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 32

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now