digitalmars.D.learn - Scope of import
- DLearner (38/38) May 14 2021 ```
- Mike Parker (10/19) May 15 2021 Your error is a linker error. Imports have nothing to do with the
- DLearner (2/3) May 15 2021 rdmd main.d
- Mike Parker (6/11) May 15 2021 Then it must be an issue with rdmd. The following both work as
- DLearner (3/4) May 15 2021 rdmd build 20210311
- Mike Parker (13/18) May 15 2021 Okay, so it's definitely a bug in rdmd. Change module A to look
- Adam D. Ruppe (12/13) May 15 2021 rdmd sucks, it runs the compiler twice and get the list of
- Dennis (2/4) May 15 2021 You can do `dmd -i -run main.d`
- Adam D. Ruppe (3/4) May 15 2021 Yeah but that's weird with how it handles arguments and without
- Alain De Vos (5/5) May 15 2021 In unix i give the compiler:
- DLearner (6/8) May 15 2021 On Saturday, 15 May 2021 at 11:38:22 UTC, Adam D. Ruppe wrote>
``` // main void main() { import A; // import B; import std.stdio; writeln("Entered main"); fnA1(); writeln("Leaving main"); } ``` ``` module A; void fnA1() { import B; import std.stdio; writeln("Entered fnA1"); fnB1(); writeln("Leaving fnA1"); } ``` ``` module B; void fnB1() { import std.stdio; writeln("Entered fnB1"); writeln("Leaving fnB1"); } ``` 1. Code above compiles but fails on linker step with 'Error 42 Symbol Undefined'. To me, unexpected behaviour as imports arranged to pick up symbols (with minimum scope). 2. Uncommenting the 'import B' in main everything works correctly. To me, particularly unexpected behaviour as no symbol from B directly used in main (also undesirable to set scope unnecessarily wide). Best regards
May 14 2021
On Saturday, 15 May 2021 at 06:55:47 UTC, DLearner wrote:1. Code above compiles but fails on linker step with 'Error 42 Symbol Undefined'. To me, unexpected behaviour as imports arranged to pick up symbols (with minimum scope).Your error is a linker error. Imports have nothing to do with the linker. They are for the compiler to know which symbols are available in the module it's currently compiling. But every symbol that you use needs to be linked by the linker, and that's a separate step.2. Uncommenting the 'import B' in main everything works correctly.That's odd. What's your command line?To me, particularly unexpected behaviour as no symbol from B directly used in main (also undesirable to set scope unnecessarily wide).Whether you use a symbol in main or not is irrelevant to the linker. Any symbol accessed anywhere in your program must ultimately be linked in.
May 15 2021
On Saturday, 15 May 2021 at 07:05:00 UTC, Mike Parker wrote:That's odd. What's your command line?rdmd main.d
May 15 2021
On Saturday, 15 May 2021 at 07:15:51 UTC, DLearner wrote:On Saturday, 15 May 2021 at 07:05:00 UTC, Mike Parker wrote:Then it must be an issue with rdmd. The following both work as expected, whether your the `import B;` in `main` is commented out or not: dmd -i main.d dmd main.d A.d B.dThat's odd. What's your command line?rdmd main.d
May 15 2021
On Saturday, 15 May 2021 at 07:19:08 UTC, Mike Parker wrote:Then it must be an issue with rdmd...rdmd build 20210311 Running under Win-10.
May 15 2021
On Saturday, 15 May 2021 at 07:15:51 UTC, DLearner wrote:On Saturday, 15 May 2021 at 07:05:00 UTC, Mike Parker wrote:Okay, so it's definitely a bug in rdmd. Change module A to look like this and it works properly: ```d module A; import B; void fnA1() { import std.stdio; writeln("Entered fnA1"); fnB1(); writeln("Leaving fnA1"); } ```That's odd. What's your command line?rdmd main.d
May 15 2021
On Saturday, 15 May 2021 at 07:15:51 UTC, DLearner wrote:rdmd main.drdmd sucks, it runs the compiler twice and get the list of imports and even then it might not see them all. Just use dmd -i main.d instead. It will be about 2x faster and more reliable. The downside differences though: * rdmd runs the program too, dmd -i just compiles. You run the program separately. * rdmd will cache the executable, dmd -i will always recompile. But since running the program is a separate step, you just run it yourself if you don't want to recompile, and run dmd if you do.
May 15 2021
On Saturday, 15 May 2021 at 11:38:22 UTC, Adam D. Ruppe wrote:* rdmd runs the program too, dmd -i just compiles. You run the program separately.You can do `dmd -i -run main.d`
May 15 2021
On Saturday, 15 May 2021 at 11:46:49 UTC, Dennis wrote:You can do `dmd -i -run main.d`Yeah but that's weird with how it handles arguments and without the compilation cache it gets really annoying to use.
May 15 2021
In unix i give the compiler: ``` ldc2 `find . -name \*.d -print` ``` So he always takes all sourcefiles
May 15 2021
On Saturday, 15 May 2021 at 11:38:22 UTC, Adam D. Ruppe wrote> Just use ```dmd -i main.d instead. It will be about 2x faster and more reliable.``` Your suggestion worked. Thank you.
May 15 2021