Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    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:
    39
    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!