www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24127] New: ImportC - no way to organize files

https://issues.dlang.org/show_bug.cgi?id=24127

          Issue ID: 24127
           Summary: ImportC - no way to organize files
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: schveiguy gmail.com

Created attachment 1889
  --> https://issues.dlang.org/attachment.cgi?id=1889&action=edit
Tarball of example code to try

When a C file is imported through a path other than the root path, the compiler
can use the C file's declarations from a root module (one that is passed on the
compile line). However, when the C file is also passed on the command line, the
compiler complains that the file can only be imported as a non-packaged file.

I have attached an example, reproduced here:

```c foo/bar/cstuff.c
void fn() {}
```

```d foo/bar/dstuff.d
module foo.bar.dstuff;

import foo.bar.cstuff;

void main()
{
    fn();
}
```

When compiling both on the command line:

```
steves homebuild:~/importcbug$ dmd foo/bar/*
foo/bar/dstuff.d(3): Error: module `cstuff` from file foo/bar/cstuff.c must be
imported with 'import cstuff;'
```

However, when compiling the C module separately it succeeds:

```
steves homebuild:~/importcbug$ dmd -c foo/bar/cstuff.c
steves homebuild:~/importcbug$ dmd foo/bar/dstuff.d cstuff.o
steves homebuild:~/importcbug$ ./dstuff
```

--
Sep 01 2023