Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Adding an additional include dir to native code

Discussion in 'Project Tiny' started by lindyrock, Mar 31, 2021.

  1. lindyrock

    lindyrock

    Joined:
    Apr 12, 2019
    Posts:
    6
    I'm building a feature that currently has native code called in with DllImport to the regular C# functions. I'm able to build it when my #include directives are relative to the calling file, e.g. in myFile.h:

    #include "../../../otherDir/otherFile.h"

    Which is ugly, a pain, and obviously not the right way to do it. I'd like to just include the base directory as an additional include dir, so that everything can be specified relative to the root of my cpp code folder. How can I specify a new include path like that?

    The cpp~ folder is automatically included from the Project.Unity > Assets > MyCompanyName > MyDemoName > Runtime > cpp~ > {a bunch of .cc/.h files live here}
     
    tonialatalo likes this.
  2. kevinmv

    kevinmv

    Unity Technologies

    Joined:
    Nov 15, 2018
    Posts:
    51
    It's not documented currently but you can put a an "include" directory inside of your "cpp~" directory and the directory will be usable by assemblies with a reference. You can see the Unity.Runtime assembly make use of this feature.

    Note, the "cpp~" needs to be beside your "myassembly.asmdef" file.

    Hope this helps!
    Kev
     
    tonialatalo likes this.
  3. lindyrock

    lindyrock

    Joined:
    Apr 12, 2019
    Posts:
    6
    That fixes it! Thanks!