Integrating devkitPro for native plugins in Unity 3DS

IMPORTANT!!!
This method currently only works in emulator, because it crashes on 3ds hardware. I am still looking into this issue so until I get it fixed you should probably hold off on doing this, unless you want to start writing a dkp plugin that may or may not be able to be used on an actual 3ds in the future... lol


As most of us know, Unity for 3DS is somewhat limited with quite a few features of the 3ds. This functionality can be expanded by using native plugins written in C or C++ that work as libraries to be used in your game.

More recently, I've found a way to write code using devkitpro and compiling it to be able to be used inside of Unity! And I would like to share it here as a basic tutorial to get started for those who are interested.

As of now I've only tried reading and writing to the SDMC, but this could potentially open the door to the many features of devkitpro and its homebrew libraries to use any low level 3DS service that isn't exposed in Unity. I think this could be a break through a barrier that has been a huge headache for devs using this engine for 3ds.

We will cover some of the essential dos and don'ts I've come across, workarounds for some stuff, and the general setup needed




What you need
  • devkitpro
  • devkitARM toolchain
  • Basic C/C++ and C# knowledge
  • Any text editor/IDE




Getting Started
  • The Unity 3DS linker uses 16-bit wide characters, but most Makefiles (that I've seen) use 32-bit characters by default. This causes an error when attempting to build the game
    • Before you compile your plugin code (this includes libctru as a whole if you use its objects!), you must add the following flag in your Makefile: -fshort-wchar
    • Example:
    • Makefile:
      CFLAGS    :=    -g -Wall -O2 -mword-relocations -fshort-wchar \
                  -ffunction-sections \
                  $(ARCH)
    • (As I mentioned, you will have to compile libctru with these flags as well if you will be using it)

  • Now, even with a successful compile of your plugin, the Unity linker will likely complain about missing internal symbols that it doesn't normally provide. So we must add them manually.
  • Examples:
    • void* __service_ptr = NULL; (This satisfies the environment handler)
    • If you're going to make use of strlen, you might need to define a local definition for it:
    • C:
      size_t strnlen(const char *s, size_t maxlen) {
          size_t i;
          for (i = 0; i < maxlen && s[i] != '\0'; i++);
          return i;
      }

  • Doing this, you can now compile your file
  • After making, head to the generated lib folder and drag the yourfilename.a file into your Plugins folder (Assets/Plugins/N3DS)
    • Don't forget! If you're using other compiled libraries like libctru you must compile it with 16-bit characters and also drag it into your project!



Implementing your plugin functionality to your Unity project

  • Once you have your plugin loaded into your project, create a new script or edit an existing one
  • Import System.Runtime.InteropServices
  • Use [DllImport("__Internal")]before statically linking a method from your plugin. Example:
    • C#:
      using System.Runtime.InteropServices;
      using UnityEngine;
      
      public class NativePlugin: MonoBehaviour {
          [DllImport("__Internal")]
          private static extern int MyNativeFunction();
      
          void Start() {
              MyNativeFunction();
              Debug.Log("Devkitpro plugin test");
          }
      }
    • [IMPORTANT] It is highly likely that running code using the plugin inside of the Editor will only result in an error on your debug console. To test your plugin, run it from an emulator or on your 3ds console instead

  • You are now able to build your game with new functionality by using your own native plugins with devkitpro! :yay3ds:


Example Project
This example plugin lets you write a file in your SD card

I will attach a ZIP file below that contains:
  • libctru compiled with 16-bit wide characters
  • An example plugin
    • Source file
    • Compiled .a
  • Makefile
  • And a C# script to get you started
Feel free to ask questions or give any suggestions for this below. This is all fairly new, and I have yet to try more of the features offered by devkitpro, as I'm still a bit new to it.
If you have any issues also feel free to comment here, I'll try to help as much as I can with my limited knowledge :yay:
 

Attachments

Last edited by CooingMaxito,
As most of us know, Unity for 3DS is somewhat limited with quite a few features of the 3ds. This functionality can be expanded by using native plugins written in C or C++ that work as libraries to be used in your game.

More recently, I've found a way to write code using devkitpro and compiling it to be able to be used inside of Unity! And I would like to share it here as a basic tutorial to get started for those who are interested.

As of now I've only tried reading and writing to the SDMC, but this could potentially open the door to the many features of devkitpro and its homebrew libraries to use any low level 3DS service that isn't exposed in Unity. I think this could be a break through a barrier that has been a huge headache for devs using this engine for 3ds.

We will cover some of the essential dos and don'ts I've come across, workarounds for some stuff, and the general setup needed




What you need
  • devkitpro
  • devkitARM toolchain
  • Basic C/C++ and C# knowledge
  • Any text editor/IDE




Getting Started
  • The Unity 3DS linker uses 16-bit wide characters, but most Makefiles (that I've seen) use 32-bit characters by default. This causes an error when attempting to build the game
    • Before you compile your plugin code (this includes libctru as a whole if you use its objects!), you must add the following flag in your Makefile: -fshort-wchar
    • Example:
    • Makefile:
      CFLAGS    :=    -g -Wall -O2 -mword-relocations -fshort-wchar \
                  -ffunction-sections \
                  $(ARCH)
    • (As I mentioned, you will have to compile libctru with these flags as well if you will be using it)

  • Now, even with a successful compile of your plugin, the Unity linker will likely complain about missing internal symbols that it doesn't normally provide. So we must add them manually.
  • Examples:
    • void* __service_ptr = NULL; (This satisfies the environment handler)
    • If you're going to make use of strlen, you might need to define a local definition for it:
    • C:
      size_t strnlen(const char *s, size_t maxlen) {
          size_t i;
          for (i = 0; i < maxlen && s[i] != '\0'; i++);
          return i;
      }

  • Doing this, you can now compile your file
  • After making, head to the generated lib folder and drag the yourfilename.a file into your Plugins folder (Assets/Plugins/N3DS)
    • Don't forget! If you're using other compiled libraries like libctru you must compile it with 16-bit characters and also drag it into your project!



Implementing your plugin functionality to your Unity project

  • Once you have your plugin loaded into your project, create a new script or edit an existing one
  • Import System.Runtime.InteropServices
  • Use [DllImport("__Internal")]before statically linking a method from your plugin. Example:
    • C#:
      using System.Runtime.InteropServices;
      using UnityEngine;
      
      public class NativePlugin: MonoBehaviour {
          [DllImport("__Internal")]
          private static extern int MyNativeFunction();
      
          void Start() {
              MyNativeFunction();
              Debug.Log("Devkitpro plugin test");
          }
      }
    • [IMPORTANT] It is highly likely that running code using the plugin inside of the Editor will only result in an error on your debug console. To test your plugin, run it from an emulator or on your 3ds console instead

  • You are now able to build your game with new functionality by using your own native plugins with devkitpro! :yay3ds:


Example Project

I will attach a ZIP file below that contains
  • libctru compiled with 16-bit wide characters
  • An example plugin
    • Source file
    • Compiled .a
  • Makefile
  • And a C# script to get you started
Feel free to ask questions or give any suggestions for this below. This is all fairly new, and I have yet to try more of the features offered by devkitpro, as I'm still a bit new to it.
If you have any issues also feel free to comment here, I'll try to help as much as I can with my limited knowledge :yay:
Thanks CooingMaxito! Great work, as always!
 
  • Like
Reactions: CooingMaxito
Thank you! I hope this can be of use to some in the future
It sure will!
Post automatically merged:

As most of us know, Unity for 3DS is somewhat limited with quite a few features of the 3ds. This functionality can be expanded by using native plugins written in C or C++ that work as libraries to be used in your game.

More recently, I've found a way to write code using devkitpro and compiling it to be able to be used inside of Unity! And I would like to share it here as a basic tutorial to get started for those who are interested.

As of now I've only tried reading and writing to the SDMC, but this could potentially open the door to the many features of devkitpro and its homebrew libraries to use any low level 3DS service that isn't exposed in Unity. I think this could be a break through a barrier that has been a huge headache for devs using this engine for 3ds.

We will cover some of the essential dos and don'ts I've come across, workarounds for some stuff, and the general setup needed




What you need
  • devkitpro
  • devkitARM toolchain
  • Basic C/C++ and C# knowledge
  • Any text editor/IDE




Getting Started
  • The Unity 3DS linker uses 16-bit wide characters, but most Makefiles (that I've seen) use 32-bit characters by default. This causes an error when attempting to build the game
    • Before you compile your plugin code (this includes libctru as a whole if you use its objects!), you must add the following flag in your Makefile: -fshort-wchar
    • Example:
    • Makefile:
      CFLAGS    :=    -g -Wall -O2 -mword-relocations -fshort-wchar \
                  -ffunction-sections \
                  $(ARCH)
    • (As I mentioned, you will have to compile libctru with these flags as well if you will be using it)

  • Now, even with a successful compile of your plugin, the Unity linker will likely complain about missing internal symbols that it doesn't normally provide. So we must add them manually.
  • Examples:
    • void* __service_ptr = NULL; (This satisfies the environment handler)
    • If you're going to make use of strlen, you might need to define a local definition for it:
    • C:
      size_t strnlen(const char *s, size_t maxlen) {
          size_t i;
          for (i = 0; i < maxlen && s[i] != '\0'; i++);
          return i;
      }

  • Doing this, you can now compile your file
  • After making, head to the generated lib folder and drag the yourfilename.a file into your Plugins folder (Assets/Plugins/N3DS)
    • Don't forget! If you're using other compiled libraries like libctru you must compile it with 16-bit characters and also drag it into your project!



Implementing your plugin functionality to your Unity project

  • Once you have your plugin loaded into your project, create a new script or edit an existing one
  • Import System.Runtime.InteropServices
  • Use [DllImport("__Internal")]before statically linking a method from your plugin. Example:
    • C#:
      using System.Runtime.InteropServices;
      using UnityEngine;
      
      public class NativePlugin: MonoBehaviour {
          [DllImport("__Internal")]
          private static extern int MyNativeFunction();
      
          void Start() {
              MyNativeFunction();
              Debug.Log("Devkitpro plugin test");
          }
      }
    • [IMPORTANT] It is highly likely that running code using the plugin inside of the Editor will only result in an error on your debug console. To test your plugin, run it from an emulator or on your 3ds console instead

  • You are now able to build your game with new functionality by using your own native plugins with devkitpro! :yay3ds:


Example Project

I will attach a ZIP file below that contains
  • libctru compiled with 16-bit wide characters
  • An example plugin
    • Source file
    • Compiled .a
  • Makefile
  • And a C# script to get you started
Feel free to ask questions or give any suggestions for this below. This is all fairly new, and I have yet to try more of the features offered by devkitpro, as I'm still a bit new to it.
If you have any issues also feel free to comment here, I'll try to help as much as I can with my limited knowledge :yay:
I tried it out and I'm not getting a lib folder or any .a files.
 
Last edited by NN3DSLLLXB,
  • Love
Reactions: CooingMaxito
Holy smokes I just realized, with this we could probably finally be able to get input from the Select button :wtf:

I need to try this...
 
I’ve come across a few more issues. I’ll document my findings and add a Troubleshooting section at the bottom if you guys get any problems trying to add certain functions
 
As most of us know, Unity for 3DS is somewhat limited with quite a few features of the 3ds. This functionality can be expanded by using native plugins written in C or C++ that work as libraries to be used in your game.

More recently, I've found a way to write code using devkitpro and compiling it to be able to be used inside of Unity! And I would like to share it here as a basic tutorial to get started for those who are interested.

As of now I've only tried reading and writing to the SDMC, but this could potentially open the door to the many features of devkitpro and its homebrew libraries to use any low level 3DS service that isn't exposed in Unity. I think this could be a break through a barrier that has been a huge headache for devs using this engine for 3ds.

We will cover some of the essential dos and don'ts I've come across, workarounds for some stuff, and the general setup needed




What you need
  • devkitpro
  • devkitARM toolchain
  • Basic C/C++ and C# knowledge
  • Any text editor/IDE




Getting Started
  • The Unity 3DS linker uses 16-bit wide characters, but most Makefiles (that I've seen) use 32-bit characters by default. This causes an error when attempting to build the game
    • Before you compile your plugin code (this includes libctru as a whole if you use its objects!), you must add the following flag in your Makefile: -fshort-wchar
    • Example:
    • Makefile:
      CFLAGS    :=    -g -Wall -O2 -mword-relocations -fshort-wchar \
                  -ffunction-sections \
                  $(ARCH)
    • (As I mentioned, you will have to compile libctru with these flags as well if you will be using it)

  • Now, even with a successful compile of your plugin, the Unity linker will likely complain about missing internal symbols that it doesn't normally provide. So we must add them manually.
  • Examples:
    • void* __service_ptr = NULL; (This satisfies the environment handler)
    • If you're going to make use of strlen, you might need to define a local definition for it:
    • C:
      size_t strnlen(const char *s, size_t maxlen) {
          size_t i;
          for (i = 0; i < maxlen && s[i] != '\0'; i++);
          return i;
      }

  • Doing this, you can now compile your file
  • After making, head to the generated lib folder and drag the yourfilename.a file into your Plugins folder (Assets/Plugins/N3DS)
    • Don't forget! If you're using other compiled libraries like libctru you must compile it with 16-bit characters and also drag it into your project!



Implementing your plugin functionality to your Unity project

  • Once you have your plugin loaded into your project, create a new script or edit an existing one
  • Import System.Runtime.InteropServices
  • Use [DllImport("__Internal")]before statically linking a method from your plugin. Example:
    • C#:
      using System.Runtime.InteropServices;
      using UnityEngine;
      
      public class NativePlugin: MonoBehaviour {
          [DllImport("__Internal")]
          private static extern int MyNativeFunction();
      
          void Start() {
              MyNativeFunction();
              Debug.Log("Devkitpro plugin test");
          }
      }
    • [IMPORTANT] It is highly likely that running code using the plugin inside of the Editor will only result in an error on your debug console. To test your plugin, run it from an emulator or on your 3ds console instead

  • You are now able to build your game with new functionality by using your own native plugins with devkitpro! :yay3ds:


Example Project
This example plugin lets you write a file in your SD card

I will attach a ZIP file below that contains:
  • libctru compiled with 16-bit wide characters
  • An example plugin
    • Source file
    • Compiled .a
  • Makefile
  • And a C# script to get you started
Feel free to ask questions or give any suggestions for this below. This is all fairly new, and I have yet to try more of the features offered by devkitpro, as I'm still a bit new to it.
If you have any issues also feel free to comment here, I'll try to help as much as I can with my limited knowledge :yay:

This is a great guide for those wanting to expand Unity's capabilities on the 3DS! One thing to note is that, when dealing with low-level services through devkitPro, handling memory and resource management carefully becomes crucial, especially since some Unity features are not optimized for homebrew development.

If you run into issues with the plugin not being recognized in the Unity editor, remember that as you pointed out, testing on the actual 3DS or emulator is key.

Looking forward to seeing more on how devkitPro can push the boundaries of Unity on the 3DS!
 
Last edited by kravoskilaura,
  • Like
Reactions: CooingMaxito
This is a great guide for those wanting to expand Unity's capabilities on the 3DS! One thing to note is that, when dealing with low-level services through devkitPro, handling memory and resource management carefully becomes crucial, especially since some Unity features are not optimized for homebrew development.

If you run into issues with the plugin not being recognized in the Unity editor, remember that as you pointed out, testing on the actual 3DS or emulator is key.

Looking forward to seeing more on how devkitPro can push the boundaries of Unity on the 3DS!
Yes I absolutely agree! I understand that memory management will be something that needs to be tackled sooner than later

I'm slowly learning dkp so that I can add new features, hopefully I can get something cool put together using this! I get that this method is very new and needs a lot of trial and error currently haha

I'll keep you guys updated!
 
So uh, it now crashes the console when trying to run anything in the plugin

Idk what's causing this but uh, not gud

EDIT: Removed the script that calls the plugin from the scene and still crashes
EDIT 2: I HAD TO REMOVE THE FRICKING PLUGIN TO MAKE IT NOT FUCKING CRASH
EDOT: AAAAAAAAAAAAAAAAAAAAAA
 
Last edited by CooingMaxito,
  • Sad
Reactions: SDA
So uh, it now crashes the console when trying to run anything in the plugin

Idk what's causing this but uh, not gud

EDIT: Removed the script that calls the plugin from the scene and still crashes
EDIT 2: I HAD TO REMOVE THE FRICKING PLUGIN TO MAKE IT NOT FUCKING CRASH
EDOT: AAAAAAAAAAAAAAAAAAAAAA
Looks like the 3DS system doesn't like this kind of plugin at all. Sorry to hear about this...
 
  • Sad
Reactions: CooingMaxito
Okay so uh, this might be on pause until I can figure out what the heck is going on lol

I feel like I'm close to getting it to work, since it runs on citra... I just need it to run on 3ds, which doesn't work for some reason (yet)
Post automatically merged:

Looks like the 3DS system doesn't like this kind of plugin at all. Sorry to hear about this...
Yeah sounds like it, sadge
:sad:
 
  • Sad
Reactions: SDA
Okay so I’ve done a lot of trial and error, and I THINK that I’ve narrowed down where this ridiculous crash is coming from

So as you guys know the current issue is that the code pretty much works flawlessly on citra, but the moment I try to run boot the game on actual hardware, it instantly throws a crash.

To isolate the issue I did a lot of things, but as of now I have ended up just making a naked version of the plugin by gutting the code of all 3ds specific thingies, also removed the inclusion of 3ds.h, and reduced it all to a basic a + b method, and this STILL crashed on console

My currently working theory is that since the code is as basic as it can get, I doubt the logic is the problem, so I think this narrows it down to the Makefile pretty much

I am going to try to strip my Makefile down to the absolute bare minimum as well and see what works to finally place the code in memory without the console having a complete meltdown

Fingers crossed, I’ll update soon as I’m not home yet
 
  • Like
Reactions: I pwned U!
Okay so very late update on this. I couldn't fix it that way, I'll still be trying other things that could get it to work, but for now don't get your hopes up lmao

As I mentioned in my Undertale 3ds thread, because of many life circumstances I am unable to have the proper time to look into this and also develop Undertale 3ds, so please be a bit patient

Updated the main post with this message at the top:
"This method currently only works in emulator, because it crashes on 3ds hardware. I am still looking into this issue so until I get it fixed you should probably hold off on doing this, unless you want to start writing a dkp plugin that may or may not be able to be used on an actual 3ds in the future... lol"

P.S If you somehow find a way to make this work on hardware please leave a post here! That would be greatly appreciated
 
  • Like
Reactions: I pwned U!
Okay so very late update on this. I couldn't fix it that way, I'll still be trying other things that could get it to work, but for now don't get your hopes up lmao

As I mentioned in my Undertale 3ds thread, because of many life circumstances I am unable to have the proper time to look into this and also develop Undertale 3ds, so please be a bit patient

Updated the main post with this message at the top:
"This method currently only works in emulator, because it crashes on 3ds hardware. I am still looking into this issue so until I get it fixed you should probably hold off on doing this, unless you want to start writing a dkp plugin that may or may not be able to be used on an actual 3ds in the future... lol"

P.S If you somehow find a way to make this work on hardware please leave a post here! That would be greatly appreciated
"withlovexanax" probably knows how to solve this problem but is hard to contact him xd
 
Just tried a simple cpp to check if I can see and add some magic numbers but when compiling I'm getting:

Code:
An empty string is not considered a valid value.
  at System.Enum.Parse (System.Type enumType, System.String value, Boolean ignoreCase) [0x00050] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Enum.cs:615
  at System.Enum.Parse (System.Type enumType, System.String value) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Enum.cs:547
  at UnityEditor.PostProcessN3DS.CopyNativePluginFiles (Boolean developmentBuild, UnityEditor.PluginFileList pluginFiles, System.Collections.Generic.List`1 dependencyList, System.String outputDirectory) [0x0007f] in C:\buildslave\unity\build\PlatformDependent\N3DS\Editor\Managed\PostProcessN3DS.cs:397
  at UnityEditor.PostProcessN3DS.CreateAXF (Boolean developmentBuild, System.String stagingArea) [0x00473] in C:\buildslave\unity\build\PlatformDependent\N3DS\Editor\Managed\PostProcessN3DS.cs:565
  at UnityEditor.PostProcessN3DS.CreateCCI (Boolean developmentBuild, System.Collections.Generic.List`1 cfaList, System.String installPath, System.String stagingArea) [0x0001f] in C:\buildslave\unity\build\PlatformDependent\N3DS\Editor\Managed\PostProcessN3DS.cs:936
  at UnityEditor.PostProcessN3DS.PostProcess (BuildTarget target, BuildOptions options, System.String installPath, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String stagingAreaDataManaged, UnityEditor.RuntimeClassRegistry usedClassRegistry) [0x00377] in C:\buildslave\unity\build\PlatformDependent\N3DS\Editor\Managed\PostProcessN3DS.cs:275
UnityEditor.HostView:OnGUI()

Have you seen something like this?


Edit: compiling again compiles... maybe unity for 3ds issue?

1774985175311.png

Post automatically merged:

Btw, I compiled libctru using the flag you mentioned and my plugin referencing libctru (3ds.h), but Unity can't compile due to missing stuff even with your libs. Did you add something to dependencies?

Code:
stderr[
armlink : error L6218:  Undefined symbol strnlen (referred from srv.o).
armlink : error L6218:  Undefined symbol __system_runflags (referred from apt.o).
armlink : error L6218:  Undefined symbol __apt_appid (referred from apt.o).
armlink : error L6218:  Undefined symbol __service_ptr (referred from env.o).
armlink : error L6218:  Undefined symbol memalign (referred from thread.o).
armlink : error L6218:  Undefined symbol __tdata_align (referred from thread.o).
armlink : error L6218:  Undefined symbol __tls_start (referred from thread.o).
armlink : error L6218:  Undefined symbol __tls_end (referred from thread.o).
armlink : error L6218:  Undefined symbol __tdata_lma (referred from thread.o).
armlink : error L6218:  Undefined symbol __tdata_lma_end (referred from thread.o).
armlink : error L6218:  Undefined symbol __sf (referred from thread.o).
armlink : error L6218:  Undefined symbol fake_heap_start (referred from allocateHeaps.o).
armlink : error L6218:  Undefined symbol fake_heap_end (referred from allocateHeaps.o).
armlink : error L6218:  Undefined symbol __system_arglist (referred from initArgv.o).
armlink : error L6218:  Undefined symbol _impure_ptr (referred from syscalls.o).
armlink : error L6218:  Undefined symbol __getreent (referred from 3dslink.o).
armlink : error L6218:  Undefined symbol dup2 (referred from 3dslink.o).
armlink : error L6218:  Undefined symbol close (referred from 3dslink.o).
armlink : error L6218:  Undefined symbol __libc_init_array (referred from stack_adjust.o).
armlink : error L6218:  Undefined symbol __get_handle (referred from soc_connect.o).
armlink : error L6218:  Undefined symbol devoptab_list (referred from soc_connect.o).
armlink : error L6218:  Undefined symbol FindDevice (referred from soc_socket.o).
armlink : error L6218:  Undefined symbol __alloc_handle (referred from soc_socket.o).
armlink : error L6218:  Undefined symbol __release_handle (referred from soc_socket.o).
armlink : error L6218:  Undefined symbol RemoveDevice (referred from archive_dev.o).
armlink : error L6218:  Undefined symbol AddDevice (referred from archive_dev.o).
armlink : error L6218:  Undefined symbol GetDeviceOpTab (referred from archive_dev.o).
armlink : error L6218:  Undefined symbol setDefaultDevice (referred from archive_dev.o).
armlink : error L6218:  Undefined symbol chdir (referred from archive_dev.o).
 
Last edited by Manurocker95,
  • Like
Reactions: CooingMaxito
Just tried a simple cpp to check if I can see and add some magic numbers but when compiling I'm getting:

Code:
An empty string is not considered a valid value.
  at System.Enum.Parse (System.Type enumType, System.String value, Boolean ignoreCase) [0x00050] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Enum.cs:615
  at System.Enum.Parse (System.Type enumType, System.String value) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Enum.cs:547
  at UnityEditor.PostProcessN3DS.CopyNativePluginFiles (Boolean developmentBuild, UnityEditor.PluginFileList pluginFiles, System.Collections.Generic.List`1 dependencyList, System.String outputDirectory) [0x0007f] in C:\buildslave\unity\build\PlatformDependent\N3DS\Editor\Managed\PostProcessN3DS.cs:397
  at UnityEditor.PostProcessN3DS.CreateAXF (Boolean developmentBuild, System.String stagingArea) [0x00473] in C:\buildslave\unity\build\PlatformDependent\N3DS\Editor\Managed\PostProcessN3DS.cs:565
  at UnityEditor.PostProcessN3DS.CreateCCI (Boolean developmentBuild, System.Collections.Generic.List`1 cfaList, System.String installPath, System.String stagingArea) [0x0001f] in C:\buildslave\unity\build\PlatformDependent\N3DS\Editor\Managed\PostProcessN3DS.cs:936
  at UnityEditor.PostProcessN3DS.PostProcess (BuildTarget target, BuildOptions options, System.String installPath, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String stagingAreaDataManaged, UnityEditor.RuntimeClassRegistry usedClassRegistry) [0x00377] in C:\buildslave\unity\build\PlatformDependent\N3DS\Editor\Managed\PostProcessN3DS.cs:275
UnityEditor.HostView:OnGUI()

Have you seen something like this?


Edit: compiling again compiles... maybe unity for 3ds issue?
Yeah I believe that is more of a unity 3ds issue, it usually sorts itself out without much of an issue

Btw, I compiled libctru using the flag you mentioned and my plugin referencing libctru (3ds.h), but Unity can't compile due to missing stuff even with your libs. Did you add something to dependencies?

Code:
stderr[
armlink : error L6218:  Undefined symbol strnlen (referred from srv.o).
armlink : error L6218:  Undefined symbol __system_runflags (referred from apt.o).
armlink : error L6218:  Undefined symbol __apt_appid (referred from apt.o).
armlink : error L6218:  Undefined symbol __service_ptr (referred from env.o).
armlink : error L6218:  Undefined symbol memalign (referred from thread.o).
armlink : error L6218:  Undefined symbol __tdata_align (referred from thread.o).
armlink : error L6218:  Undefined symbol __tls_start (referred from thread.o).
armlink : error L6218:  Undefined symbol __tls_end (referred from thread.o).
armlink : error L6218:  Undefined symbol __tdata_lma (referred from thread.o).
armlink : error L6218:  Undefined symbol __tdata_lma_end (referred from thread.o).
armlink : error L6218:  Undefined symbol __sf (referred from thread.o).
armlink : error L6218:  Undefined symbol fake_heap_start (referred from allocateHeaps.o).
armlink : error L6218:  Undefined symbol fake_heap_end (referred from allocateHeaps.o).
armlink : error L6218:  Undefined symbol __system_arglist (referred from initArgv.o).
armlink : error L6218:  Undefined symbol _impure_ptr (referred from syscalls.o).
armlink : error L6218:  Undefined symbol __getreent (referred from 3dslink.o).
armlink : error L6218:  Undefined symbol dup2 (referred from 3dslink.o).
armlink : error L6218:  Undefined symbol close (referred from 3dslink.o).
armlink : error L6218:  Undefined symbol __libc_init_array (referred from stack_adjust.o).
armlink : error L6218:  Undefined symbol __get_handle (referred from soc_connect.o).
armlink : error L6218:  Undefined symbol devoptab_list (referred from soc_connect.o).
armlink : error L6218:  Undefined symbol FindDevice (referred from soc_socket.o).
armlink : error L6218:  Undefined symbol __alloc_handle (referred from soc_socket.o).
armlink : error L6218:  Undefined symbol __release_handle (referred from soc_socket.o).
armlink : error L6218:  Undefined symbol RemoveDevice (referred from archive_dev.o).
armlink : error L6218:  Undefined symbol AddDevice (referred from archive_dev.o).
armlink : error L6218:  Undefined symbol GetDeviceOpTab (referred from archive_dev.o).
armlink : error L6218:  Undefined symbol setDefaultDevice (referred from archive_dev.o).
armlink : error L6218:  Undefined symbol chdir (referred from archive_dev.o).
I also got this same problem while adding more functionality to my own plugins, I believe that when adding a devkitpro plugin Unity is essentially trying to link a plugin that expects a full 3DS environment, but Unity's linker/armlink doesn't know where to find the devkitPro system libraries or how to initialize them, that could maybe explain why it throws Undefined symbol

Unfortunately, you might have to add stubs or the methods for those undefined symbols manually in your plugin, that's what I basically did and it managed to compile

Also unfortunate news, as I mentioned at the top of the post, a built game using dkp plugins does compile and does run on emulator, but I couldn't manage to get it up and running on hardware...
Still unsure what causes this, I've yet to keep looking into it but for now I don't have a solution for that specific problem :sad:

If you manage to somehow get it working, that would be great, but I imagine it will be pretty hard to do
Post automatically merged:

  • Now, even with a successful compile of your plugin, the Unity linker will likely complain about missing internal symbols that it doesn't normally provide. So we must add them manually.
  • Examples:
    • void* __service_ptr = NULL; (This satisfies the environment handler)
    • If you're going to make use of strlen, you might need to define a local definition for it:
    • C:
      size_t strnlen(const char *s, size_t maxlen) {
          size_t i;
          for (i = 0; i < maxlen && s[i] != '\0'; i++);
          return i;
      }
Here's what I'm talking about for the missing internal symbols thingy
 
Yeah I believe that is more of a unity 3ds issue, it usually sorts itself out without much of an issue


I also got this same problem while adding more functionality to my own plugins, I believe that when adding a devkitpro plugin Unity is essentially trying to link a plugin that expects a full 3DS environment, but Unity's linker/armlink doesn't know where to find the devkitPro system libraries or how to initialize them, that could maybe explain why it throws Undefined symbol

Unfortunately, you might have to add stubs or the methods for those undefined symbols manually in your plugin, that's what I basically did and it managed to compile

Also unfortunate news, as I mentioned at the top of the post, a built game using dkp plugins does compile and does run on emulator, but I couldn't manage to get it up and running on hardware...
Still unsure what causes this, I've yet to keep looking into it but for now I don't have a solution for that specific problem :sad:

If you manage to somehow get it working, that would be great, but I imagine it will be pretty hard to do
Post automatically merged:


Here's what I'm talking about for the missing internal symbols thingy
Limiting to what libctru can link ended in whatyou said. On Emulator it works but retail crashes with "undefined instruction" error, even before calling the plugin functions... The ctr sdk probably misses some stuff the regular hb playback has. Dang...

Or maybe it's due to the fact that the CTR SDK blocks the SD without development build setup. We should try other DKP functionalities in case it's that.
 
Last edited by Manurocker95,

Site & Scene News

Popular threads in this forum