Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLion: running kdb in debug mode #2766

Closed
alexsaber opened this issue Jun 9, 2019 · 16 comments

Comments

Projects
None yet
5 participants
@alexsaber
Copy link
Contributor

commented Jun 9, 2019

Steps to Reproduce the Problem

I followed the newly created tutorial to run kdb in debug mode in CLion --> https://github.com/ElektraInitiative/libelektra/blob/master/doc/tutorials/contributing-clion.md

I was able to build the project successfully. But I fail to run it afterward.

I found this issue where the same problem was discussed. #1233

However, when I execute, libelektra-core.so file seems to be missing.

readelf -a /usr/lib/libelektra-core.so | grep RPATH
#> readelf: Fehler: '/usr/lib/libelektra-core.so': Keine solche Datei

How can I fix this problem?

Expected Result

Use the CLion debugger

Actual Result

/home/osboxes/TU/libelektra/cmake-build-debug/bin/kdb mount test.ini user/tests/ini ini
The command /home/osboxes/TU/libelektra/cmake-build-debug/bin/kdb mount failed while accessing the key database with the info:
Sorry, 1 warning was issued ;(
Warning (#1):
Description: could not load module, dlopen failed
Module: dl
At: /home/osboxes/TU/libelektra/src/libs/loader/dl.c:89
Reason: of module: libelektra-resolver.so, because: libelektra-resolver.so: cannot open shared object file: No such file or directory
Mountpoint:
Configfile:
Sorry, the error (#40) occurred ;(
Description: failed to open default backend (see warnings for more information)
Reason: could not open default backend
Module:
At: /home/osboxes/TU/libelektra/src/libs/elektra/kdb.c:290
Mountpoint:
Configfile:

Process finished with exit code 5

@markus2330

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

Thank you for reporting this problem!

However, when I execute, libelektra-core.so file seems to be missing.

If you do not install Elektra, the binaries are obviously only in the build directory.

But this should already be enough. When I want to run binaries from the build directory I use . ~e/scripts/run_dev_env which should fix your problem, in your case this should be (if libelektra contains the source dir):

cd /home/osboxes/TU/libelektra/cmake-build-debug
. /home/osboxes/TU/libelektra/scripts/run_dev_env
/home/osboxes/TU/libelektra/cmake-build-debug/bin/kdb mount test.ini user/tests/ini ini

@e01306821 did you also run into this problem?

Of course it would be nice if run_dev_env would already be sourced from CLion.

@kodebach any idea how run_dev_env from within CLion?

@alexsaber

This comment has been minimized.

Copy link
Contributor Author

commented Jun 10, 2019

@markus2330
Thank you very much!

cd /home/osboxes/TU/libelektra/cmake-build-debug
. /home/osboxes/TU/libelektra/scripts/run_dev_env
/home/osboxes/TU/libelektra/cmake-build-debug/bin/kdb mount test.ini user/tests/ini ini

I confirm that it works. However I still need to attach the CLion debugger somehow. I tried to attach to the process running the script by its PID, but with no success.

@e01306821

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

did you also run into this problem?

No, this problem is new to me too.

@kodebach

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

What run configuration did you use? Clion only builds the target specified in the run configuration before building. For various reasons, not all of our CMake dependencies are set up correctly. Please try manually cding into the cmake-build-* directory that Clion created and executing make. This should build everything so that you always have at least some version of the libraries when running from Clion.

@kodebach any idea how run_dev_env from within CLion?

No, I literally never touched that script.

@markus2330

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

@kodebach @e01306821 thank you for your quick answers.

For various reasons, not all of our CMake dependencies are set up correctly.

I think this is not the problem here as executing in the shell works.

According to https://stackoverflow.com/questions/37662130/clion-or-cmake-does-not-see-environment-variable sourcing run_dev_env in /etc/environment is the only way accepted by CLion.

So adding

. /home/osboxes/TU/libelektra/scripts/run_dev_env

to /etc/environment might work. @alexsaber please confirm

@kodebach

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

You can also add environment variables to run configurations. So you may try to add LD_LIBRARY_PATH there.

However, I still think that calling make might solve the problem. I now for a fact that just running kdb from Clion doesn't build any plugins, which could explain why (according to the error message above) libelektra-resolver.so wasn't found.

@markus2330

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

You can also add environment variables to run configurations. So you may try to add LD_LIBRARY_PATH there.

This is not a good solution as then everyone need to duplicate all the environment variables locally. It is quite error prone to do that. Furthermore, debugging screenshots is a quite inefficient development approach.

I would prefer if we have one standardized way to run Elektra from the build directory (the run_dev_env) and the different IDEs or development environments source this script.

running kdb from Clion doesn't build any plugins, which could explain why (according to the error message above)

Is this already mentioned in the tutorial?It definitely should be mentioned.

@alexsaber

This comment has been minimized.

Copy link
Contributor Author

commented Jun 10, 2019

What run configuration did you use? Clion only builds the target specified in the run configuration before building. For various reasons, not all of our CMake dependencies are set up correctly. Please try manually cding into the cmake-build-* directory that Clion created and executing make. This should build everything so that you always have at least some version of the libraries when running from Clion.

@kodebach any idea how run_dev_env from within CLion?

No, I literally never touched that script.

@kodebach thank you for your reply!
I tried to cd into the build directory and execute make. Unfortunately, I still have the same problem.

@alexsaber

This comment has been minimized.

Copy link
Contributor Author

commented Jun 10, 2019

So adding

. /home/osboxes/TU/libelektra/scripts/run_dev_env

to /etc/environment might work. @alexsaber please confirm

Unfortunately, it did not work, but I am not sure if I did it correctly.
I modified the file like this.

osboxes@osboxes:~/.config/kdb/elektra_debug/user$ cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
./home/osboxes/TU/libelektra/scripts/run_dev_env
@kodebach

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

but I am not sure if I did it correctly.

You forgot the space between . and the path it seems.

Unfortunately, I still have the same problem.

Hm, that is weird. CMake should set the RPATH for the binaries to the correct lib directory.
Could you please post what readelf -d /home/osboxes/TU/libelektra/cmake-build-debug/bin/kdb show?

@alexsaber

This comment has been minimized.

Copy link
Contributor Author

commented Jun 10, 2019

You forgot the space between . and the path it seems.

Thank you, but it obviously didn't make any difference.

@markus2330

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

The space is essential: Only with a space "." is the "source" shell-built-in.

Did you restart the computer after modifying /etc/environment?

If it does not work, then add LD_LIBRARY_PATH manually.

@alexsaber

This comment has been minimized.

Copy link
Contributor Author

commented Jun 11, 2019

@markus2330 thank you for your suggestions!
A reboot did not help. But I set the LD_LIBRARY_PATH in the debug run config of CLion and it worked! I am so happy you cannot believe it! =)
I can extend the tutorial of my colleague a bit by describing to set the LD_LIBRARY_PATH env variable within the CLion. I assume it does not affect the system scope, which is good.

@markus2330

This comment has been minimized.

Copy link
Contributor

commented Jun 12, 2019

Yes, best you add a troubleshooting section, as we already have in doc/COMPILE.md

@alexsaber

This comment has been minimized.

Copy link
Contributor Author

commented Jun 12, 2019

Did it here #2777

@alexsaber

This comment has been minimized.

Copy link
Contributor Author

commented Jun 12, 2019

I close the issue since it has been resolved. Thank you all for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.