Directly compiling a D program with other libraries
Jeremy
jtbx at disroot.org
Mon Mar 13 18:52:05 UTC 2023
> That's a linker error, meaning the missing symbol isn't
> available to link into the executable. You need to compile the
> source of all the libraries you use and make sure the resultant
> binaries are available for the linker to link into the
> executable.
>
> The -I switch you've passed tells the compiler where to find
> imported modules. The compiler needs parse them to know which
> symbols are available for you to use when it's compiling your
> code. (The current working directory is the default anyway, so
> you don't need to pass `-I.` for that.)
>
> By default, the compiler does not compile imported modules. If
> you add `-i` to the command line, then it will compile all of
> the modules you import (as long as they're in the `-I` path),
> excluding the DRuntime and Phobos modules. It will then also
> pass all of the compiled object files to the linker, so then
> your linker error should go away.
>
Using `-i` solved my problem, thank you very much!
> However, when you choose not to use dub, you need to also
> ensure that you are accounting for any special compiler flags
> the libraries you use may require (for example, specific
> `-version` values). If they're configured to compile as static
> or shared libraries, it may be easier just to store the source
> for each of them outside of your project's source tree, use dub
> to build each of them, and then pass the compiled libraries to
> the compiler when you build your program. In that case, you
> wouldn't use `-i`. Just make sure that `-I` is correctly
> configured in that case.
Okay, thanks.
More information about the Digitalmars-d-learn
mailing list