Redian新闻
>
Call assembly in c++ under linux
avatar
Call assembly in c++ under linux# Programming - 葵花宝典
G*m
1
I'm writing some code which needs to call assembly function in C++ code.
it works fine under windows, however, it does not work under linux, i googled
lot, could not figure out the problem, can anybody help me out of this.
Here is the code.
// header file a.h
#define __ASM_NAME(name) "_" name
#define __ASM_TYPE(name) ".type " __ASM_NAME(#name) ",@function\n"
#define __ASM_GLOBAL_FUNC(name,code) \
__asm__( ".align 4\n\t" \
".globl " __ASM_NAME(#name) "\n\t" \
avatar
t*t
2
Sorry I can't write chinese.
This is most probably name inconsistent problem, including c++ name mangling
and assembly naming convention.
It seems in your original "windows" program, you used __ASM_NAME to write
name, which is just put underscore before name. This is traditional and you
said it worked. I am not very sure about windows executable naming convention,
but I heard it does use this prefix underscore. Seems there's no c++ name
mangling problem here, did you put extern "C" {} around you

【在 G***m 的大作中提到】
: I'm writing some code which needs to call assembly function in C++ code.
: it works fine under windows, however, it does not work under linux, i googled
: lot, could not figure out the problem, can anybody help me out of this.
: Here is the code.
: // header file a.h
: #define __ASM_NAME(name) "_" name
: #define __ASM_TYPE(name) ".type " __ASM_NAME(#name) ",@function\n"
: #define __ASM_GLOBAL_FUNC(name,code) \
: __asm__( ".align 4\n\t" \
: ".globl " __ASM_NAME(#name) "\n\t" \

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。