OSX Snow Leopard:静态和动态链接的行为不同
我有一些如下结构的代码:
固定主线 - >用户代码->依赖库
这三个部分可以静态链接就万事大吉了。 或者,主线可以变成可执行文件 并将用户代码放入dylib中,主线加载 使用 dlopen() 输入用户代码并使用 dlsym() 输入它。
我有数百个测试程序,这些程序运行良好,但有两种情况 失败的地方:
- 情况1:依赖库是gmpxx(依赖于gmp)。
- 情况 2:依赖库是 SDL
在 gmp 情况下,动态程序会打印正确的答案,然后终止:
flx_run(29601) malloc: *** error for object 0x7fff712ac500: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Abort trap (gdb) bt #0 0x00007fff8438e0b6 in __kill () #1 0x00007fff8442e9f6 in abort () #2 0x00007fff84346195 in free () #3 0x00000001000d3a35 in flxusr::gmp__hyphen_0::_init_ () Previous frame inner to this frame (gdb could not unwind past this frame)
我猜想这里存在一些内存损坏。
在 SDL 情况下:
~/felix>LD_LIBRARY_PATH=build/release/lib/rtl build/release/bin/flx_arun demos/sdl/sdl-1.01.03-0.dylib frames in seconds = FPS frames in seconds = FPS frames in seconds = FPS
而
~/felix>demos/sdl/sdl-1.01.03-0 98 frames in 5.016 seconds = 19.5375 FPS 100 frames in 5.043 seconds = 19.8295 FPS 82 frames in 5.043 seconds = 16.2602 FPS
帧速率数据的格式是通过
_urv20946 = ::flx::rtl::strutil::str(((double)PTF Frames / seconds ));
注意到
template<class T> string str(T const &t) { std::ostringstream x; x << t; return x.str(); }
此代码位于依赖库“中”(当然不是,它位于头文件中!)
有什么想法吗?
I have some code structured like this:
Fixed mainline -> user code -> dependent library
These three parts can be statically linked and all is well.
Alternatively, the mainline can be turned into an executable
and the user code into a dylib, and the mainline loads the
user code with dlopen() and enters it with dlsym().
I have hundreds of test programs where this works fine, but two cases
where it fails:
- Case 1: the dependent library is gmpxx (which depends on gmp).
- Case 2: the dependent library is SDL
In the gmp case the dynamic program prints the correct answers by then terminates with:
flx_run(29601) malloc: *** error for object 0x7fff712ac500: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Abort trap (gdb) bt #0 0x00007fff8438e0b6 in __kill () #1 0x00007fff8442e9f6 in abort () #2 0x00007fff84346195 in free () #3 0x00000001000d3a35 in flxusr::gmp__hyphen_0::_init_ () Previous frame inner to this frame (gdb could not unwind past this frame)
I would guess some memory corruption is here.
In the SDL case:
~/felix>LD_LIBRARY_PATH=build/release/lib/rtl build/release/bin/flx_arun demos/sdl/sdl-1.01.03-0.dylib frames in seconds = FPS frames in seconds = FPS frames in seconds = FPS
whereas
~/felix>demos/sdl/sdl-1.01.03-0 98 frames in 5.016 seconds = 19.5375 FPS 100 frames in 5.043 seconds = 19.8295 FPS 82 frames in 5.043 seconds = 16.2602 FPS
The frame rate data is formatted by
_urv20946 = ::flx::rtl::strutil::str(((double)PTF Frames / seconds ));
where
template<class T> string str(T const &t) { std::ostringstream x; x << t; return x.str(); }
noting this code is "in" a dependent library (well of course not, it is in a header file!)
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论