Не удается динамически подгрузить библиотеку, собранную с MinGW и CMake в CLion
Собрал свою библиотеку в CLion с помощью MinGW (x86) и CMake. Далее собрал программу, в которую можно динамически подгружать dll-библиотеки (тоже x86). В результате получаю сообщение об ошибке (GetLastError возвращает ошибку 126).
"Library libshared not found! Error is: 126"
Подскажите, пожалуйста, в чем может быть проблема?
Код этой программы:
#include <iostream>
#include <Windows.h>
#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
typedef int (*function)(int a);
std::wstring s2ws(const std::string& s) {
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
int main() {
string name;
cout << "Enter the name of library: ";
cin >> name;
wstring stemp = s2ws(name);
LPCWSTR result = stemp.c_str();
HMODULE hm = LoadLibrary(result);
if (hm == NULL) {
cout << "Library " << name << " not found! Error is: " << GetLastError() << endl;
system("pause");
}
else {
cout << "Library " << name << " is loaded" << endl;
function add = (function)GetProcAddress(hm, "hello");
add(321);
}
FreeLibrary(hm);
_getch();
return 0;
}
Код моей dll-библиотеки:
#include <iostream>
extern "C" void __declspec(dllexport) f();
void f() {
std::cout << "Test";
}
Код CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(sharedLibsDemo)
add_library(shared SHARED shared.cpp)