1

I have one c++ project 'A' which outputs a dynamic library. I want this library to link to a static library 'B' that I made. The problem is that I am having an undefined external symbol error on compile time. I tried to configure 'B' as a dynamic library and the linking works fine, but the requirement is to have a dynamic library linking to a static library.

My questions are:

  1. What might be different between a static library and a dynamic library that might affect this type of linking?
  2. When using a static library should all the symbols that I want to use dllexported? If yes, why is it not necessary to do using when linking to dynamic library

EDIT

In B project I have the following:

Header file

#define APICALL extern "C"  __declspec(dllexport)
#define STACKMODE   __stdcall

APICALL void STACKMODE GenerateTIERJ_PAM4(double * timeVals, double * YVals, double * smoothedYVals, double lineRate, double ratio, double*tiePts, double * timeIndexes, double *RJ_RMS, int cntData);

Source file

APICALL void STACKMODE GenerateTIERJ_PAM4(double * timeVals, double * YVals, double * smoothedYVals, double lineRate, double ratio, double*tiePts, double * timeIndexes, double *RJ_RMS, int cntData)
{
    //Doing some stuff
}

In A project I am using this function directly using

extern "C" __declspec(dllimport)void GenerateTIERJ_PAM4(double * timeVals, double * YVals, double * smoothedYVals, double lineRate, double ratio, double*tiePts, double * timeIndexes, double *RJ_RMS, int cntData);

When trying to use B as a dynamic library it works but when trying to use it as a static library I get the following

Error LNK2019 unresolved external symbol __imp_GenerateTIERJ_PAM4 referenced >in function "public: static double __cdecl >Filters::ProcessScopeSamplesForTIE

Hasan H
  • 142
  • 11
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix). In any case, it would be helpful if you first read that to get an insight on the problem itself. Then, if this doesn't help, extract a [mcve] and provide that as part of your question. – Ulrich Eckhardt Jul 01 '20 at 06:25
  • You are overthinking this. You have an unresolved external symbol because you've declared a symbol but not defined it. Look for the simple explanation first. – john Jul 01 '20 at 06:26
  • @john but if that's the case then I wouldn't be able to link to B dynamically. – Hasan H Jul 01 '20 at 06:32
  • @HasanH then maybe provide some snippet around the error where it occurs? – arsdever Jul 01 '20 at 06:42
  • @HasanH Not true, if the missing symbol is referenced from B then you would not get an error when linking with B dynamically. – john Jul 01 '20 at 07:03
  • 2
    Does this answer your question? [dllimport /dllexport and static libraries compilation under visual c++](https://stackoverflow.com/questions/4841719/dllimport-dllexport-and-static-libraries-compilation-under-visual-c) – dewaffled Jul 01 '20 at 08:53

0 Answers0