将用MASM制作的库调用到C或C ++ [英] Calling a library made in MASM to C or C++

查看:106
本文介绍了将用MASM制作的库调用到C或C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试调用用masm制作的c库. 我已经从程序集MASM制作了一个.lib文件. 但我不知道如何将其称为C语言库. 这是.lib文件 https://www.dropbox.com/s/d9d8cjbxmo51yqg/main.lib

需要帮助. 谢谢

解决方案

哦,天哪.巨大的陷阱.在Visual Studio中的32位masm .asm文件中,.model flat,c"是至关重要的.特别是"c". 64位masm汇编由于某种原因不需要它,因此可以正常工作.但是,如果您尝试从程序集的C ++或C代码中调用extern"C"定义的函数,则32位将不会链接,并且它将抱怨未解析的符号,无论在您的asm中定义了EXTERN符号:PROC.

与64位相比,这是一种奇怪的传统32位内容.

除此之外,对于您的问题,我想您只想声明自己的asm函数PUBLIC,只需在asm中声明"PUBLIC函数名",然后就不需要标头或其他任何东西,只需用调用C/C ++代码中的extern"或extern"C",它将在汇编对象和链接中找到它们.

i have been trying to call a library in c which was made in masm. I have managed to make a .lib file from assembly MASM. But i have no idea how to call it to C language as a library. Here is the .lib file https://www.dropbox.com/s/d9d8cjbxmo51yqg/main.lib

Help needed. Thanks

解决方案

Oh man. Huge gotcha on this. In a 32bit masm .asm file in visual studio, that ".model flat, c" is CRITICAL. ESPECIALLY the "c". 64 bit masm assembly doesn't need it for some reason it just works. But if you try to call extern "C" defined functions from your C++ or C code in your assembly, the 32 bit won't link and it will complain about unresolved symbols, regardless of defining EXTERN symbol: PROC in your asm.

It's some kind of weird legacy 32 bit thing versus the 64 bit.

Beside that, for your question, I think you just want to declare your asm functions PUBLIC, just "PUBLIC functionname" in your asm, and then you don't need a header or anything for them, just define them with "extern" or extern "C" in your calling C/C++ code and it will find them in the assembly object and link.

这篇关于将用MASM制作的库调用到C或C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆