根据我的研究,我发现gnu c默认使用cdecl进行函数调用。vst sdk在使用gnu c编译时显式地将调用定义为cdecl,并指出以下错误:
again.cpp:27:15: warning: multi-character character constant [-Wmultichar]
In file included from /code/vstsdk2.4/public.sdk/source/vst2.x/audioeffect.h:16:0,
from /code/vstsdk2.4/public.sdk/source/vst2.x/audioeffectx.h:17,
from again.h:16,
from again.cpp:13:
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:125:32: error: expected ')' before '*' token
In file included from /code/vstsdk2.4/public.sdk/source/vst2.x/audioeffect.h:16:0,
from /code/vstsdk2.4/public.sdk/source/vst2.x/audioeffectx.h:17,
from again.h:16,
from again.cpp:13:
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:126:32: error: expected ')' before '*' token
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:127:27: error: expected ')' before '*' token
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:128:27: error: expected ')' before '*' token
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:129:27: error: expected ')' before '*' token
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:130:28: error: expected ')' before '*' token
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:149:2: error: 'AEffectDispatcherProc' does not name a type
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:152:2: error: 'AEffectProcessProc' does not name a type
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:155:2: error: 'AEffectSetParameterProc' does not name a type
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:158:2: error: 'AEffectGetParameterProc' does not name a type
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:183:2: error: 'AEffectProcessProc' does not name a type
/code/vstsdk2.4/pluginterfaces/vst2.x/aeffect.h:187:2: error: 'AEffectProcessDoubleProc' does not name a type
In file included from /code/vstsdk2.4/public.sdk/source/vst2.x/audioeffectx.h:17:0,
from again.h:16,
from again.cpp:13:
/code/vstsdk2.4/public.sdk/source/vst2.x/audioeffect.h:27:35: error: expected ')' before 'audioMaster'
In file included from /code/vstsdk2.4/public.sdk/source/vst2.x/audioeffectx.h:17:0,
from again.h:16,
from again.cpp:13:
/code/vstsdk2.4/public.sdk/source/vst2.x/audioeffect.h:155:2: error: 'audioMasterCallback' does not name a type
In file included from again.h:16:0,
from again.cpp:13:
/code/vstsdk2.4/public.sdk/source/vst2.x/audioeffectx.h:27:36: error: expected ')' before 'audioMaster'
In file included from again.cpp:13:0:
again.h:22:29: error: expected ')' before 'audioMaster'
again.cpp:16:36: error: 'audioMasterCallback' was not declared in this scope
again.cpp:17:1: error: expected ',' or ';' before '{' token
again.cpp:22:14: error: expected constructor, destructor, or type conversion before '(' token
scons: *** [again.os] Error 1
scons: building terminated because of errors.
同时,当我删除显式定义cdecl并让编译器决定时,它编译时没有一个问题。这是否应该抛出相同的错误,因为默认值是cdecl?
我在维基百科上读到,在cdecl的情况下,“由于gcc版本4.5,在调用函数时堆栈必须与16字节边界对齐(以前的版本只需要4字节对齐)”,这是否能为我的问题提供一个洞察和可能的原因?
另外,当我将其定义为“快速调用”或“stdcall”时,也会遇到同样的错误。那么这里到底发生了什么?
最佳答案
我不喜欢直接修改源代码,因为在尝试维护多个平台时会遇到麻烦。相反,我将-D__cdecl=""
传递给编译器标志来定义它。
我用这种方法在linux上构建了一些vst,它工作得很好。你应该安全地定义掉(或者手动删除,如果你愿意的话)显式的cdecl。vst sdk在这个意义上有点迟钝,特别是它认为世界上只有两个操作系统值得支持,mac和windows。如果查看aeffect.h
,您将发现以下代码:
#if TARGET_API_MAC_CARBON
#ifdef __LP64__
#pragma options align=power
#else
#pragma options align=mac68k
#endif
#define VSTCALLBACK
#elif defined __BORLANDC__
#pragma -a8
#elif defined(__GNUC__)
#pragma pack(push,8)
#define VSTCALLBACK __cdecl
#elif defined(WIN32) || defined(__FLAT__) || defined CBUILDER
#pragma pack(push)
#pragma pack(8)
#define VSTCALLBACK __cdecl
#else
#define VSTCALLBACK
#endif
所以基本上,解决这个问题的最好办法就是取消CDECL的定义。gcc应该可以很好地编译代码。
关于linux - Steinberg VST SDK使用g++ cdecl调用约定,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10789012/