Visual 2015 Compiling DLL
Visual 2015 Compiling DLL
我正在创建应该作为模块(运行时加载)的DLL
它适用于linux/windows与开放等。
它看起来像:
. cpp
std::string pomnoz(std::string &s, std::string &ds)
{
std::cout << s << " " << ds << std::endl;
return s.append(ds);
}
. h
#ifdef __cplusplus
extern "C"
{
#endif
std::string pomnoz(std::string &s, std::string &ds);
#ifdef __cplusplus
}
#endif
问题是,当我用g++编译它时,它生成了~480kb . dll,在windows/linux上工作没有问题(我传递2个字符串,它返回它)。
但是我不能使用g++,因为我在库中进一步使用c14。
在windows上,我使用VS2015,它创建了65kb . dll不工作(它加载但返回null而不是funcptr)。
我将尝试删除#ifdef __cplusplus
但一切都没有改变。
问题在哪里?我应该在构建选项中切换一些东西?
您缺少pomnoz
函数旁边的lexport:
__declspec(dllexport) std::string pomnoz(std::string &s, std::string &ds);
然后在你的应用程序中,你可以动态加载dll并检索导出函数的地址:
HMODULE lib = LoadLibrary(L"test.dll");
typedef std::string(*FNPTR)(std::string&, std::string&);
FNPTR myfunc = (FNPTR)GetProcAddress(lib, "pomnoz");
if (!myfunc)
return 1;
std::string a("a");
std::string b("b");
myfunc(a, b);
相关文章:
- 挂起和取消挂起一个文件DLL
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 导入库可以跨dll版本工作吗
- 从C++dll访问C#中的一行主要参数
- 链接到自行创建的dll失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- C++:将外部库链接到dll库
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 不同的Visual Studio版本中缺少.dll
- 从DLL中删除类的实例
- 如何包装第三方DLL在R中使用
- 使用c#访问c++dll中带有char*参数的函数时发生AccessViolationException
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- Compiling a DLL in C++ mingw 64
- Compiling a dll with g++
- Visual 2015 Compiling DLL