# Windows linker issue on develop

**URL:** <https://forum.juce.com/t/windows-linker-issue-on-develop/55524>\
**Category:** General JUCE discussion\
**Created:** [March 26, 2023, 4:19pm UTC](https://forum.juce.com/t/windows-linker-issue-on-develop/55524 "2023-03-26T16:19:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [March 26, 2023, 4:19pm UTC](https://forum.juce.com/t/windows-linker-issue-on-develop/55524/1 "2023-03-26T16:19:18Z")

</div>

👋

I’m getting the following linker error:

```auto
error: undefined symbol: bool __cdecl juce::detail::isRunningInUnity(void)

```

This occurs on

1. develop
2. Windows only
3. Only targets that have the JUCE target as a dependency

The JUCE targets themselves seem to build fine. Mac/Linux also seem fine.

You can see it happen on an Catch2 target linking against a JUCE target here: [https://github.com/sudara/pamplejuce/actions/runs/4525122043/jobs/7969404050](https://github.com/sudara/pamplejuce/actions/runs/4525122043/jobs/7969404050)

I tried [8efadd1](https://github.com/juce-framework/JUCE/commit/8efadd14bbd34fee6f7d20b1ed02e125f8e837d9) and it didn’t exhibit the problem. I suspect the issue comes from some of the plugin client reorganization stuff after this commit (cc @reuk).

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [March 27, 2023, 1:58pm UTC](https://forum.juce.com/t/windows-linker-issue-on-develop/55524/2 "2023-03-27T13:58:59Z")

</div>

Thanks, I see what’s going wrong. We’re currently trying to determine the cleanest solution, but should have something out shortly.

Tangentially-related: when I build your project locally with ClangCL, I get quite a lot of duplicate symbol warnings (ODR violations) when linking the test target. I think the problem is that the `JUCE_DEPENDENCIES` are linked separately to the plugin target and the test target. JUCE modules are interface targets, which means that they are built separately for each non-interface target that links against them. In turn, this means that the test binary contains two copied of the JUCE modules; one from the plugin shared-code target, and one linked directly to the test target.

To avoid the ODR violations, you could consider _only_ linking JUCE\_DEPENDENCIES to the shared-code target, then re-exporting the shared-code target’s preprocessor definitions and include directories. That way, when you add the shared-code target as a dependency of the test target, the test target will still inherit all of the JUCE flags and include directories.

```auto
target_compile_definitions(${PROJECT_NAME} INTERFACE $<TARGET_PROPERTY:${PROJECT_NAME},COMPILE_DEFINITIONS>)
target_include_directories(${PROJECT_NAME} INTERFACE $<TARGET_PROPERTY:${PROJECT_NAME},INCLUDE_DIRECTORIES>)

```

---

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [March 27, 2023, 2:04pm UTC](https://forum.juce.com/t/windows-linker-issue-on-develop/55524/3 "2023-03-27T14:04:26Z")

</div>

> [@reuk](#):
>
> That way, when you add the shared-code target as a dependency of the test target, the test target will still inherit all of the JUCE flags and include directories.

Ahhhhh, I’ve been wondering about how to do this! This is really useful, thank you for the heads up and solution…

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [March 30, 2023, 5:13pm UTC](https://forum.juce.com/t/windows-linker-issue-on-develop/55524/4 "2023-03-30T17:13:14Z")

</div>

This should now be fixed on develop:

> <https://github.com/juce-framework/JUCE/commit/4fbc4da29ad9330b391ceba0632091dca6ae4dd0>

---

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [June 28, 2023, 2:05pm UTC](https://forum.juce.com/t/windows-linker-issue-on-develop/55524/5 "2023-06-28T14:05:43Z")

</div>

> [@reuk](#):
>
> To avoid the ODR violations, you could consider _only_ linking JUCE\_DEPENDENCIES to the shared-code target, then re-exporting the shared-code target’s preprocessor definitions and include directories.

Just wanted to follow up and say that this worked, but we’re having [some debate over on the pamplejuce repo](https://github.com/sudara/pamplejuce/issues/31#issuecomment-1611292090) about the visibility of modules.

Basically, our `Tests` target might need to specify different compile definitions, such as `JUCE_MODAL_LOOPS_PERMITTED=1` or `RUN_TESTS_IN_MODULES=1` — to accommodate this, it seems like there would need to be two compiled shared plugin targets?

We’re not quite sure how to approach that with the shared plugin target. I’ve been doing everything wrong (setting my modules to PUBLIC visibility) and that’s somehow been working for me with no linker warnings…

---

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [August 6, 2023, 8:07pm UTC](https://forum.juce.com/t/windows-linker-issue-on-develop/55524/6 "2023-08-06T20:07:48Z")

</div>

For some reason I wasn’t ever able to set additional definitions via `target_compile_definitions` for our Test target when going the “copy defs and dirs from the plugin target” route.

I’ve tried out @chrhaase’s suggestion of creating an INTERFACE target that houses the shared app code and definitions. The main juce shared plugin target as well as the Tests target then link to that.

```auto
target_link_libraries("${PROJECT_NAME}" PRIVATE SharedCode)
target_link_libraries(Tests PRIVATE "${PROJECT_NAME}" SharedCode Catch2::Catch2WithMain)

```

Things seem happy now, but thought I’d share in case this is still unideal in some way. The other route I considered was just setting up a cmake flag/option, but that’s sort of bulkier/more manual…

> <https://github.com/sudara/pamplejuce/pull/33>
>
> f637d797cca2352fe3aa37bd56025109a5c3dbe9 attempted to fix #31 — putting the juce… modules (and third party modules) back to PRIVATE visibility. See that issue for details on why this needs to be the case in JUCE.
> 
> Unfortunately, that fix doesn't account for the fact that differing compile definitions may be desired. For example we might want to set \`JUCE\_MODAL\_LOOPS\_PERMITTED=1\` in tests to be able to run the MessageManager so callbacks fire, or set something like \`RUN\_MY\_TESTS=1\` so that tests in source files and module directories will run. Trying to add additional definitions via \`target\_compile\_definitions\` wasn't working.
> 
> This PR implements @chrhaase's suggestion of sticking all app code and config in an INTERFACE target so that it can be shared between the various juce plugin targets as well as the \`Tests\` target.
