在Visual Studio项目中使用_penter函数会导致堆栈溢出

问题描述

我遵循了official guide,使用命令提示符分别编译代码输出二进制文件运行良好。 但是为了将这些代码放在一起,我编写了一个标题profile.h

#pragma once
#include <stdio.h>

extern "C" void __declspec(naked) __cdecl _penter(void) {
    _asm {
        push eax
        push ebx
        push ecx
        push edx
        push ebp
        push edi
        push esi
    }

    printf_s("\nIn a function!");

    _asm {
        pop esi
        pop edi
        pop ebp
        pop edx
        pop ecx
        pop ebx
        pop eax
        ret
    }
}

一个cpp,profile.cpp

#include<stdio.h>
#include "profile.h"


void blabla() {

}
int main()
{
    blabla();
}

并在配置属性> C / C ++>命令行属性页>其他选项中添加/Gh选项。

但是,运行输出始终会导致堆栈溢出错误似乎_penter函数不断调用自身。 我尝试了另一种方法,使用cl编译_penter函数(就像官方指南一样,输出是penter.obj),然后将其复制到Visual Studio项目中,在项目配置属性中,添加其他选项/Gh penter.obj 但是这种方法不起作用,penter.obj会导致许多编译错误

那么,如何正确使用/ Gh选项?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)