Cygwin gcc - asm 错误:
我有一个用C编写的项目,最初是在Linux上完成的,但现在必须在Windows上完成。部分代码在多个地方包含此行,
asm("movl temp, %esp");
但这会导致“对‘temp’的未定义引用”错误。
使用 gcc 4.3.2 编译器(在另一台机器上测试)在 Linux 上编译没有问题,这是我在 Cygwin 上的版本。还有其他方法可以完成这条线正在做的事情吗?
I have a project written in C that originally was being done on Linux, but now must be done on Windows. Part of the code include this line in several places
asm("movl temp, %esp");
But that causes an "undefined reference to `temp'" error.
This has no problem compiling on Linux using the gcc 4.3.2 compiler (tested on another machine), which is the version I have on Cygwin. Is there another way to accomplish what this line is doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将 cygwin 版本从 更改
为
是,它是相同的编译器和汇编器,但它们的设置不同以与主机系统兼容。
您可以通过简单地告诉 gcc 要使用的特定名称来隔离系统相关的符号前缀:
这避免了某种 #if 并删除了主机操作系统依赖项,但添加了编译器依赖项。说到编译器扩展,有些人会写(参见
info as
):这里的想法是,这种语法允许编译器通过查找
temp
来帮助您,即使它位于寄存器中或需要一些指令来加载,并且为了避免与您发生冲突,它可能使用的是您破坏的寄存器。它需要这个,因为编译器不会以任何方式解析普通的 __asm__()。就您而言,您似乎正在实现自己的线程包,因此这些都不重要。 Gcc 不打算使用 %esp 进行计算。 (但为什么不直接使用 pthreads...?)
You need to change the cygwin version from
to
Yes, it's the same compiler and assembler but they are set up differently for compatibility with the host system.
You can isolate the system-dependent symbol prefixing by simply telling gcc a specific name to use:
This avoids an #if of some sort and removes a host OS dependency but adds a compiler dependency. Speaking of compiler extensions, some people would write (see
info as
) something like:The idea here is that this syntax allows the compiler to help you out, by finding
temp
, even if it's lying about in a register or takes a few instructions to load, and also to avoid conflicting with you, it case it was using a register you clobbered. It needs this because a plain__asm__()
is not parsed in any way by the compiler.In your case, you seem to be implementing your own threading package, and so none of this really matters. Gcc wasn't about to use %esp for a calculation. (But why not just use pthreads...?)