0

I'm using an external library that I do not have control over, more precisely ADTF streaming library. I linked to this library in Visual Studio 2019 (using VS 2010 Platform Toolset). To do so, I added the include directory to

ProjectName -> Properties -> C/C++ -> General, 

the path to the folder containing the lib to

ProjectName -> Properties -> Linker -> General 

and the name of the lib (adtfstreamingD_280.lib) to

ProjectName -> Properties -> Linker -> Input.

No I get a linker error but only for static class methods, there is no linker error for non-static methods. Does anyone know how to resolve such a problem? Any help would be very appreciated.

My Code:

header file:

#ifndef _DAT_HANDLER_H_
#define _DAT_HANDLER_H_

#include <string>
#include <stdint.h>

#include "adtf_streaming.h"

class DatHandler
{
public:
    DatHandler();
    ~DatHandler();
    void Load(std::string datFilePath);
    int32_t GetNumOfStreams();

protected:

private:
    // Resources are handled by ADTF
    adtfstreaming::IADTFFileReader* m_fileReader;   

};
#endif // _DAT_HANDLER_H_

cpp file:

#include "DatHandler.h"

DatHandler::DatHandler() : m_fileReader(nullptr)
{
    // do nothing
}

DatHandler::~DatHandler()
{
    if (nullptr != m_fileReader)
    {
        m_fileReader->Close();
        adtfstreaming::IADTFFileReader::Release(m_fileReader);
    }
}

int32_t DatHandler::GetNumOfStreams()
{
    int32_t streamCount;
    tResult res = m_fileReader->GetStreamCount(streamCount);
    if (IS_FAILED(res))
    {
        return -1;
    }
    return streamCount;
}

void DatHandler::Load(std::string path)
{
    if (nullptr == m_fileReader)
    {
        m_fileReader = adtfstreaming::IADTFFileReader::Create();
    }
    else
    {
        m_fileReader->Close();
    }
    m_fileReader->Open(path.c_str());
}

The errors (in German, don't know how to get Error output in English):

Error   LNK2019 Verweis auf nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: static long __cdecl adtfstreaming::IADTFFileReader::Release(class adtfstreaming::IADTFFileReader *)" (__imp_?Release@IADTFFileReader@adtfstreaming@@SAJPAV12@@Z)" in Funktion ""public: __thiscall DatHandler::~DatHandler(void)" (??1DatHandler@@QAE@XZ)".

Error   LNK2019 Verweis auf nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: static class adtfstreaming::IADTFFileReader * __cdecl adtfstreaming::IADTFFileReader::Create(void)" (__imp_?Create@IADTFFileReader@adtfstreaming@@SAPAV12@XZ)" in Funktion ""public: void __thiscall DatHandler::Load(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Load@DatHandler@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)".

Error   LNK1120 2 nicht aufgelöste externe Verweise.    

Edit: Maybe I also should have mentioned that I only have ADTF streaming library 2.8.0 available.

Tobias Brösamle
  • 598
  • 5
  • 18
  • Does this answer your question? [Linking a library fails with LINK1181 on VS17](https://stackoverflow.com/questions/58605032/linking-a-library-fails-with-link1181-on-vs17) – Alan Birtles Nov 27 '19 at 15:48
  • @Alan: I tried defining STREAMINGLIB_EXPORTS, but it didn't work. Also, I do not have linker error 1181. The accepted answer suggests building the streaming lib fox x64, but honestly, I don't exactly know how I should do that missing the .cpp files. – Tobias Brösamle Nov 27 '19 at 16:06
  • I honestly do not think it's a duplicate of the linked question. There, the .lib file could not be found, which doesn't seem to be a problem here. In my case, only static methods are problematic while linking. – Tobias Brösamle Nov 27 '19 at 16:13
  • As far as I'm concerned you may not define static members of the class. A static class member must have a unique definition, or it will violate the one-definition rule. A static class member that can't be defined inline must be defined in one source file by using its fully qualified name. If it isn't defined at all, the linker generates LNK2019. And you might also define the symbol as static and then reference it outside the file.For more details I suggest you could refer to the link:https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2019?view=vs-2019 – Jeaninez - MSFT Nov 28 '19 at 02:18
  • @MSFT: But it should be compiled in the lib, right? I mean, ADTF itself also uses the same library, i.e. it should work in principal. – Tobias Brösamle Nov 28 '19 at 07:26
  • I suggest you could try to add the code: `#pragma comment(lib, "adtfstreamingD_280.lib");` – Jeaninez - MSFT Dec 03 '19 at 02:22
  • @Jeaninez-MSFT: this is already done by the included header file. – Tobias Brösamle Dec 09 '19 at 14:29

1 Answers1

0

Despite all the comments to my question and the linked answers, I was not able to make it work using just Visual Studio.

However, after setting up a CMake project, it worked out of the box. So I guess the easiest way to make the ADTF streaming library work is creating a CMake project.

As the streaming library is located in external/adtf-streaminglib, the following two lines of code are all that's necessary in CMake:

find_package(ADTF_STREAMING 2.8.0 PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/adtf-streaminglib REQUIRED)
target_link_libraries(TARGET ${ADTF_STREAMING_LIB})

The variable ${ADTF_STREAMING_LIB} is defined by the found package. I have no idea why I couldn't link the library correctly with Visual Studio, I can only guess that using CMake, some more parameters are set that I could not find in Visual Studio or that are not available there.

Tobias Brösamle
  • 598
  • 5
  • 18