I am working on a dynamic library that gets included in a larger project. To be able to run it on Windows and Linux, I wanted to try to set up type aliasing
with char
and wchar_t
depending on if there is UNICODE or not. However, when trying to build the main project I am running into linking errors.
error LNK2019: unresolved external symbol
.
The import worked previously, but after introducing the type aliasing (see types.h), I start getting linking errors.
export
#pragma once
#if defined(IO_EXPORTS)
#define IO_API __declspec(dllexport)
#else
#define IO_API __declspec(dllimport)
#endif
types.h
#pragma once
#include "export"
#include <fstream>
#include <string>
namespace IO
{
#ifdef UNICODE
using T = wchar_t;
#else
using T = char;
#endif
using string = std::basic_string<T>;
} // namespace IO
manager.h
#pragma once
#include "types.h"
#include "export"
namespace IO
{
class IO_API Manager
{
size_t read(IO::String filename) { // do some stuff };
};
} // namespace IO
The entire linking message:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct IO::Result __thiscall IO::Manager::read(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >)" (__imp_?read@Manager@IO@@QAE?AUResult@2@V?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z) referenced in function "private: void __thiscall std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >::_Construct<1,unsigned short const *>(unsigned short const * const,unsigned int)" (??$_Construct@$00PBG@?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@AAEXQBGI@Z)
Note that I am not 100% sure the type aliasing is causing the issue, but I cannot think of another reason the error suddenly appear, since I have not changed much else. Could it be possible that it causes the errors, and if so, what do I need to do differently?