# Tutorial Step 10 POSITION\_INDEPENDENT\_CODE step

**URL:** https://discourse.cmake.org/t/tutorial-step-10-position-independent-code-step/9041
**Category:** Usage
**Created:** [September 21, 2023, 4:34pm UTC](https://discourse.cmake.org/t/tutorial-step-10-position-independent-code-step/9041 "2023-09-21T16:34:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![tjdphd](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/c57346/32.png) [@tjdphd](https://discourse.cmake.org/u/tjdphd)
#### Post date: [September 21, 2023, 4:34pm UTC](https://discourse.cmake.org/t/tutorial-step-10-position-independent-code-step/9041/1 "2023-09-21T16:34:15Z")

</div>

Greetings,

working through step 10 of tutorial and now at the last paragraph which starts “At this point, if you build everything …” and goes onto say there will be a link error if you try to build without doing what follows.

It says something about setting “the POSITION\_INDEPENDENT\_CODE target property of SqrtLibrary to be `True` when building shared libraries” and then provides the code to write below this. From what I can see here, It looks like you’re just supposed to add the line:

target\_compile\_definitions(MathFunctions PRIVATE “EXPORTING\_MYMATH”)

below the line

target\_link\_libraries(MathFunctions PUBLIC tutorial\_compiler\_flags)

in the CMakeLists.txt file in the MathFunctions subdirectory.

There’s nothing shown that explicitly sets the POSITION\_INDEPENDENT\_CODE target property of SqrtLibrary as far as I can see, this is very unclear first of all pedogogically. Second of all, it doesn’t seem to work anyway. I still get the same link error when I try to build namely:  
“LINK : fatal error LNK1181: cannot open input file ‘Release\MathFunctions.lib’ [C:\Users\tdennis…”

Can someone explain what I’m missing and can someone make this step clearer? In particular, explain this business of POSITION\_INDEPENDENT\_CODE and how what is written is related to this?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [September 21, 2023, 10:21pm UTC](https://discourse.cmake.org/t/tutorial-step-10-position-independent-code-step/9041/2 "2023-09-21T22:21:10Z")

</div>

@betsy.mcphail may be interested in following up on this query.
