Invoking a build procedure from C ++ code using Visual Studio

Stuck with Visual Studio, Assembly, and C ++

C ++:

extern "C" void asm_calculate_reals();
int main()
{
   asm_calculate_reals();
   return 0;
}

Assembly:

PUBLIC _asm_calculate_reals
.386
.model flat, stdcall
option casemap :none
.stack 100h
.code
_asm_calculate_reals PROC
   ;code goes here
   ret
_asm_calculate_reals ENDP
end

When I create my project, Visual Studio reports the following error:

error LNK1120 error lnk1120 1 unresolved externals

In fact, I can’t understand what is wrong with this easy part of the program.

Log file:

Build started 16.04.2015 16:53:21.
     1>Project "somepath\Reals loop 3variants.vcxproj" in node 2 (targets Build).
     1>Link:
         somepath\link.exe /ERRORREPORT:PROMPT /OUT:"somepath\Debug\Reals loop 3variants.exe" /INCREMENTAL /NOLOGO somelibs /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"somepath\Debug\Reals loop 3variants.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"somepath\Debug\Reals loop 3variants.lib" /MACHINE:X86 /SAFESEH:NO Debug\main.obj
         Debug\reals.obj
     1>main.obj : error LNK2019: reference to the unresolved external symbol _asm_calculate_reals in function _main
     1>somepath\Debug\Reals loop 3variants.exe : fatal error LNK1120: unresolved identifiers: 1
     1>Building project "somepath\Reals loop 3variants.vcxproj" finished (targets Build) with errors.

Build failed.
+4
source share
2 answers

The real problem was defining the model inside the assembly source.

.model flat, stdcall - an error has occurred.

.model flat, c - The transition to this, works as expected.

+1
source

Try adding this line to your assembly code - global _asm_calculate_reals- Make this visible to the linker. The "global" keyword in the assembly tells the assembler to make the shortcut visible outside the file.

0
source

All Articles