可以从.h文件生成dlsym命令吗?

时间:2017-07-18 21:17:06

标签: c++ sdl sdl-2 dlopen dlsym

已经解决了! See the result here

不确定我是否在正确的位置询问,但有没有人知道基于.h文件生成dlopen和dlsym命令的正确方法?

我正在尝试动态加载SDL2 - 这是一个用C语言编写的库 - 但是用ctags提取函数列表及其参数的所有方法看起来都没有结果(必须手动纠正3500中240个函数的参数列表)有趣)。

ctags -R -x --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -f sdl /usr/include/SDL2/

ctags的结果如下所示:

extern DECLSPEC int SDLCALL SDL_SetTextureColorMod (SDL_Texture * texture,
extern DECLSPEC int SDLCALL SDL_SetThreadPriority (SDL_ThreadPriority priority);
extern DECLSPEC void SDLCALL SDL_SetWindowBordered (SDL_Window * window,

此:

ctags -R -x --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -f sdl /usr/include/SDL2/ | grep "SDL_AddTimer"

产生这种结果:

SDL_AddTimer     prototype    93 /usr/include/SDL2/SDL_timer.h extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,

注意间隔后缺少的参数。它坏了。

我也看到this是一个东西,它显然是自动生成的,而不是手工制作。

所以......有没有人知道有什么方法可以自动生成类似的东西?特别是对于SDL2?

或者我应该只使用SDL功能,并手动调用它们?不要问为什么我不愿意只使用dlopen和dlsym链接。

1 个答案:

答案 0 :(得分:3)

我通过使用decltype解决了这个问题。

typedef decltype(SDL_RenderDrawRects)* PF_SDL_RenderDrawRects;

这样,我不需要函数的参数列表。 The wrappers are found here