Linking to C
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Nov 2 18:55:58 PDT 2010
On 11/2/10 7:47 PM, scrappylildude wrote:
> Hello,
>
> New to D, but I am loving it so far.
>
> I am having some trouble linking to a C library static library (LibRaw 0.10.0). I ran htod on the LibRaw
> header files, and fixed up the resulting file by hand.
>
> Now when I compile and attempt to link, I get one error:
>
> Undefined symbols:
> "_D16libraw_c_headers12__ModuleInfoZ", referenced from:
> _D10helloworld12__ModuleInfoZ in helloworld.o
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
> --- errorlevel 1
>
> Obviously I don't have any identifiers by these names. I wrote a simple library which printf's "Hello
> World" and linked to it without problems. So I thought the problem might be due to name mangling
> incompatibilities, so I recompiled libraw under gcc4.2 and llvm-gcc and got the same issue both times.
>
> Can anyone provide a clue? I know the linker can't resolve the above, but I have no idea how to go
> about fixing it.
>
> Environment: Mac OS X 10.6.4, DMD v2.049.
Say you used htod obtaining libraw_c_headers.d and then used import in
some D program like this:
// File myfile.d
import libraw_c_headers;
... more D code ...
In that case, the module libraw_c_headers.d needs to be actually
included in the build. For example, I assume you now do:
$ dmd myfile.d
Hi, this is your linker and I'll output an incomprehensible message.
&^%$%$#%&^$*&^(*&^*&$&^#%$^#$%^#@$@#^%$#&^%$*%^&
$ _
You need to do:
$ dmd myfile.d libraw_c_headers.d
$ _
Andrei
More information about the Digitalmars-d
mailing list