简体   繁体   English

如何获得C ++自己的目录?

[英]How to get c++ own directory?

I have a c++ .so file, so I called this from python. 我有一个c ++ .so文件,所以我从python调用了它。 I wanna get .so file own location from c++ code. 我想从C ++代码获取.so文件的位置。 I used getcwd and readlink. 我使用了getcwd和readlink。 They returned python code running directory. 他们返回了python代码运行目录。 Is there someone knows the issue? 有没有人知道这个问题? Please help me, thanks. 请帮助我,谢谢。

Ps my .so file location is: /home/user/cpp/test.so ps我的.so文件位置是:/home/user/cpp/test.so
my python code location is: /home/user/python/test.py 我的python代码位置是:/home/user/python/test.py
getcwd, readlink's output is : /home/user/python (i wanna get "/home/user/cpp") getcwd,readlink的输出为:/ home / user / python(我想获取“ / home / user / cpp”)

In general, the easiest/most efficient way to find an executable's shared library dependencies - and their paths - is with the "ldd" command. 通常,找到可执行文件的共享库依赖关系及其路径的最简单/最有效的方法是使用“ ldd”命令。

If you want to get this information programmatically, one possibility is dl_iterate_phdr 如果要以编程方式获取此信息,则一种可能性是dl_iterate_phdr

Another is to check /proc/--pid--/maps: 另一个是检查/ proc /-pid-/ maps:

http://www.unix.com/programming/34498-how-view-loaded-shared-libraries-running-processes-linux.html http://www.unix.com/programming/34498-how-view-loaded-shared-libraries-running-processes-linux.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM