Re: Accessing file-scope variable from shared library ctor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 31 May 2013 21:45, Andy Falanga (afalanga) wrote:
>
> You've spoken what's taken me a few hours to find on my own.  I've attempted to fix this with things like:
>
> #include <string>
> #include <dlfcn.h>
>
> namespace {
>         std::string myPath __attribute__((init_priority(101)))("");
>         __attribute__((constructor(102)))
>         void SetPath() { ... }
> }

How does this relate in any way to what Florian said?

Did you try actually following the advice?

namespace {
std::string& getPath() { static std::string s; return s; }
}

void SetPath() {
    Dl_info dl_info;
    dladdr((void*)SetPath, &dl_info);
    getPath() = dl_info.dli_fname; // <-- segfault when built with
optimizations turned on
}




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux