Bug 8856 – import inside function sometimes causes link errors

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-19T18:18:13Z
Last change time
2017-12-05T20:40:21Z
Assigned to
No Owner
Creator
thelastmammoth
Depends on
8858

Comments

Comment #0 by thelastmammoth — 2012-10-19T18:18:13Z
I sometimes get link errors eg: void fun(){ import mypackage.mymodule; mypackage.mymodule.myfun(); //might cause link error, depending on contents of myfun } (cf http://forum.dlang.org/thread/[email protected])
Comment #1 by andrej.mitrovich — 2012-10-19T18:44:09Z
We'll need a failing test-case. What contents cause the linker error?
Comment #2 by thelastmammoth — 2012-10-19T20:18:49Z
(In reply to comment #1) > We'll need a failing test-case. What contents cause the linker error? here's a failure case which I simplified to the maximum. Note that link error occurs with rdmd, not with dmd, as shown below. So that is a problem with rdmd failing to find dependencies in some cases. ---- rdmd ${DFLAGS} main =>Undefined symbols for architecture x86_64: "_D9main_aux24fun1FZv", referenced from: _D8main_aux4testFZv in main.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status ---- dmd ${DFLAGS} main main_aux main_aux2 => works ---- Here are the files: . ├── main.d ├── main_aux.d └── main_aux2.d cat main.d import main_aux; void main(){ test; } cat main_aux.d module main_aux; //putting the main function here removes link error //void main(){ // test; //} //import main_aux2; //uncomment removes link error void test(){ import main_aux2; fun1(); } cat main_aux2.d module main_aux2; void fun1() { }
Comment #3 by thelastmammoth — 2012-10-19T20:20:57Z
In the above post, DFLAGS is just the usual import path to dmdroot/phobos, druntime/import and phobos library path.
Comment #4 by andrej.mitrovich — 2012-10-19T20:34:14Z
(In reply to comment #2) > snip The problem is DMD's -v option doesn't output dependencies when an import is function local. test.d: module test; import foo; void main() { } foo.d: module foo; import bar; bar.d is empty $ dmd -c -v test.d > import foo (foo.d) > import bar (bar.d) Now use a local import in foo.d: foo.d: module foo; void loc() { import bar; } $ dmd -c -v test.d > import foo (foo.d) DMD doesn't output the import to bar.d when using -v. That has to be fixed.
Comment #5 by andrej.mitrovich — 2013-01-11T19:15:13Z
Caused by same issue as in Issue 7016. *** This issue has been marked as a duplicate of issue 7016 ***
Comment #6 by timothee.cour2 — 2017-12-05T20:40:21Z
*** This issue has been marked as a duplicate of issue 8858 ***