<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Setting Environment variable in Makefile in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127917#M93085</link>
    <description>&lt;!--!*#--&gt;I can see two problems.&lt;BR /&gt;&lt;BR /&gt;1.) the "$" character is special to make. To get the shell to see one "$", you must use "$$" in the Makefile.&lt;BR /&gt;&lt;BR /&gt;2.) Environment variables can only be inherited from parent to child processes, not vice versa.&lt;BR /&gt;&lt;BR /&gt;In this case, the parent process is the 'make' that is processing the Makefile. When it reaches the "export HAI=HELLO" line, it will create a child process to run a shell to execute the export statement. The variable is set in the environment of the child process only. After the export statement is completed, the child process exits and its environment, including the new variable, is gone. The "echo $HAI" statement is executed by another child process.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Two ways to solve this problem:&lt;BR /&gt;&lt;BR /&gt;1.) Join the variable initialization and the variable use into a single shell command, so that one child shell will execute both:&lt;BR /&gt;&lt;BR /&gt;all: GO&lt;BR /&gt;&lt;BR /&gt;GO:&lt;BR /&gt;        export HAI=HELLO; \&lt;BR /&gt;        echo $$HAI&lt;BR /&gt;&lt;BR /&gt;Not very flexible, but it works.&lt;BR /&gt;&lt;BR /&gt;2.) Use Makefile variables instead of environment variables:&lt;BR /&gt;&lt;BR /&gt;HAI=HELLO&lt;BR /&gt;&lt;BR /&gt;all: GO&lt;BR /&gt;&lt;BR /&gt;GO:&lt;BR /&gt;        echo $(HAI)&lt;BR /&gt;&lt;BR /&gt;Note the different syntax for variable expansion.&lt;BR /&gt;&lt;BR /&gt;MK</description>
    <pubDate>Fri, 11 Jan 2008 14:43:00 GMT</pubDate>
    <dc:creator>Matti_Kurkela</dc:creator>
    <dc:date>2008-01-11T14:43:00Z</dc:date>
    <item>
      <title>Setting Environment variable in Makefile</title>
      <link>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127916#M93084</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;       I want to set environment variables in the Makefile.&lt;BR /&gt;    for this i wrote as below&lt;BR /&gt;&lt;BR /&gt;     all : GO&lt;BR /&gt;&lt;BR /&gt;      GO :&lt;BR /&gt;            export HAI=HELLO&lt;BR /&gt;            echo $HAI&lt;BR /&gt;&lt;BR /&gt;     But , it is not working &lt;BR /&gt;&lt;BR /&gt;     can some one help me to achieve this.&lt;BR /&gt;&lt;BR /&gt;thanks and regards&lt;BR /&gt;Vikram</description>
      <pubDate>Fri, 11 Jan 2008 14:24:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127916#M93084</guid>
      <dc:creator>CA1490051</dc:creator>
      <dc:date>2008-01-11T14:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Environment variable in Makefile</title>
      <link>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127917#M93085</link>
      <description>&lt;!--!*#--&gt;I can see two problems.&lt;BR /&gt;&lt;BR /&gt;1.) the "$" character is special to make. To get the shell to see one "$", you must use "$$" in the Makefile.&lt;BR /&gt;&lt;BR /&gt;2.) Environment variables can only be inherited from parent to child processes, not vice versa.&lt;BR /&gt;&lt;BR /&gt;In this case, the parent process is the 'make' that is processing the Makefile. When it reaches the "export HAI=HELLO" line, it will create a child process to run a shell to execute the export statement. The variable is set in the environment of the child process only. After the export statement is completed, the child process exits and its environment, including the new variable, is gone. The "echo $HAI" statement is executed by another child process.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Two ways to solve this problem:&lt;BR /&gt;&lt;BR /&gt;1.) Join the variable initialization and the variable use into a single shell command, so that one child shell will execute both:&lt;BR /&gt;&lt;BR /&gt;all: GO&lt;BR /&gt;&lt;BR /&gt;GO:&lt;BR /&gt;        export HAI=HELLO; \&lt;BR /&gt;        echo $$HAI&lt;BR /&gt;&lt;BR /&gt;Not very flexible, but it works.&lt;BR /&gt;&lt;BR /&gt;2.) Use Makefile variables instead of environment variables:&lt;BR /&gt;&lt;BR /&gt;HAI=HELLO&lt;BR /&gt;&lt;BR /&gt;all: GO&lt;BR /&gt;&lt;BR /&gt;GO:&lt;BR /&gt;        echo $(HAI)&lt;BR /&gt;&lt;BR /&gt;Note the different syntax for variable expansion.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Fri, 11 Jan 2008 14:43:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127917#M93085</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2008-01-11T14:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Environment variable in Makefile</title>
      <link>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127918#M93086</link>
      <description>Hi MK,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;    In that case what i should do if i have to set an environment variable initially and use the same variable in the later part of the Makefile.&lt;BR /&gt;&lt;BR /&gt;thanks and regards&lt;BR /&gt;Vikram</description>
      <pubDate>Fri, 11 Jan 2008 14:59:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127918#M93086</guid>
      <dc:creator>CA1490051</dc:creator>
      <dc:date>2008-01-11T14:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Environment variable in Makefile</title>
      <link>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127919#M93087</link>
      <description>&lt;!--!*#--&gt;&amp;gt; I want to set environment variables in the&lt;BR /&gt;&amp;gt; Makefile.&lt;BR /&gt;&lt;BR /&gt;Can you set the environment variables outside&lt;BR /&gt;the "make" file?&lt;BR /&gt;&lt;BR /&gt;   var1=value1 [...] make [...]&lt;BR /&gt;&lt;BR /&gt;Or, can you use "make" macros (again, outside&lt;BR /&gt;the "make" file) instead of environment&lt;BR /&gt;variables?&lt;BR /&gt;&lt;BR /&gt;   make var1=value1 [...] [...]&lt;BR /&gt;&lt;BR /&gt;Or, can you use "make" macros to set&lt;BR /&gt;environment variables on "make" action lines?&lt;BR /&gt;&lt;BR /&gt;GO :&lt;BR /&gt;        var1=$(VAR1) actual_command&lt;BR /&gt;&lt;BR /&gt;A more realistic example of what you really&lt;BR /&gt;need to do might be helpful.</description>
      <pubDate>Fri, 11 Jan 2008 17:22:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127919#M93087</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-01-11T17:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Environment variable in Makefile</title>
      <link>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127920#M93088</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;     Basically i want to link some shared libraries present in the lib directory and build an executable.&lt;BR /&gt;&lt;BR /&gt;      so instead of hard coring the Path of these shared libraries in the make file, i wanted to give the relative path.&lt;BR /&gt;&lt;BR /&gt;   example - &lt;BR /&gt;      cc -o abc  abc.o xyz.o -L../../lib/lhai&lt;BR /&gt;&lt;BR /&gt;       but if i give this in the Makefile it is  giving ld errors.&lt;BR /&gt;&lt;BR /&gt;      So i thought of setting the path in the &lt;BR /&gt;makefile through the environment variable.&lt;BR /&gt;&lt;BR /&gt;     Even if i do like below&lt;BR /&gt;   LIB = -L../../lib/libhai.so \&lt;BR /&gt;         -L../../lib/libhello.so&lt;BR /&gt;&lt;BR /&gt;    all : TARGET&lt;BR /&gt;&lt;BR /&gt;    TARGET : &lt;BR /&gt;             cc cc -o abc $(OBJECTS)$(LIB)&lt;BR /&gt;&lt;BR /&gt;    the compiler gives ld PATH error&lt;BR /&gt;&lt;BR /&gt;   Should i have to set the SHLIB_PATH or LD_PATH&lt;BR /&gt;&lt;BR /&gt;   to compile I i do this can i execute this executable on a separate machine without setting any environment variabls&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;thanks and regards&lt;BR /&gt;vikram&lt;BR /&gt;     &lt;BR /&gt;         &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Jan 2008 19:17:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127920#M93088</guid>
      <dc:creator>CA1490051</dc:creator>
      <dc:date>2008-01-11T19:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Environment variable in Makefile</title>
      <link>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127921#M93089</link>
      <description>&amp;gt; [...] it is giving ld errors.&lt;BR /&gt;&lt;BR /&gt;Which errors?&lt;BR /&gt;&lt;BR /&gt;I really doubt that "ld -L" cares whether&lt;BR /&gt;you specify an absolute path or a relative&lt;BR /&gt;path, but it probably does require you to&lt;BR /&gt;specify the right path.  For one thing, a&lt;BR /&gt;relative path depends on where you are.  You&lt;BR /&gt;might throw in a "pwd" near your link&lt;BR /&gt;command, to see where you are when you try to&lt;BR /&gt;do that link.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;  Should i have to set the SHLIB_PATH or&lt;BR /&gt;&amp;gt; LD_PATH&lt;BR /&gt;&lt;BR /&gt;That's what "-L" (and its friends) are for,&lt;BR /&gt;but you need to specify the right stuff,&lt;BR /&gt;which, I'd guess, you are not doing.  But I&lt;BR /&gt;don't know where you are, or what's in&lt;BR /&gt;"../../lib/".&lt;BR /&gt;&lt;BR /&gt;&amp;gt; So i thought of setting the path in the&lt;BR /&gt;&amp;gt; makefile through the environment variable.&lt;BR /&gt;&lt;BR /&gt;This is why it's often better to describe the&lt;BR /&gt;actual problem than it is to ask how to&lt;BR /&gt;implement some poor solution to that problem.</description>
      <pubDate>Fri, 11 Jan 2008 20:05:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127921#M93089</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-01-11T20:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Environment variable in Makefile</title>
      <link>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127922#M93090</link>
      <description>&lt;P data-unlink="true"&gt;See my answers to your other thread:&lt;BR /&gt;&lt;U&gt;&lt;STRIKE&gt;&lt;A&gt;http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1192582&lt;/A&gt;&lt;/STRIKE&gt;&lt;/U&gt;&amp;nbsp;&amp;nbsp;&lt;FONT color="#008000"&gt;&lt;STRONG&gt;[Admin: The link is no longer valid&amp;gt; Broken Link removed]&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt;So i thought of setting the path in the makefile through the environment variable.&lt;BR /&gt;&lt;BR /&gt;You'll get the same error until you get the path and options straight.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Even if i do like below&lt;BR /&gt;LIB = -L../../lib/libhai.so \&lt;BR /&gt;-L../../lib/libhello.so&lt;BR /&gt;&lt;BR /&gt;This isn't the correct syntax. The correct syntax is: -L../../lib -lhai -lhello&lt;BR /&gt;&lt;BR /&gt;Note the shlibs will have to use the .sl suffix, since you are on PA.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Should i have to set the SHLIB_PATH&lt;BR /&gt;&lt;BR /&gt;SHLIB_PATH is a runtime (dld) path.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;can i execute this executable on a separate machine without setting any environment variables&lt;BR /&gt;&lt;BR /&gt;See your other thread.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:02:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/setting-environment-variable-in-makefile/m-p/4127922#M93090</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2020-09-29T17:02:05Z</dc:date>
    </item>
  </channel>
</rss>

