# use or build

**URL:** https://discourse.cmake.org/t/use-or-build/675
**Category:** Usage
**Created:** [February 21, 2020, 5:09am UTC](https://discourse.cmake.org/t/use-or-build/675 "2020-02-21T05:09:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Tomasz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tomasz/32/381_2.png) [@Tomasz](https://discourse.cmake.org/u/Tomasz)
#### Post date: [February 21, 2020, 5:09am UTC](https://discourse.cmake.org/t/use-or-build/675/1 "2020-02-21T05:09:27Z")

</div>

Hi

I have lib installed in /usr/local/lib. I try to use it as package in other project. I create .cmake file and i put it in appropriate directory. Package was found by cmake but linker error occurred. Is a way in cmake to set up LD\_LIBRARY\_PATH? Maybe is in cmake better way to solve this problem?

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [February 21, 2020, 1:21pm UTC](https://discourse.cmake.org/t/use-or-build/675/2 "2020-02-21T13:21:09Z")

</div>

Without knowing the specifics of your project, I’d suggest taking a look at the [packages](https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html) documentation. Also, CMake prefers to use absolute paths to libraries, rather than `-l` and `-L` flags. Is the link error happening at compile/link time or run time?

---

<div class="post-metadata">

### Author: ![Tomasz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tomasz/32/381_2.png) [@Tomasz](https://discourse.cmake.org/u/Tomasz)
#### Post date: [February 23, 2020, 2:39pm UTC](https://discourse.cmake.org/t/use-or-build/675/3 "2020-02-23T14:39:02Z")

</div>

Thanks for response. Error occurred in linking process. When I copy libXCLZ4.so to /usr/lib problem disappeared.

# critical part in first CMakeLists.txt

#instalation  
if(UNIX)  
set\_target\_properties ( XCLZ4 PROPERTIES PUBLIC\_HEADER “include/CLZ4.h” )  
install( TARGETS XCLZ4 DESTINATION lib/X PUBLIC\_HEADER DESTINATION include/X )  
message ( ${PRFIX}/X )  
install( FILES XCLZ4Config.cmake DESTINATION /usr/local/lib/cmake )  
elseif ( WIN32 )  
endif()

# whole XCLZ4Config.cmake

set( XCLZ4\_INCLUDE\_DIRS ${PREFIX}/include/X )  
set( XCLZ4\_LIBRARIES ${PREFIX}/lib/X/libXCLZ4.so)

Library and XCLZ4Config.cmake after installation process was copied in to appropriate localization.

# critical part of second CMakeLists.txt ( in which i try to use libXCLZ4.so )

find\_package (XCLZ4)  
if( XCLZ4\_FOUND )  
target\_link\_libraries( XLogger PRIVATE XCLZ4 )  
else()  
add\_subdirectory( ${CMAKE\_SOURCE\_DIR}/XLZ4 build/XLZ4 )  
endif()
