Loading dynamic libraries for different platforms and architectures

Is there a recommended c++ way to determine the platform and architecture at runtime in order to select the appropriate dynamic library to load?

Or to put it another way :slight_smile: My plugin loads a dynamic library, I can conditionally compile a path for each platform no problem, but is there a similar selector to PLATFORM_LINUX that will tell me is it’s X86_64 or arm64?

Ideally I’d simply like to construct a path at runtime that uses the Platform name (which I can get with GetPlatformName) and architecture name, but I can’t see how to get the chip architecture at runtime.

Any advice? How typically do developers handle loading libraries at runtime for different platforms and architectures.

The OP is way too verbose, let me simplify :slight_smile:

Is there a way to determine the chip architecture (ie. X86_64, arm64) at runtime?

It depends on the engine version you are using.

For 5.3 specifically I was able to use Target.Architecture inside the module’s Build.cs file. If you need it inside the .cpp/.h files. you can make certain macros using PublicDefinitions.Add("YOUR_DEFINE_ARHITECTURENAME"); and make #ifdef/#if conditions. If you have a different engine versions, you can still access the information in the module build file, but the type of variable is different.

Here is an example of a third-party plugin I’ve worked on: unreal-engine-sdk/Source/ThirdParty/ConfigCatCppSDK/ConfigCatCppSdk.Build.cs at 61f85c4014a5112081261109b330f1dbc4b9c8eb · configcat/unreal-engine-sdk · GitHub

Thank you so much - exactly what I was looking for!

Very much appreciated.

Just trying this out and the following line:

if (Target.Architecture.ToLower().Contains("arm64"))

generates an error while building the solution (or in my case the Xcode project files):

error CS7036: There is no argument given that corresponds to the required formal parameter ‘destination’ of ‘MemoryExtensions.ToLower(ReadOnlySpan, Span, CultureInfo?)’

That doesn’t seem right me to me :slight_smile:

Is this something you’ve seen, or know what the issue may be? Is this the variable type issue you referred to? I’m working with a source build of 5.3.2 on Mac arm64.

Thanks again for your time.

1 Like

It certainly could be related. If you have the time, it would be best to take a look together and I can uncover that for you.

In my experience with Mac specifically multiple arhitectures could be valid at the same time during build time (because God knows why).

It would be best if we could take a look at this together because that format should work for 5.3. Is there an email/discord/twitter I can reach out to?

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.