使用存根自动解决缺少库中未定义的引用?

发布于 2025-01-16 13:36:57 字数 404 浏览 1 评论 0原文

我正在为一个为 MSVC 开发的 C/(C++) 项目构建一些单元测试内容。我需要将其移植到 g++ / MinGw。有一个用 VS 构建的库(DLL)。我无法让这个库与其余代码链接,我总是收到未定义的引用错误。 MSVC 和 g++ 之间的名称管理似乎不兼容。不幸的是,我无法使用 g++ 重新编译该库,因为它使用了一些与 g++ (MFC/AFX) 不兼容的 Microsoft 东西。

所以我想知道是否有任何方法告诉 g++ 将所有未定义的引用替换为仅返回 0 或 Null 的简单存根函数。

因为我实际上并不需要任何函数,而且我什至不会调用调用任何缺失函数的函数。我只是想在那里有一些东西,以便项目可以在不更改我想要测试的代码的情况下进行编译。

有什么办法可以做到这一点吗?是否有一个工具可以提取所有公开的函数并创建一个仅包含存根函数的替换库?

I am building some unit testing stuff for a C/(C++) project that was developed for MSVC. I need to port it to g++ / MinGw. There is a library (DLL) that was build with VS. I can not get this library to link with the rest of the code, i always get undefined reference errors. It seems that the name mangeling between MSVC and g++ not compatible. Unfortunately I can not recompile the library with g++ because it uses some Microsoft Stuff that is incompatible with g++ (MFC/AFX).

So I wonder if there is any way to tell g++ to replace all undefined references with simple stub functions that just return 0 or Null.

Because I dont really need any of the functions, and I won't even call functions that call any of the missing functions. I just want to have something there so that the project compiles without changing the code that i want to test.

Is there any way to do that? Is there a tool that maybe extracts all the exposed functions and creates a replacement lib that only contains the stub functions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文