gpt4 book ai didi

为 Labview 创建 DLL

转载 作者:太空宇宙 更新时间:2023-11-04 08:28:10 24 4
gpt4 key购买 nike

我有一个 c 项目,我使用 Mingw gcc 编译器从中创建了一个 .exe。我需要为labview制作一个dll。我已经阅读了不同的位置如何做到这一点,但似乎没有人完全告诉我这是如何完成的。

我添加了编译器设置-shared

enter image description here

然后我能够成功加载 dll 并在其他 C 项目和 labview 中使用这些函数。

但是所有函数在labview中都是可见的,我还没有添加

__declspec(dllexport)

例如在 Mingw 网站上我被告知要这样做。

我是否正确地完成了此操作,还是这里可能出现问题?

最佳答案

在 gcc 中,默认情况下会导出所有符号(函数)。大多数指南都基于 Visual Studio,情况并非如此。

然而,可以通过禁用默认导出来强制控制导出的符号。这可以通过传递来完成。

-fvisibility=hidden

对编译器的每次调用。并随后用 标记导出的函数。

__attribute__ ((dllexport))

就像您使用 declspec 一样。这样做有好处,下一页对此有更好的解释。 https://gcc.gnu.org/wiki/Visibility

编辑:我看到使用 mingw 改变了一点。

If you pass the -no-undefined and --enable-runtime-pseudo-reloc options to the linker, you don't have to add dllimport or dllexport attributes to the source code that the DLL is made with ; all functions are imported/exported automatically by default, just like in unices.

发件人:http://www.mingw.org/wiki/sampledll

您是否将这些标志中的任何一个传递给链接器?

关于为 Labview 创建 DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29487515/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com