Can't Call MASM functions from CPP?

Hritik Shahi 20 Reputation points
2024-07-14T04:31:57+00:00

I recently started to Learn x64 MASM. I'm using Visual Studio 2022.

I wrote a simple function in assembly ..

.code
funcCall proc
	ret
funcCall endp
end

I tried calling it from C++ file:

#include <iostream>

extern "C" int funcCall(int c);

int main()
{
	std::cout<<funcCall(5);
}

I get these Errors, But the Tutorial I'm following it works just fine.

1>MSVCRT.lib(error.obj) : error LNK2019: unresolved external symbol strcpy_s referenced in function "void __cdecl _RTC_StackFailure(void *,char const *)" (?_RTC_StackFailure@@YAXPEAXPEBD@Z)
09:55:00:890	1>MSVCRT.lib(error.obj) : error LNK2019: unresolved external symbol strcat_s referenced in function "void __cdecl _RTC_StackFailure(void *,char const *)" (?_RTC_StackFailure@@YAXPEAXPEBD@Z)
09:55:00:890	1>MSVCRT.lib(error.obj) : error LNK2019: unresolved external symbol __stdio_common_vsprintf_s referenced in function _vsprintf_s_l
09:55:00:890	1>MSVCRT.lib(error.obj) : error LNK2001: unresolved external symbol __C_specific_handler_noexcept
09:55:00:890	1>MSVCRT.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __vcrt_GetModuleFileNameW referenced in function "int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)" (?_RTC_GetSrcLine@@YAHPEAEPEA_WKPEAH1K@Z)
09:55:00:890	1>MSVCRT.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __vcrt_LoadLibraryExW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDllFromInstallPath(void)" (?GetPdbDllFromInstallPath@@YAPEAUHINSTANCE__@@XZ)


How can I fix these ?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,176 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,755 questions
{count} votes

Accepted answer
  1. RLWA32 45,691 Reputation points
    2024-07-14T08:06:20.88+00:00

    @Hritik Shahi I expect that there were many more linker errors than the few that you posted. I can reproduce the problem by changing the defaults for linker inputs in an empty project.

    The following errors were produced when using the linker inputs shown in the image below. There were many more errors that were not included in the image but the ones shown seem to be identical to your post.

    LinkerErrors

    Linker inputs-

    LinkerInput

    A debug build requires the debug version of the CRT library -- msvcrtd.lib.

    Also, as far as I can see there is no reason to ignore default libraries. Let VC++ include the correct versions for you.

    There were no linker errors when the following was used. Func.obj is the output from the x64 assembler.

    LinkerSuccess

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.