PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How to make CMake use environment variable LD_LIBRARY_PATH and C_INCLUDE_DIRS

 August 21, 2022     build, cmake, environment-variables     No comments   

Issue

Is there a way to pass C_INCLUDE_DIRS and LD_LIBRARY_PATH from cmake command line or is there a way to set env so that CMAKE can find and use them?


Solution

It is not fully clear what you intend to do with these variables. Here are some possibilities:

  1. Inside a CMake script you can read environment variables using the syntax $ENV{<VARIABLE_NAME>}. So in your CMakeLists.txt you can have something like

    message( "Found environment variable LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}" )
    
  2. If you want to add the location contained in this variable to be available to your CMake target executables and libraries then you can use the link_directories() command as

    link_directories( $ENV{LD_LIBRARY_PATH} )
    
  3. Or if you have someone else's project and you want to instruct CMake to look for libraries in some additional directories you can use CMAKE_PREFIX_PATH or CMAKE_LIBRARY_PATH. For example to pass these variables in a command line you could do

    cmake -D CMAKE_PREFIX_PATH=/path/to/custom/location
    


Answered By - user6764549
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing