相关疑难解决方法(0)

为什么Apple clang在'官方'clang支持时不允许使用C++ 11 thread_local

下面是一个简单的程序,它在共享库中使用非POD类型的C++ 11 thread_local变量进行测试.

如果我使用自制软件,这很好用:

> /usr/local/Cellar/llvm/3.5.0_2/bin/clang --version                                          
clang version 3.5.0 (tags/RELEASE_350/final)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

> cmake .. -G Ninja -DCMAKE_C_COMPILER=/usr/local/Cellar/llvm/3.5.0_2/bin/clang -DCMAKE_CXX_COMPILER=/usr/local/Cellar/llvm/3.5.0_2/bin/clang++
-- The C compiler identification is Clang 3.5.0
-- The CXX compiler identification is Clang 3.5.0
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Ninja
-- …
Run Code Online (Sandbox Code Playgroud)

xcode clang c++11

23
推荐指数
1
解决办法
1万
查看次数

C++强制卸载共享库

我正在尝试创建一个多次重新加载共享库的应用程序.但在某个时间点,dlmopen失败并出现错误

/usr/lib/libc.so.6: cannot allocate memory in static TLS block

以下是重现此问题的最小代码:

#include <dlfcn.h>
#include <cstdio>
#include <vector>

int main() {
  for (int i = 0; i < 100; ++i) {
    void *lib_so = dlmopen(LM_ID_NEWLM, "lib.so", RTLD_LAZY | RTLD_LOCAL);
    if (lib_so == NULL) {
      printf("Iteration %i loading failed: %s\n", i, dlerror());
      return 1;
    }
    dlclose(lib_so);
  }

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

并清空lib.cpp,用.编译

g++ -rdynamic -ldl -Wl,-R . -o test main.cpp
g++ -fPIC -shared lib.cpp -o lib.so
Run Code Online (Sandbox Code Playgroud)

更新

它似乎即使用一个线程也会崩溃.问题是:如何强制库卸载或销毁使用的未使用的命名空间LM_ID_NEWLM

c++ linux shared-libraries

8
推荐指数
1
解决办法
1333
查看次数

标签 统计

c++ ×1

c++11 ×1

clang ×1

linux ×1

shared-libraries ×1

xcode ×1