0

here is my assembly code. it's not the actual code, but it does not matter what the function is, i get the same error.

.model flat, c

.code

function proc
retn
function endp

end

i tried:

  • typing "public function" after the "endp"
  • making it an __stdcall
  • changing the name. adding and removing _ in multiple places

what i did:

  • changed build configuration to include MASM files
  • made sure the .asm file is not excluded from the build

i keep getting an error saying "unresolved external symbol".

thing is, it also seems to add a _ before the actual function name, which is why i tried changing things around and adding _ before the functions myself, but it did not work.

what can i do?

this is how i import it:

extern "C" unsigned int function();
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
tb044491
  • 144
  • 7
  • 1
    How are you linking this? Is this Visual C++? – David Wohlferd May 18 '20 at 22:42
  • yeah, i'm using VS2017 – tb044491 May 18 '20 at 22:43
  • Are you certain the asm file is actually building? I seem to recall having to set it as a custom tool, that .asm files are not recognized by default. Check the file properties page under the General page and "Item type" line. If I'm correct that msbuild doesn't have an existing target for asm files you'll have to change it to custom build tool and write an ml/ml64 command yourself. – SoronelHaetir May 18 '20 at 22:47
  • Something like [this](https://stackoverflow.com/a/43038502/2189500)? – David Wohlferd May 18 '20 at 22:48
  • @DavidWohlferd that's exactly what i did. i am experiencing new issues now. if i put `_` before the function name in the .asm file, i get an unresolved external symbol error for every one of the functions in the class that follows the `extern "C"`. if i put it inside the .cpp file, and not the .hpp file, i get the same unresolved external symbol for the asm function – tb044491 May 18 '20 at 22:50
  • @SoronelHaetir it says "Microsoft Macro Assembler" – tb044491 May 18 '20 at 22:51
  • Besides adding the `_` in the ASM file (and not the C++ file) you will have to mark the labels public so they can be seen by other modules: https://learn.microsoft.com/en-us/cpp/assembler/masm/public-masm?view=vs-2019 – Michael Petch May 18 '20 at 22:54
  • @MichaelPetch i mentioned in my OP that after the function declaration, i put "public + the name of the function", and it still does not work. – tb044491 May 18 '20 at 22:56
  • I know you did, but you said you "tried it", but it is unclear if you tried all three things at the same time - a PUBLIC statement; added the under score to each ASM label you want make public (**DO NOT add an `_` in the C++ code!**); and used `extern "C"` to remove C++ name mangling. – Michael Petch May 18 '20 at 22:58

0 Answers0