OSX Snow Leopard:静态和动态链接表现不同

时间:2011-11-16 17:12:19

标签: macos linker g++ 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();
  }

注意这段代码是“在”一个依赖库中(当然不是,它在头文件中!)

有什么想法吗?

0 个答案:

没有答案