Page 2 of 2
Re: How to get the folder of the executable?
Posted: Fri Aug 10, 2018 7:53 am
by Marc56us
I don't know if this will work, but in the default Linux PB installation, there is a dot in Library Subsystem (= search in the executable folder)
Put your lib in your executable folder
In preferences
[X] Create temporary executable in the source directory
Library Subsystem: . (point)

Re: How to get the folder of the executable?
Posted: Fri Aug 10, 2018 8:14 am
by RASHAD
Maybe the problem is between Debian and VirtualBox
Just a suggestion
Re: How to get the folder of the executable?
Posted: Fri Aug 10, 2018 8:48 am
by Martin Verlaan
No, it also happens in Debian directly installed on PC (a user who is using Debian drew my attention to this problem, that why I installed Debian in VirtualBox).
I tried all above suggestions, but none with success. I think the best solution is OpenLibrary(), but I tried that as well and it generates an memory error. I used this example
https://www.un4seen.com/stuff/bass24-pb.zip as a test and replaced the .dll filenames with .so but maybe that's not the correct way for Linux.
Re: How to get the folder of the executable?
Posted: Fri Aug 10, 2018 8:56 am
by wilbert
Martin Verlaan wrote:I think the best solution is OpenLibrary(), but I tried that as well and it generates an memory error. I used this example
https://www.un4seen.com/stuff/bass24-pb.zip as a test and replaced the .dll filenames with .so but maybe that's not the correct way for Linux.
It's an old include file for 32 bit.
You will need to replace quite a bit of .l (Long) types into .i (Integer) to make it work on 64 bit.
Edit:
I might have been to fast with my conclusion.
Most things seem to work fine without converting .l to .i
Re: How to get the folder of the executable?
Posted: Fri Aug 10, 2018 9:27 am
by #NULL
Maybe some distros search for shared libraries in the current directory per default, but usually they don't.
You can add '.' to LD_LIBRARY_PATH before running the binary. Or you properly install the library in your system including running ldconfig so its being found in the default locations.
For a test you may just open a terminal in the binary directory and try
Code: Select all
export LD_LIBRARY_PATH=. && ./binary
where binary is you executable name.
Re: How to get the folder of the executable?
Posted: Fri Aug 10, 2018 9:58 am
by Martin Verlaan
Still there is one thing I don't understand. I am using an relative path with Import, so why does Import refers to my source folder and not to the folder in which it was compiled and saved. To me, this looks like a bug.
Re: How to get the folder of the executable?
Posted: Fri Aug 10, 2018 10:35 am
by #NULL
You are right. If you move the binary and the *.so around then the binary will still use the lib from the original source folder. If you rename the original lib file then the copied binary won't run. I don't know if this is right or wrong though. 'Create executable in the source directory' doesn't change anything about that and is only for running from IDE.
mylib.pb
Code: Select all
; executable format 'Shared.so'
; create executable to 'mylib', creates mylib.so
ProcedureDLL.i f(p.i)
ProcedureReturn p * 2
EndProcedure
main.pb
Code: Select all
; create executable 'main'
Import "mylib.so"
f(p.i)
EndImport
MessageRequester("test", "f(123): " + Str(f(123)))
then copy main and mylib.so elsewhere. main will run, but not if you rename the mylib.so in the original folder.
Re: How to get the folder of the executable?
Posted: Fri Aug 10, 2018 10:52 am
by Marc56us
Linux Debian is configured by default as a normal Unix (i.e. secured against misuse)
So there is no path on the current directory. (verify: echo $PATH does not end with :.)
Add an . in the PATH variable and try again

Re: How to get the folder of the executable?
Posted: Fri Aug 10, 2018 11:02 am
by Martin Verlaan
Okay, learned a lot today. I will use import "\usr\lib\smartmix\file.so" and I will include a folder "smartmix" with the executable. I will tell the users of my program that they must copy this folder to \usr\lib\ and then everything will be fine

Thanks everybody for your replies.
Oh and the reason it works here in Linux Mint, is because the source code folder exist there! In a clean installed Mint it will not work (just like Debian), so I have to follow above method for that distro as well. I am happy that I understand it now.