remoteAPI.dll with ARM64

Typically: "How do I... ", "How can I... " questions
RobEng
Posts: 6
Joined: 23 Jul 2021, 13:47

remoteAPI.dll with ARM64

Post by RobEng »

Hello,

is there a remoteAPI.dll compatible with ARM64 architecture? We want to use the remoteAPI in our current Unity project (for Hololens2, ARM CPU).

Thank you for any help or possible solution you can offer me

coppelia
Site Admin
Posts: 10312
Joined: 14 Dec 2012, 00:25

Re: remoteAPI.dll with ARM64

Post by coppelia »

Hello,

if you are talking about the legacy remote API, then I believe you should be able to compile it on your platform and it should work fine. Please give it a try and let me know.

Cheers

RobEng
Posts: 6
Joined: 23 Jul 2021, 13:47

Re: remoteAPI.dll with ARM64

Post by RobEng »

Hello,

thank you for your reply. Yes, I'm talking about the legacy remote API. Which files exactly do I need to compile? I found a folder called remoteAPI with the files extApi.c, extApi.h, extApiInternal.h, extApiPlatform.c and extApiPlatform.h, as well as a folder called remoteApiBindings.

Many thanks

fferri
Posts: 1187
Joined: 09 Sep 2013, 19:28

Re: remoteAPI.dll with ARM64

Post by fferri »

Have a look at Enabling the remote API - client side to know which one you need.

RobEng
Posts: 6
Joined: 23 Jul 2021, 13:47

Re: remoteAPI.dll with ARM64

Post by RobEng »

Hello,

thank you. I tried compiling the files for ARM64, but unfortunately didn't succeed in doing so. When I build it, it creates the dll without any error messages, however when I deploy it to the HoloLens 2, it still can't be found. Since I've never created a .dll file before, I don't know where exactly my mistake originates. Here are the steps I followed (I am using Visual Studio 2019):

1. I created a new dll project called remoteAPI
2. I included the headers (extAPI.h and extAPIPlatform.h) in the pch.h file inside extern "C" {}
3. I renamed the .c files (extAPI.c and extAPIPlatform.c) to .cpp and also placed the code inside extern "C" {}
4. I created a new configuration in the configuration manager and copied the settings from x86
5. In the debug properties under linker/advanced/target machine, I chose MachineARM64(/MACHINE:ARM64)

Do you happen to know what I did wrong, whether I miss any steps / forgot to change some settings, or where I could get some help with this?

coppelia
Site Admin
Posts: 10312
Joined: 14 Dec 2012, 00:25

Re: remoteAPI.dll with ARM64

Post by coppelia »

You can directly use the visual studio project files located in programming/remoteApiBindings/lib (i.e. remoteApiSharedLib-64.vcxproj) to rebuild the remoteApi.dll library. That's the easiest. It only relies on having additionally following 3 repositories in the programming folder: include, common and remoteApi.

However if you were already able to build the library, then that should be fine too. Adjust the target machine. Make sure to have the release configuration, otherwise you might need additional dependencies. Finally, when you say
I deploy it to the HoloLens 2, it still can't be found
, what does it mean exactly? Not sure what is supposed to load the remoteApi.dll on that side. But if a library can't be loaded, it is often because it can't be found in the search path, because it was build for another architecture (e.g. 32 vs 64 bit), or because some dependency is missing (you can use Dependencies to check for that).

Cheers

RobEng
Posts: 6
Joined: 23 Jul 2021, 13:47

Re: remoteAPI.dll with ARM64

Post by RobEng »

Thank you for your detailed and quick response. I followed your steps, opened the remoteApiSharedLib-64.vcxproj project, changed the platform to ARM64 and made sure that in the preferences C/C++ the three repositories are added to the additoinal include directories (only common was missing). The configuration is on release and the target machine is MachineARM64, but for some reason this results in 6 linking errors (LNK2001).
In the file extApiPlatform.obj, there are following unresolved symbols: close_shared_memory, set_shared_memory_name, map_shared_memory, set_shared_memory_size and destroy_shared_memory (all seem to be defined in shared_memory.c, which is located in common, so all symbols should have already been defined in the build, if I'm not mistaking). Is there an additional directory that I need to include or preference that needs changing for this to work?

To your question, when I was debugging my unity project from the HoloLens, it threw an exception stating that it was unable to load the remoteAPI.dll, as it wasn't found. As you stated I think the reason for this was missing dependencies, as I hadn't included the three libraries, that you mentioned.

Thank you again for taking the time answering my questions

coppelia
Site Admin
Posts: 10312
Joined: 14 Dec 2012, 00:25

Re: remoteAPI.dll with ARM64

Post by coppelia »

You have two possibilities:
  • either remove and add again the shared_memory.c and shared_memory.h files (not sure why that is, probably a default setting for those files was changed, but can't put the finger on it)
  • or add following preprocessor define: DO_NOT_USE_SHARED_MEMORY
You'll then probably also need to add a new ARM64 configuration via the configuration manager, to avoid a linker error like fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'ARM64'.

Cheers

RobEng
Posts: 6
Joined: 23 Jul 2021, 13:47

Re: remoteAPI.dll with ARM64

Post by RobEng »

Thank you for the suggestions. When using DO_NOT_USE_SHARED_MEMORY, these errors no longer occur, however I think I've stumbled across a bigger issue.
_WIN32 is defined by C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h which seems to be automatically included by the project (see image below). I assume this causes the previous errors with the shared_memory files and also causes the issues when attempting to use the dll in unity. How come this file is used? Additionally, the supported library can be built for windows, linux and apple, which do I need to choose when building for ARM64? The company I work for is interested in using this for a project and we really appreciate the help here.

Image

Code: Select all

#ifdef _WIN32
    #define EXTAPI_DLLEXPORT extern __declspec(dllexport)
#endif
#if defined (__linux) || defined (__APPLE__)
    #define EXTAPI_DLLEXPORT extern
#endif
Cheers

coppelia
Site Admin
Posts: 10312
Joined: 14 Dec 2012, 00:25

Re: remoteAPI.dll with ARM64

Post by coppelia »

I would suggest you go another, easier path, since on Windows things can be quite confusing, specially with vs...

Set-up an ubuntu20 (vm) machine for the cross compilation.

Make sure you have the prerequisites:

Code: Select all

$ sudo apt install gcc
$ sudo apt install make
$ sudo apt install gcc-aarch64-linux-gnu
$ sudo apt install binutils-aarch64-linux-gnu 
Then create file makeArm64 in programming/remoteApiBindings/lib/ with following content:

Code: Select all

CFLAGS =  -Wall -fPIC -static -D__linux
CFLAGS += -DNON_MATLAB_PARSING -DMAX_EXT_API_CONNECTIONS=255
CFLAGS += -I../../include
CFLAGS += -I../../remoteApi

all: 
	@rm -f lib/*.*
	@rm -f *.o 

	aarch64-linux-gnu-gcc $(CFLAGS) -c ../../remoteApi/extApi.c -o extApi.o
	aarch64-linux-gnu-gcc $(CFLAGS) -c ../../remoteApi/extApiPlatform.c -o extApiPlatform.o
	aarch64-linux-gnu-gcc $(CFLAGS) -c ../../common/shared_memory.c -o shared_memory.o

	@mkdir -p libArm64
	aarch64-linux-gnu-gcc *.o -o libArm64/libremoteApi.so -lpthread -lrt -shared
Then from within that folder:

Code: Select all

$ make -f makeArm64
Cheers

Post Reply