.bashrc/.bash_profile not loading export

0

I'm trying to compile code and in order to get it to work I need to run the following line before compilation:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

After this the code compiles normally, I'm trying to add this so that I do not need to run this line each time when I restart my PC. I've tried adding that line to the .bashrc file (does the file path needs quotes?) which has not seemed to work. I have also tried creating a .bash_profile file an adding the line in there but again this does not seem to work.

Whenever I try to compile after adding the .bash_profile I am getting the following error:

./makeScript: line 1: pkg-config: command not found

Colin747

Posted 2015-10-08T10:10:01.207

Reputation: 253

Possible duplicate of What are PATH and other environment variables, and how can I set or use them?

– DavidPostill – 2015-10-08T10:29:51.820

What's then first line of: makeScript? – kenorb – 2015-10-08T11:11:15.130

g++ -std=c++11 $1 -o $2 \pkg-config --cflags --libs opencv` ` I have tried removing the hyphen is that line as well to no effect. – Colin747 – 2015-10-08T11:15:09.483

Answers

0

It should work if you added it into ~/.bashrc or ~/.bash_profile.

If this won't work, make sure your script actually uses bash shell (shebang), as if you're using different shell, possibly it won't be loaded.

However I think your problem is not related to PKG_CONFIG_PATH, but PATH variable which doesn't contain the right directory where pkg-config executable binary is present.

Check by:

$ which pkg-config
/usr/local/bin/pkg-config

If you can't find it, make sure you've installed it and linked it, e.g. using Homebrew:

brew install pkg-config; brew link pkg-config

And your /usr/local/bin is in your PATH, e.g.

export PATH=/usr/local/sbin:/usr/local/bin:$PATH

As a side note, you can check your export variables by running set command just before the link which fails.

Another thing to track the problem is to debug your scripts by running like: bash -x ./makeScript or adding -x at the end of your shebang (e.g. #!/bin/bash -x).

kenorb

Posted 2015-10-08T10:10:01.207

Reputation: 16 795

0

Take ~/.profile:

$ cat >> ~/.profile << EOF
> PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
> EOF

Load changes (if you do not want to reboot):

$ source ~/.profile

Test:

$ echo $PKG_CONFIG_PATH
/usr/local/lib/pkgconfig

h0ch5tr4355

Posted 2015-10-08T10:10:01.207

Reputation: 883

That resulted in the error pkg-config: command not found when I tried to compile. – Colin747 – 2015-10-08T10:35:05.067

Maybe typing mistakes? You have once hyphens and once none – h0ch5tr4355 – 2015-10-08T10:36:37.067

echo $PKG_CONFIG_PATH results in /usr/local/lib/pkgconfig, does that look correct? – Colin747 – 2015-10-08T10:38:27.560

Yes when its the normal command for your configuration. if pkgconfig doesn't exist at all, the answer is useless. In oyur script you seem to call pkg-config although your variable navigates to pkgconfig ; missing hyphen – h0ch5tr4355 – 2015-10-08T10:44:33.687

I added in the hyphen and got the error pkg-config: command not found. echo $PKG_CONFIG_PATH /usr/local/lib/pkg-config. – Colin747 – 2015-10-08T10:47:26.093