# Using libraries with std::shared\_ptrs

**URL:** <https://forums.unrealengine.com/t/using-libraries-with-std-shared-ptrs/1173215>\
**Category:** C++\
**Tags:** third-party-librarie, unreal-engine, CPP, pointers\
**Created:** [May 21, 2023, 5:16am UTC](https://forums.unrealengine.com/t/using-libraries-with-std-shared-ptrs/1173215 "2023-05-21T05:16:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DentonJC](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DentonJC](https://forums.unrealengine.com/u/DentonJC)\
**Post date:** [May 21, 2023, 5:16am UTC](https://forums.unrealengine.com/t/using-libraries-with-std-shared-ptrs/1173215/1 "2023-05-21T05:16:15Z")

</div>

I have a third party library that I need to include in my Unreal project. This library is full of std::shared\_ptr and expects std::shared\_ptrs as part of its API. Its not really feasable to swap them all to TSharedPtr.  
I will of course use TSharedPtrs wherever possible, but what are my options here?  
How can I safely create std::shared\_ptrs on the heap without destroying the Unreal memory system/garbage collection etc?

---

<div class="post-metadata">

**Author:** ![maurodorni](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@maurodorni](https://forums.unrealengine.com/u/maurodorni)\
**Post date:** [June 13, 2023, 5:46am UTC](https://forums.unrealengine.com/t/using-libraries-with-std-shared-ptrs/1173215/2 "2023-06-13T05:46:29Z")

</div>

follow for potential solution: I have the same issue (3rd party with heavy usage of std::shared\_ptr) and it’s quite messy, lot of issues on FMEMORY\_INLINE\_FUNCTION\_DECORATOR void FMemory::Free(void\* Original)

---

<div class="post-metadata">

**Author:** ![DentonJC](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DentonJC](https://forums.unrealengine.com/u/DentonJC)\
**Post date:** [June 23, 2023, 5:58pm UTC](https://forums.unrealengine.com/t/using-libraries-with-std-shared-ptrs/1173215/3 "2023-06-23T17:58:27Z")

</div>

I got mine working. But it was caused by the fact that my third party dll was using a different version of the c++ CRT. It was compiled using Visual Studio 2017, while unreal was compiled using VS 2019 compiler. By compiling both my dll and unreal with vs 2019, and hiding my DLL behind a c style interface, it seemed to work.

I found these two articles extremely helpful:

> **[Learn why - Mixing Multiple Visual Studio Versions is Evil | SiOM Systems](https://siomsystems.com/mixing-visual-studio-versions/)**
>
> Find out why mixing multiple Visual Studio versions in a program is evil. Learn some workarounds, if you must allow multiple Visual Studio versions.

> **[Adding custom third-party library to plugin from scratch | Unreal Engine...](https://unrealcommunity.wiki/adding-custom-third-party-library-to-plugin-from-scratch-867b28)**
>
> In this article we will create custom dll project (emulating third-party library), custom plugin , connect plugin with dll project and add that plugin to blank project

From what I gather, you might be able to use shared pointers without a restrictive interface, but its recommended not to do so. Passing anything beyond simple data structures and pointers past dll boundaries doesn’t appear to be recommended, although perhaps that only applies to cases where they were built using different compilers or different CRT. In any case, you should avoid it wherever possible, along with any templated objects.

By me using different compilers, it appears that causes my dll to try to use the CRT runtime it was built with, different heap than unreal’s heap. Resulting in heap corruption.

I’m no expert, so I don’t have the best details, but I can at least walk you through what worked in my case. I will continue to refine and improve my project in the future, and see if I can do it without using an extra module interface

EDIT: Nope, looks like using a module interface is definitely required in my case. Trying to use my dll without it caused my heap corruption issues again.

---

<div class="post-metadata">

**Author:** ![eray\_ozr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eray\_ozr](https://forums.unrealengine.com/u/eray_ozr)\
**Post date:** [April 10, 2024, 9:16am UTC](https://forums.unrealengine.com/t/using-libraries-with-std-shared-ptrs/1173215/5 "2024-04-10T09:16:24Z")

</div>

Could you find any solution ?
