- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Setting Environment variable in Makefile
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2008 06:24 AM
тАО01-11-2008 06:24 AM
Setting Environment variable in Makefile
I want to set environment variables in the Makefile.
for this i wrote as below
all : GO
GO :
export HAI=HELLO
echo $HAI
But , it is not working
can some one help me to achieve this.
thanks and regards
Vikram
- Tags:
- environment
- make
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2008 06:43 AM
тАО01-11-2008 06:43 AM
Re: Setting Environment variable in Makefile
1.) the "$" character is special to make. To get the shell to see one "$", you must use "$$" in the Makefile.
2.) Environment variables can only be inherited from parent to child processes, not vice versa.
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.
Two ways to solve this problem:
1.) Join the variable initialization and the variable use into a single shell command, so that one child shell will execute both:
all: GO
GO:
export HAI=HELLO; \
echo $$HAI
Not very flexible, but it works.
2.) Use Makefile variables instead of environment variables:
HAI=HELLO
all: GO
GO:
echo $(HAI)
Note the different syntax for variable expansion.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2008 06:59 AM
тАО01-11-2008 06:59 AM
Re: Setting Environment variable in Makefile
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.
thanks and regards
Vikram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2008 09:22 AM
тАО01-11-2008 09:22 AM
Re: Setting Environment variable in Makefile
> Makefile.
Can you set the environment variables outside
the "make" file?
var1=value1 [...] make [...]
Or, can you use "make" macros (again, outside
the "make" file) instead of environment
variables?
make var1=value1 [...] [...]
Or, can you use "make" macros to set
environment variables on "make" action lines?
GO :
var1=$(VAR1) actual_command
A more realistic example of what you really
need to do might be helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2008 11:17 AM
тАО01-11-2008 11:17 AM
Re: Setting Environment variable in Makefile
Basically i want to link some shared libraries present in the lib directory and build an executable.
so instead of hard coring the Path of these shared libraries in the make file, i wanted to give the relative path.
example -
cc -o abc abc.o xyz.o -L../../lib/lhai
but if i give this in the Makefile it is giving ld errors.
So i thought of setting the path in the
makefile through the environment variable.
Even if i do like below
LIB = -L../../lib/libhai.so \
-L../../lib/libhello.so
all : TARGET
TARGET :
cc cc -o abc $(OBJECTS)$(LIB)
the compiler gives ld PATH error
Should i have to set the SHLIB_PATH or LD_PATH
to compile I i do this can i execute this executable on a separate machine without setting any environment variabls
thanks and regards
vikram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2008 12:05 PM
тАО01-11-2008 12:05 PM
Re: Setting Environment variable in Makefile
Which errors?
I really doubt that "ld -L" cares whether
you specify an absolute path or a relative
path, but it probably does require you to
specify the right path. For one thing, a
relative path depends on where you are. You
might throw in a "pwd" near your link
command, to see where you are when you try to
do that link.
> Should i have to set the SHLIB_PATH or
> LD_PATH
That's what "-L" (and its friends) are for,
but you need to specify the right stuff,
which, I'd guess, you are not doing. But I
don't know where you are, or what's in
"../../lib/".
> So i thought of setting the path in the
> makefile through the environment variable.
This is why it's often better to describe the
actual problem than it is to ask how to
implement some poor solution to that problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 02:28 AM - last edited on тАО09-29-2020 10:02 AM by Parvez_Admin
тАО01-14-2008 02:28 AM - last edited on тАО09-29-2020 10:02 AM by Parvez_Admin
Re: Setting Environment variable in Makefile
See my answers to your other thread:http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1192582 [Admin: The link is no longer valid> Broken Link removed]
>So i thought of setting the path in the makefile through the environment variable.
You'll get the same error until you get the path and options straight.
>Even if i do like below
LIB = -L../../lib/libhai.so \
-L../../lib/libhello.so
This isn't the correct syntax. The correct syntax is: -L../../lib -lhai -lhello
Note the shlibs will have to use the .sl suffix, since you are on PA.
>Should i have to set the SHLIB_PATH
SHLIB_PATH is a runtime (dld) path.
>can i execute this executable on a separate machine without setting any environment variables
See your other thread.