Reputation: 114
There was a similar question to mine however the answers were not quite solutions so if I could get some help with this it would be greatly appreciated.
The problem is that when I compile, Xcode gives the aforementioned error of sh: gnuplot: command not found.
I checked which gnuplot
in terminal and as expected from macports it is in /opt/local/bin/gnuplot
. Also printf("PATH=%s\n", getenv("PATH"));
shows the path PATH=/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
I suspect therein lies the problem but I am not sure how to fix it.
Thanks in advance!
Upvotes: 1
Views: 19385
Reputation: 69
The key issue to prevent Xcode from running is indeed related to PATH
of gnuplot
. Depending on which package management system you use in mac, the directory of gnuplot
can vary.
Typing which gnuplot
in terminal will show the exact location of gnuplot
.
In the case of macport
, gnuplot
is located in /opt/local/bin
, which is not included in the default path setting of Xcode.
To check your PATH
, typing
std::cout << "PATH=" << getenv("PATH") << std::endl; // #include<iostream>
or
printf( "PATH=%s\n", getenv("PATH") ); // #include<cstdio>
can show you a likewise path as
/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin
Here is my solution.
The easiest way is to use a soft link to combine the real directory (/opt/local/bin
) of gnuplot
with the acceptable direction, such as ( /usr/bin
) that shows from getenv("PATH")
in Xcode, like
ln -s /opt/local/bin/gnuplot /usr/bin/gnuplot
If your .bash_profile
setting resists the previous method, then the safer and more stable method is to adding an external path in Xcode project directly,
which is original from here. In brief, add PATH
in Product>Scheme>Edit Scheme...
as shown below before closing this window.
Try this code to generate your first ever gnuplot in Xcode
#include <iostream>
#include "gnuplot-iostream.h"
int main( ) {
Gnuplot gp;
gp << "plot [-10:10] sin(x),atan(x),cos(atan(x))\n";
return 0;
}
Upvotes: 1
Reputation: 122391
Replace occurrences of gnuplot
, in your script, with /opt/local/bin/gnuplot
to take $PATH
out of the equation.
Upvotes: 1