digitalmars.D - Linking doubts
- Carotinho (11/11) Nov 29 2004 Hi!
- Russ Lewis (12/22) Nov 29 2004 Importing a module gives you the ability to call functions in that
- Sebastian Beschke (3/7) Nov 30 2004 And, just for clarifying, you need to link the appropriate object file i...
- Carotinho (5/14) Nov 30 2004 Thanks!
Hi! I have two linking questions 1) If I create a module, and then import it in another source file, how come that a function defined in the module is "undefined", if I try to dmd only the source file? I have to compile the module, and then link the source file against the module. Is it right or I'm missing something? 2) Is it possible to make D functions available to a C program? I tried linking the C source code and the D object altogether with phobos, but with errors... what I'm supposed to do? I thank you in advance:) Carotinho
Nov 29 2004
Carotinho wrote:Hi! I have two linking questions 1) If I create a module, and then import it in another source file, how come that a function defined in the module is "undefined", if I try to dmd only the source file? I have to compile the module, and then link the source file against the module. Is it right or I'm missing something?Importing a module gives you the ability to call functions in that module. However, the function code is only compiled in the *other* module. The C analogy would be that when you import a module, it's like #include-ing a header, while compiling a module is is like compiling a C file. So yes, you have to compile and link together all modules which include functions that you need.2) Is it possible to make D functions available to a C program? I tried linking the C source code and the D object altogether with phobos, but with errors... what I'm supposed to do?You can make a D function callable from C like this: extern(C) int myFunction(<args>) { <code> } You can make a C function callable from D like this: extern(C) int myOtherFunction(<args>);
Nov 29 2004
Russ Lewis wrote:You can make a C function callable from D like this: extern(C) int myOtherFunction(<args>);And, just for clarifying, you need to link the appropriate object file in. -Sebastian
Nov 30 2004
Sebastian Beschke wrote:Russ Lewis wrote:Thanks! I -ahem- misread the docs and thought that extern (C) was here just to link TO C :) Byez!You can make a C function callable from D like this: extern(C) int myOtherFunction(<args>);And, just for clarifying, you need to link the appropriate object file in. -Sebastian
Nov 30 2004