Adding LD_PRELOAD to 'run' executable in CLion

Starl1ght Source

When I compile my test application in CLion with gcc 6.2, it outputs

/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.21' not found
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.9' not found

Which is obvious, since I am using gcc 4.8 as system compiler, and gcc 6.2 resides in my home folder, and compiled program is using my system libs.

Obvious solution here is to use LD_PRELOAD, which is working fine, when I am running my compiled app via console.

The question: What shall I put into CMakeList.txt in CLion, so, when I click "Run" in CLion - my compiled app executes as "LD_PRELOAD=something ./myApp" instead of just "./myApp"

c++cmakeclion

Answers

answered 1 year ago Starl1ght #1

Well, helped myself. Added environment variable in build configuration for project in CLion. enter image description here

answered 1 year ago yugr #2

When I compile my test application in CLion with gcc 6.2, it outputs

I guess you mean "when I run my test application". That happens because your app was linked to newer version of libstdc++ but can only find older one at startup.

What shall I put into CMakeList.txt in CLion, so, when I click "Run" in CLion - my compiled app executes as "LD_PRELOAD=something ./myApp" instead of just "./myApp"

You either need to run your app with modified LD_LIBRARY_PATH (so that it points to 6.2's libstdc++, not 4.8's) or build with custom rpath:

 gcc -Wl,-rpath=/path/to/new/libstdc++ ...

comments powered by Disqus