Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 04:25:42 UTC, Mike Parker wrote: extern(C), not simply extern. It turns off the name mangling. But really, the proper thing to do is to drop the prototype and import the module with the implementation. It's tge way modules are intended to be used. Unless you're doing something specidic like writing a library that calls an arbitrary user function. Alright, so I misunderstood what ketmar was saying. His solution did work. I'm just not sure I understand what you are trying to say here: I've started using dub for things, and I've learned a lot since this thread. Anyway, thanks for the support with this everybody.
Re: DMD Refuses to Compile Multiple Source Files
Thanks loads. I got it working using those modules. ~Sam
Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 23:12:15 UTC, Mike Parker wrote: (source files), then use the import statement to make the declarations in other modules. Sorry, this should read "make the implementations available to other modules".
Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 19:28:20 UTC, Samwise wrote: On Wednesday, 18 January 2017 at 04:25:42 UTC, Mike Parker wrote: extern(C), not simply extern. It turns off the name mangling. But really, the proper thing to do is to drop the prototype and import the module with the implementation. It's tge way modules are intended to be used. Unless you're doing something specidic like writing a library that calls an arbitrary user function. Alright, so I misunderstood what ketmar was saying. His solution did work. I'm just not sure I understand what you are trying to say here: But really, the proper thing to do is to drop the prototype and import the module with the implementation. This will still preserve my multiple source files, without worrying about the headers, right? Thanks, ~Sam Yes. Take a look at some random projects from code.dlang.org and look at the way they have laid out their modules and what they import and from where.
Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 04:25:42 UTC, Mike Parker wrote: extern(C), not simply extern. It turns off the name mangling. But really, the proper thing to do is to drop the prototype and import the module with the implementation. It's tge way modules are intended to be used. Unless you're doing something specidic like writing a library that calls an arbitrary user function. Alright, so I misunderstood what ketmar was saying. His solution did work. I'm just not sure I understand what you are trying to say here: But really, the proper thing to do is to drop the prototype and import the module with the implementation. This will still preserve my multiple source files, without worrying about the headers, right? Thanks, ~Sam
Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 04:06:23 UTC, Samwise wrote: On Wednesday, 18 January 2017 at 03:51:50 UTC, ketmar wrote: On Wednesday, 18 January 2017 at 03:37:46 UTC, Samwise wrote: extern int getReturnCode() { return 4; } still does not compile using the command from above. I may very well be misunderstanding you though. yep. *both* prototype and real declaration should b `extern(C)`. `(C)` part is important too! I have both the header in hello.d and the actual function in getReturnCode.d as extern, and it still fails with the same error. extern(C), not simply extern. It turns off the name mangling. But really, the proper thing to do is to drop the prototype and import the module with the implementation. It's tge way modules are intended to be used. Unless you're doing something specidic like writing a library that calls an arbitrary user function.
Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 04:06:23 UTC, Samwise wrote: I have both the header in hello.d and the actual function in getReturnCode.d as extern, and it still fails with the same error. nope. it works.
Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 03:51:50 UTC, ketmar wrote: On Wednesday, 18 January 2017 at 03:37:46 UTC, Samwise wrote: extern int getReturnCode() { return 4; } still does not compile using the command from above. I may very well be misunderstanding you though. yep. *both* prototype and real declaration should be `extern(C)`. `(C)` part is important too! I have both the header in hello.d and the actual function in getReturnCode.d as extern, and it still fails with the same error.
Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 03:37:46 UTC, Samwise wrote: extern int getReturnCode() { return 4; } still does not compile using the command from above. I may very well be misunderstanding you though. yep. *both* prototype and real declaration should be `extern(C)`. `(C)` part is important too!
Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 03:25:47 UTC, Stefan Koch wrote: On Wednesday, 18 January 2017 at 03:11:08 UTC, Samwise wrote: On Wednesday, 18 January 2017 at 02:48:45 UTC, James Buren wrote: Import the source file containing the external function instead of writing that prototype. It should compile then. This seems like a workaround more than a permanent solution. It would work, but still. I'm also not sure about the syntax for that (Given that getReturnCode.d is in the same directory as hello.d). ~Sam In extern (D) functions (which is the default) The module name is part of the mangled name. What you are trying to do would work , if the getReturnType would be extern(C). Without changing anything about the hello.d file from above, and the only change being adding the extern keyword to the getReturnValue.d like this: extern int getReturnCode() { return 4; } still does not compile using the command from above. I may very well be misunderstanding you though. I've not been doing this particularly long... ~Sam
Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 03:11:08 UTC, Samwise wrote: On Wednesday, 18 January 2017 at 02:48:45 UTC, James Buren wrote: Import the source file containing the external function instead of writing that prototype. It should compile then. This seems like a workaround more than a permanent solution. It would work, but still. I'm also not sure about the syntax for that (Given that getReturnCode.d is in the same directory as hello.d). ~Sam In extern (D) functions (which is the default) The module name is part of the mangled name. What you are trying to do would work , if the getReturnType would be extern(C).
Re: DMD Refuses to Compile Multiple Source Files
On Wednesday, 18 January 2017 at 02:48:45 UTC, James Buren wrote: Import the source file containing the external function instead of writing that prototype. It should compile then. This seems like a workaround more than a permanent solution. It would work, but still. I'm also not sure about the syntax for that (Given that getReturnCode.d is in the same directory as hello.d). ~Sam
Re: DMD Refuses to Compile Multiple Source Files
Import the source file containing the external function instead of writing that prototype. It should compile then.
DMD Refuses to Compile Multiple Source Files
Alright. For the sake of this argument, I'm going to post all the stuff about a really tiny boring program that quite literally does nothing, even though I found this issue when I was working with a much larger project with more functions. Basically I'm getting errors when I attempt to compile multiple source files using the DMD. It does not matter whether it's through dub or just straight DMD. A few little code snippets and DMD output (The dub output is basically the same as the DMD, just with a few more lines): hello.d (This file contains the main function, as you can see. I put the headers in here to simplify things.): import std.stdio; int getReturnCode(); int main() { writeln("Hello World!"); return getReturnCode(); } getReturnCode.d (This file is the home of my cute function, which does nothing...): int getReturnCode() { return 4; } Those were the complete contents of my two basic program files. The Compilation works fine (Can generate both object files using the -c switch with the DMD). However, it just stops when linking... $ dmd getReturnCode.d hello.d getReturnCode.o: In function `_Dmain': hello.d:(.text._Dmain+0x17): undefined reference to `_D5hello13getReturnCodeFZi' collect2: error: ld returned 1 exit status --- errorlevel 1 This basic output is what I'm getting whenever I try to compile a main function using a function call that is for a function not included in the main.d, regardless of pretty much any other thing. Thank you for reading and at least attempting to help me solve this issue... ~Sam