I'm trying to create a .dll and .lib files with VS2019 using this guide and load my library statically and dynamically.
I have dll project named dllSolution.
In my dllSolution there are standart framework.h, pch.h, dllmain.cpp, pch.cpp and my a.h file:
#pragma once
#ifdef DLLSOLUTION_EXPORTS
#define DLLSOLUTION_API __declspec(dllexport)
#else
#define DLLSOLUTION_API __declspec(dllimport)
#endif // !DLLSOLUTION_EXPORTS
#ifndef WINAPI
#define WINAPI __stdcall
#endif // !WINAPI
extern "C" DLLSOLUTION_API int WINAPI a();
with a.cpp:
#include "a.h"
#include "pch.h"
#ifndef WINAPI
#define WINAPI __stdcall
#endif // !WINAPI
int WINAPI a() { return 10; }
but when I build this project it produces no .lib file as if there is no export from library:
1>------ Rebuild All started: Project: dllSolution, Configuration: Debug Win32 ------
1>pch.cpp
1>a.cpp
1>dllmain.cpp
1>Generating Code...
1>dllSolution.vcxproj -> C:\CoolPathToMyDll\dllSolution\Debug\dllSolution.dll
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
I have tried to move implementation into dllmain.cpp with no result.
I also have tried to switch ConfigurationType to StaticLibrary(.lib) and fine, it generates .lib, but then, when I statically link my library to another project and use this a() in my main(), it says:
error LNK2019: unresolved external symbol __imp__a@0 referenced in function _main
What is the problem and why does this problem happen?