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?
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…?)