I'm working with assembly code for the first time for a school project and I'm having some issues getting Visual Studio 2005 to play ball.

I have two very basic files I'm working with:

main.cpp
extern void clear();

int main() {
clear();
return 1;
}


factorial.asm
.586              ;Target processor.  Use instructions for Pentium class machines
.MODEL FLAT, C    ;Use the flat memory model. Use C calling conventions
.STACK            ;Define a stack segment of 1KB (Not required for this example)
.DATA            ;Create a near data segment.  Local variables are declared after
                  ;this directive (Not required for this example)
.CODE            ;Indicates the start of a code segment.

clear PROC
  xor eax, eax
  xor ebx, ebx
  ret
clear ENDP
END


All I'm trying to do is get this to build in Visual Studio. My professor provided a tutorial on how to do this in 2003, and it seems like that should translate to 2005, but I just keep getting linking errors. I can only assume the problem is that when an attempt is made to compile main.cpp, the object file I generate from factorial.asm is not in the expected location. I changed around the custom build settings to get factorial.obj to end up in the Debug directory, and now the unresolved externals error has turned into the following:

Error 1 fatal error LNK1104: cannot open file '..\debug\factorial.obj,factorial.obj' PS7

From this it now looks like Visual Studio is trying to find the file in every single place except where it's actually at.

This makes absolutely no sense to me. Can anyone point me in the right direction?
Posted on 2006-04-15 15:56:01 by ^eMpTy^
What is your command line ? It should work with /Fo"$(IntDir)\$(InputName).obj"

With VS2005 you can also use a custom build rule.
Posted on 2006-04-15 23:52:22 by Dr. Manhattan
here's what i did, maybe it helps:
Posted on 2006-04-16 05:31:16 by tofu-sensei
You have a .cpp file, and thus the default for externs is to use C++-style name decoration. What you need is...


extern "C" void clear();

int main() {
clear();
return 1;
}


If you're going to import a bunch of things, you can do


extern "C"

  void clear();
  int foo();
  char bar(int parm);
}

Posted on 2006-04-16 06:21:08 by f0dder
so how do I make it work then? modify the code I mean?
Posted on 2006-04-16 11:03:23 by para
As I showed you :)

instead of
extern void clear();
you must do
extern "C" void clear();

Also, that "clear" function can cause you a LOT of trouble - EBX, ESI, EDI must be preserved in external functions.
Posted on 2006-04-16 11:05:52 by f0dder