Thread overview
how to import file from another path in dub ?
Jul 05, 2018
Flaze07
Jul 05, 2018
Timoses
Jul 05, 2018
Flaze07
July 05, 2018
I have a dub project, and I put the importPath to the path of the file I want to import and the source file to the source folder, and it appears that I have succeeded at importing the module, but there's one problem, it appears like I need to define some sort of thing, because the error says " Error 42: Symbol Undefined __D9animation12__ModuleInfoZ" ( I am using coedit ), do I need to compile the file into .lib ?
July 05, 2018
On Thursday, 5 July 2018 at 05:38:29 UTC, Flaze07 wrote:
> I have a dub project, and I put the importPath to the path of the file I want to import and the source file to the source folder, and it appears that I have succeeded at importing the module, but there's one problem, it appears like I need to define some sort of thing, because the error says " Error 42: Symbol Undefined __D9animation12__ModuleInfoZ" ( I am using coedit ), do I need to compile the file into .lib ?

You can follow what happens when you do `dub -v`. When using the `importPaths` the compiler will import the path during compilation, but not compile the files in importPath and put it in the object file. The call is something like this:

dmd -I<myImportPath> <mySourceFiles>

Afterwards the linker tries to find the function defined in import path, which however is not found as it was not compiled.
My guess is that this could be useful when using something like interface files (in D .di files, or in C/C++ header files) which only has declarations).
Then you would have to pass the linker the library or object file which actually contains the compiled functions. Otherwise you get an error like the one you have.

Depending on your use case I see these options:
- If you have a library that defines the symbols that you are using in the imported files you could use the dub `libs` setting
- Otherwise, if you're just using the other folder to separate code you can redefine dub's `sourcePaths`. I believe it overwrites the previous, so you have to include your 'source' folder again:

"sourcePaths": ["source", "<importPath>"]


When using sourcePaths, dub actually passes all files within all mentioned paths to dmd to compile.


Hope I got it right : D.
July 05, 2018
On Thursday, 5 July 2018 at 08:55:13 UTC, Timoses wrote:
> Depending on your use case I see these options:
> - If you have a library that defines the symbols that you are using in the imported files you could use the dub `libs` setting
> - Otherwise, if you're just using the other folder to separate code you can redefine dub's `sourcePaths`. I believe it overwrites the previous, so you have to include your 'source' folder again:
>
> "sourcePaths": ["source", "<importPath>"]
>
>
> When using sourcePaths, dub actually passes all files within all mentioned paths to dmd to compile.
>
>
> Hope I got it right : D.

I see...so that means, I only need importPaths if I have compiled it to libs got it