www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to import file from another path in dub ?

reply Flaze07 <christianseiji.cs gmail.com> writes:
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 ?
Jul 04 2018
parent reply Timoses <timosesu gmail.com> writes:
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.
Jul 05 2018
parent Flaze07 <christianseiji.cs gmail.com> writes:
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
Jul 05 2018