Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Different getenv("PATH") and $PATH on macos M1 (for libclang.dylib)
Different getenv("PATH") and $PATH on macos M1 (for libclang.dylib) [message #59478] Wed, 04 January 2023 04:36 Go to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
$PATH has got a lot more than getenv("PATH")
One of the reasons why theide can't find libclang.
How to load libclang - that's a different question...

P.S. My first experiments show that libclang is loaded but i guess something wrong is related multithreading...
Luckily, I have just discovered that gdb-appple exists... May it will work with my version of theide..

[Updated on: Thu, 05 January 2023 07:17]

Report message to a moderator

Re: Different getenv("PATH") and $PATH on macos [message #59485 is a reply to message #59478] Thu, 05 January 2023 02:23 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Relevant information: How to set PATH for Finder-launched applications

Regards,
Novo
Re: Different getenv("PATH") and $PATH on macos [message #59487 is a reply to message #59485] Thu, 05 January 2023 05:43 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Novo wrote on Thu, 05 January 2023 01:23
Relevant information: How to set PATH for Finder-launched applications


I had seen that link before I posted but I could not to digest. That's why I posted here. It is not about setting the PATH. It is about getting the PATH. We are not going to ask every theide user to set "sudo launchctl config user path", aren't we? Moreover, the PATH is set. I can get it on terminal with 'echo $PATH' without problems. The questions is - how to get it programatically with upp the right way. getenv used inside ide is the wrong way.
P.S. for some reasons this doesn't work:
String path = Sys("echo $PATH");

//gives path="$PATH";

echo is excluded...
More info on this https://stackoverflow.com/questions/36326868/getting-environ ment-variable-path-in-linux-using-c-in-eclipse

[Updated on: Thu, 05 January 2023 06:51]

Report message to a moderator

Re: Different getenv("PATH") and $PATH on macos [message #59488 is a reply to message #59487] Thu, 05 January 2023 07:03 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
    FILE* pip = popen("exec bash -c 'echo $PATH'", "r");
    if (!pip)
    {
		LOG("can not open pipe!");
    }

    char lineversion[600];
    memset (lineversion, 0, sizeof(lineversion));
    if (!fgets(lineversion, sizeof(lineversion), pip))
    {
		LOG("fgets error!");
    }

	String path2;
	path2.Cat(lineversion);
	LOG("path2="<< path2);


This works. But I wonder if there is a more effective way in upp? Upp way...

[Updated on: Thu, 05 January 2023 07:11]

Report message to a moderator

Re: Different getenv("PATH") and $PATH on macos [message #59490 is a reply to message #59487] Thu, 05 January 2023 16:37 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1092
Registered: August 2007
Senior Contributor
Hi,

Quote:
I had seen that link before I posted but I could not to digest. That's why I posted here. It is not about setting the PATH. It is about getting the PATH. We are not going to ask every theide user to set "sudo launchctl config user path", aren't we? Moreover, the PATH is set. I can get it on terminal with 'echo $PATH' without problems. The questions is - how to get it programatically with upp the right way. getenv used inside ide is the wrong way.
P.S. for some reasons this doesn't work:


Since $PATH is not part of unix echo command, it is a *shell* variable, it is actually the responsibility of shell to replace it with the actual path here. You need to run the command via a shell so that it can inherit the shell's env, and the shell can replace the variable with the output.

And using bash does not seem optimal here, AFAIK the practice is to symlink sh to the preferred shell installed on the system.


Sys("sh -c \'echo $PATH\'");


should work.

Best regards,
Oblivion


Re: Different getenv("PATH") and $PATH on macos [message #59491 is a reply to message #59487] Thu, 05 January 2023 18:47 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
fudadmin wrote on Wed, 04 January 2023 23:43
Novo wrote on Thu, 05 January 2023 01:23
Relevant information: How to set PATH for Finder-launched applications


I had seen that link before I posted but I could not to digest. That's why I posted here. It is not about setting the PATH. It is about getting the PATH. We are not going to ask every theide user to set "sudo launchctl config user path", aren't we? Moreover, the PATH is set. I can get it on terminal with 'echo $PATH' without problems. The questions is - how to get it programatically with upp the right way. getenv used inside ide is the wrong way.
P.S. for some reasons this doesn't work:
String path = Sys("echo $PATH");

//gives path="$PATH";

echo is excluded...
More info on this https://stackoverflow.com/questions/36326868/getting-environ ment-variable-path-in-linux-using-c-in-eclipse

It was supposed to be a hint.
Macos doesn't seem to run a login shell when you log into an account. This is why PATH is not set.
If you check Macos Terminal settings you'll find "on launch" setting. By default it runs a login shell.
Basically, you log into system each time you launch a terminal Smile

Related info:
man opendirectoryd
     Open Directory forms the foundation of how Mac OS X accesses all authoritative configuration information
     (users, groups, mounts, managed desktop data, etc.).  This allows use of virtually any directory system
     via Apple and third party modules.

PATH shouldn't be used with Macos GUI apps, IMHO.


Regards,
Novo
Re: Different getenv("PATH") and $PATH on macos [message #59492 is a reply to message #59490] Thu, 05 January 2023 23:37 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Oblivion wrote on Thu, 05 January 2023 15:37
Hi,

...
Since $PATH is not part of unix echo command, it is a *shell* variable, it is actually the responsibility of shell to replace it with the actual path here. You need to run the command via a shell so that it can inherit the shell's env, and the shell can replace the variable with the output.

And using bash does not seem optimal here, AFAIK the practice is to symlink sh to the preferred shell installed on the system.


Sys("sh -c \'echo $PATH\'");


should work.

Best regards,
Oblivion


Oh... Embarassed
I missed \' thing..
https://stackoverflow.com/questions/1250079/how-to-escape-si ngle-quotes-within-single-quoted-strings
Now, yes, it works upp way!
Btw, bash and zsh (what I am using on mac) also work and give the same results.
But your remark about the sh symlink is also very useful.

Thank you very much, Oblivion.

[Updated on: Fri, 06 January 2023 00:07]

Report message to a moderator

Re: Different getenv("PATH") and $PATH on macos [message #59493 is a reply to message #59491] Fri, 06 January 2023 00:05 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Novo wrote on Thu, 05 January 2023 17:47
fudadmin wrote on Wed, 04 January 2023 23:43
Novo wrote on Thu, 05 January 2023 01:23
Relevant information: How to set PATH for Finder-launched applications


I had seen that link before I posted but I could not to digest. That's why I posted here. It is not about setting the PATH. It is about getting the PATH. We are not going to ask every theide user to set "sudo launchctl config user path", aren't we? Moreover, the PATH is set. I can get it on terminal with 'echo $PATH' without problems. The questions is - how to get it programatically with upp the right way. getenv used inside ide is the wrong way.
P.S. for some reasons this doesn't work:
String path = Sys("echo $PATH");

//gives path="$PATH";

echo is excluded...
More info on this https://stackoverflow.com/questions/36326868/getting-environ ment-variable-path-in-linux-using-c-in-eclipse

It was supposed to be a hint.
Macos doesn't seem to run a login shell when you log into an account. This is why PATH is not set.
If you check Macos Terminal settings you'll find "on launch" setting. By default it runs a login shell.
Basically, you log into system each time you launch a terminal Smile

Related info:
man opendirectoryd
     Open Directory forms the foundation of how Mac OS X accesses all authoritative configuration information
     (users, groups, mounts, managed desktop data, etc.).  This allows use of virtually any directory system
     via Apple and third party modules.

PATH shouldn't be used with Macos GUI apps, IMHO.


I really appreciate your answers, Novo. It is always good to have more opinions and it be really interesting to find out
what function Apple uses for their needs. But.
Quote:

This is why PATH is not set.


No. The PATH is set. It is only NOT correctly retrieved with the getenv("PATH") function. Or let'say it is the other PATH set.

But in Terminal one can get the correct one. And I tested it.
And it is also possible to get the correct one with what Oblivion correctly corrected:

Sys("sh -c \'echo $PATH\'");


Do any opendirectoryd API functions/classes exist?
Or anything else what could correctly replace getenv? Or $PATH?
Or any code which is more politically and/or programatically correct than this:
Sys("sh -c \'echo $PATH\'");

?
Re: Different getenv("PATH") and $PATH on macos [message #59494 is a reply to message #59493] Fri, 06 January 2023 06:06 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
fudadmin wrote on Thu, 05 January 2023 18:05

No. The PATH is set. It is only NOT correctly retrieved with the getenv("PATH") function. Or let'say it is the other PATH set.

But in Terminal one can get the correct one. And I tested it.
And it is also possible to get the correct one with what Oblivion correctly corrected:

Sys("sh -c \'echo $PATH\'");


Do any opendirectoryd API functions/classes exist?
Or anything else what could correctly replace getenv? Or $PATH?
Or any code which is more politically and/or programatically correct than this:
Sys("sh -c \'echo $PATH\'");

?

Yes, it is set. But it is set not by a shell.
According to Set system-wide PATH environment variable for Mac OS GUI apps which is dated 2020 setting PATH via /etc/launchd.conf works.
Comments to "How to set PATH for Finder-launched applications" say that this doesn't work ...
Sys("sh -c \'echo $PATH\'") is a hack. This is not a Macos way. You are not supposed to use shell on Mac. Macos itself doesn't launch shell on login.
This is why I personally wouldn't recommend to use PATH in GUI apps on Mac.
Legally Macos is Unix (and Linux and different flavors of BSD are not), but practically it is something different Smile
I do not know what you need PATH for, but I believe there should be a different way of solving your problem.
Quote:
Do any opendirectoryd API functions/classes exist?
Or anything else what could correctly replace getenv? Or $PATH?
Or any code which is more politically and/or programatically correct than this:

IMHO, if you need shell-related PATH you need to call "sh -c". If you need native Macos PATH you should call regular getenv.
Macos PATH and shell PATH is not the same thing, IMHO. Macos ignores shell.


Regards,
Novo
Re: Different getenv("PATH") and $PATH on macos [message #59495 is a reply to message #59494] Fri, 06 January 2023 09:47 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Novo wrote on Fri, 06 January 2023 05:06


Yes, it is set. But it is set not by a shell.
According to Set system-wide PATH environment variable for Mac OS GUI apps which is dated 2020 setting PATH via /etc/launchd.conf works.
Comments to "How to set PATH for Finder-launched applications" say that this doesn't work ...
Sys("sh -c \'echo $PATH\'") is a hack. This is not a Macos way. You are not supposed to use shell on Mac. Macos itself doesn't launch shell on login.


My strong guess that the PATH is set by the shell. But by the wrong shell...
And I am coming to conclusion because of macports and brew and/or X11 subsystem.
Quote:

This is why I personally wouldn't recommend to use PATH in GUI apps on Mac.

Legally Macos is Unix (and Linux and different flavors of BSD are not), but practically it is something different Smile

I do not know what you need PATH for, but I believe there should be a different way of solving your problem.

Novo, you need to tell this to Mirek or create your own Pull Request on ultimate/ultimate github...

It not me who needs PATH. It is Ultimate++'s theide which uses PATH and tries to look for libclang in the wrog places... Smile

As I wrote in the first opening message at the very top of this thread:
fudadmin wrote on Wed, 04 January 2023 03:36
$PATH has got a lot more than getenv("PATH")
One of the reasons why theide can't find libclang.
How to load libclang - that's a different question...

[Updated on: Fri, 06 January 2023 09:49]

Report message to a moderator

Re: Different getenv("PATH") and $PATH on macos [message #59511 is a reply to message #59495] Tue, 10 January 2023 16:43 Go to previous message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
fudadmin wrote on Fri, 06 January 2023 03:47

My strong guess that the PATH is set by the shell. But by the wrong shell...

Default shell is stored in /etc/passwd in in Linux and BSD.
If you look at the content of this file in MacOS you won't even find your account there.
Basically, all shell-related stuff is ignored by MacOS, IMHO.
It looks like PATH for GUI apps (launched by launchd) is set by launchd.

BTW, path to libs is set by LD_LIBRARY_PATH in Linux and BSD. Smile
PATH is used to locate executables.

I know how to trace loader in Linux but have no idea how to do that with GUI apps in MacOS launched with launchd. :-/


Regards,
Novo
Previous Topic: Compilation on Linux +GUI,X11
Next Topic: Cannot link with obj generated on custom build step.
Goto Forum:
  


Current Time: Fri Apr 19 11:20:05 CEST 2024

Total time taken to generate the page: 0.03411 seconds