As part of learning C++, I wrote a simple class library + application that references it. Everything builds, except the class library does not generate a .lib file, which results in the application throwing a "LINK : fatal error LNK1104: cannot open file". This seems very reasonable; obviously, if a necessary file isn't there, there's an error and it's fatal. (Side note: I don't have a book yet)
So, I went looking for reasons a .lib file might not be generated. My search-fu, by the way, is rather weak. All I did find was that, if the library did not have any __declspec(dllexport) tags, it would not export a .lib.
I shall now post the header and .cpp contents of the class library (A simple "Console" class with one "Write(std::string)" method).
Header:
// Extensions.h
#pragma once
#include "stdafx.h"
namespace Extensions {
__declspec(dllexport) class Console
{
public:
__declspec(dllexport) static void Write(std::string text);
};
}
I am unsure whether I need to tag the function when I've tagged the class, but I can check that when it works.
And the .cpp file:
// This is the main DLL file.
#include "stdafx.h"
// #include "Console.h"
namespace Extensions {
void Console::Write(std::string text)
{
std::cout << text.c_str();
}
}
I've checked and it is set to generate a dynamic link library.
Thanks.