# Create symlink to a install result

**URL:** https://discourse.cmake.org/t/create-symlink-to-a-install-result/8502
**Category:** Code
**Tags:** os:linux
**Created:** [July 12, 2023, 9:01am UTC](https://discourse.cmake.org/t/create-symlink-to-a-install-result/8502 "2023-07-12T09:01:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![WeissZucker](https://discourse.cmake.org/user_avatar/discourse.cmake.org/weisszucker/32/3601_2.png) [@WeissZucker](https://discourse.cmake.org/u/WeissZucker)
#### Post date: [July 12, 2023, 9:01am UTC](https://discourse.cmake.org/t/create-symlink-to-a-install-result/8502/1 "2023-07-12T09:01:01Z")

</div>

.  
├── build  
│ └── lib  
│ └── foo.so  
└── package  
├── fixed  
│ └── dir  
│ └── structure  
│ └── bar.so  
└── lib  
└── foo.so

I don’t have much experience on writing CMakeLists. I have a project where I want to create a symlink bar.so that points to “package/lib/foo.so”, and this needs to be done in a different CMakeLists.txt from the one for the target foo.

Some question:

1. how to ensure the order? The foo.so has to be installed before symlink.
2. how to create symlink? I think add\_custom\_target can help on this?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 18, 2023, 12:00am UTC](https://discourse.cmake.org/t/create-symlink-to-a-install-result/8502/2 "2023-07-18T00:00:45Z")

</div>

> [@WeissZucker](#):
>
> how to ensure the order? The foo.so has to be installed before symlink.

Not sure that matters, but just make sure the directory installing `foo.so` is `add_subdirectory`’d before the `install()` for the symlink is performed.

> [@WeissZucker](#):
>
> how to create symlink? I think add\_custom\_target can help on this?

You can use `install(CODE)` or `install(SCRIPT)` to run CMake code at install time. There, you can use `file(CREATE_LINK … SYMBOLIC)`.
