LD_LIBRARY_PATH, the shared lib path in linux

前端 未结 2 1986
小蘑菇
小蘑菇 2020-12-12 02:07

I wrote a shared object, say libsd.so, and I put libsd.so and its header file sd.h in ~/lib.

Here is another prog

相关标签:
2条回答
  • 2020-12-12 02:28

    Try $HOME/lib instead of ~/lib - it should be the same but I've seen cases where ~ wasn't expanded properly when used in an variable assignment.

    To check, try echo $LD_LIBRARY_PATH which gives you the current value.

    Re export: If you omit the export, then the variable is only known to the current shell process and will not be exported to child processes. So if you omit it, echo $LD_LIBRARY_PATH will get the value because the variable is expanded by the shell before the echo command/builtin has a chance to do anything. But ./test won't see it because it's not exported to the new subprocess.

    0 讨论(0)
  • 2020-12-12 02:37

    Without the export your declared LD_LIBRARY_PATH is only valid in the script (.bashrc). With the export it should work, but it is usually not a good idea to set your LD_LIBRARY_PATH like this.

    If you don't want to install your library in the system path (e.g. /usr/lib) you should probably use a script that sets LD_LIBARAY_PATH locally and starts your application.

    0 讨论(0)
提交回复
热议问题