Comment #0 by sigurdbergsvela — 2015-06-10T01:34:49Z
Created attachment 1526
Project to show the bug
When importing std.stdio in a specific context, causes an "undefined symbols for architecture"
Its easier if I just include the project(Just a test project, so its small).
Comment #1 by k.hara.pg — 2015-06-10T02:24:11Z
(In reply to sigsve from comment #0)
> When importing std.stdio in a specific context, causes an "undefined symbols
> for architecture"
I'm on Windows so I need to guess what "undefined symbols for architecture" is.
Maybe it's a linker error? As I can see the Rakefile, it does not compile and link the file src/collector/Stack.d. It would be the reason of linker error.
D's import is not same with the #include in C. If you import a module, you also need to compile and link it normally.
Comment #2 by sigurdbergsvela — 2015-06-10T04:22:13Z
My apologies for being vague, I was hoping you'd have a Mac available.
It is definitely a linking error(This is the error I get):
Undefined symbols for architecture x86_64:
"_D5Stack12__ModuleInfoZ", referenced from:
_D4Main12__ModuleInfoZ in Main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
But, as said, this error only shows if I include std.stdio in the Stack.d file
Comment #3 by sigurdbergsvela — 2015-06-10T04:27:48Z
Although, you are right.
Sorry, I though DMD compiled and linked Stack.d automagically(Which it seems to have done, when I do not import std.stdio)
But when I compile each file separately to .o files, and link them, it works.
Comment #4 by k.hara.pg — 2015-06-10T14:46:03Z
(In reply to sigsve from comment #2)
> Undefined symbols for architecture x86_64:
> "_D5Stack12__ModuleInfoZ", referenced from:
> _D4Main12__ModuleInfoZ in Main.o
> ld: symbol(s) not found for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
It says a ModuleInfo symbol of Stack module is missing.
(In reply to sigsve from comment #3)
> Sorry, I though DMD compiled and linked Stack.d automagically(Which it seems
> to have done, when I do not import std.stdio)
If you don't list a module file in dmd command line, the symbols in it are compiled (== semantic analysis done) but those code won't be output to any object files.
When you don't add `import std.stdio;` in Stack.d, today's dmd fortunately determines the ModuleInfo object of Stack module is unnecessary, so the build will succeed. However it's just undocumented behavior, and might be changed in the future.
So I'd recommend to compile and link Stack.d always when you import it from other modules.
Comment #5 by dlang-bugzilla — 2017-07-21T09:50:06Z