digitalmars.D - Linking to C
- scrappylildude <sdl yahoo.com> Nov 02 2010
- Mike Chaten <mchaten gmail.com> Nov 02 2010
- Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> Nov 02 2010
- scrappylildude <sdl yahoo.com> Nov 02 2010
- "Nick Sabalausky" <a a.a> Nov 02 2010
- Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> Nov 02 2010
- scrappylildude <sdl yahoo.com> Nov 02 2010
- "Nick Sabalausky" <a a.a> Nov 02 2010
- Mike Chaten <mchaten gmail.com> Nov 02 2010
- "Nick Sabalausky" <a a.a> Nov 02 2010
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.
Nov 02 2010
--0016e6dd95a9d7c19104941bc119 Content-Type: text/plain; charset=ISO-8859-1 How are you compiling & linking the files? I've gotten this error before when I forgot to include a file in my compilation (in your case libraw_c_headers) On Tue, Nov 2, 2010 at 8:47 PM, scrappylildude <sdl yahoo.com> 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.
--0016e6dd95a9d7c19104941bc119 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable How are you compiling & linking the files? I've gotten this error b= efore when I forgot to include a file in my compilation (in your case libra= w_c_headers)<br><br><div class=3D"gmail_quote">On Tue, Nov 2, 2010 at 8:47 = PM, scrappylildude <span dir=3D"ltr"><<a href=3D"mailto:sdl yahoo.com">s= dl yahoo.com</a>></span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex;">Hello,<br> <br> New to D, but I am loving it so far.<br> <br> I am having some trouble linking to a C library static library (LibRaw 0.10= .0). =A0I ran htod on the LibRaw<br> header files, and fixed up the resulting file by hand.<br> <br> Now when I compile and attempt to link, I get one error:<br> <br> Undefined symbols:<br> =A0"_D16libraw_c_headers12__ModuleInfoZ", referenced from:<br> =A0 =A0 =A0_D10helloworld12__ModuleInfoZ in helloworld.o<br> ld: symbol(s) not found<br> collect2: ld returned 1 exit status<br> --- errorlevel 1<br> <br> Obviously I don't have any identifiers by these names. =A0I wrote a sim= ple library which printf's "Hello<br> World" and linked to it without problems. =A0So I thought the problem = might be due to name mangling<br> incompatibilities, so I recompiled libraw under gcc4.2 and llvm-gcc and got= the same issue both times.<br> <br> Can anyone provide a clue? =A0I know the linker can't resolve the above= , but I have no idea how to go<br> about fixing it.<br> <br> Environment: Mac OS X 10.6.4, DMD v2.049.<br> </blockquote></div><br> --0016e6dd95a9d7c19104941bc119--
Nov 02 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
Nov 02 2010
Thank you Andrei! I thought because I had imported libraw_c_headers.d in myfile.d that I didn't need to do that. Thank you, it works perfectly. P.S. Sorry, perhaps this question should have been posted in D.Learn?
Nov 02 2010
"scrappylildude" <sdl yahoo.com> wrote in message news:iaqgha$1p6k$1 digitalmars.com...Thank you Andrei! I thought because I had imported libraw_c_headers.d in myfile.d that I didn't need to do that.
If you use something like rdmd or xfbuild then you can just specify the "main" D file, and it'll automatically find all dependencies like that.P.S. Sorry, perhaps this question should have been posted in D.Learn?
Probably, but we're not too strict :)
Nov 02 2010
On 11/2/10 9:14 PM, scrappylildude wrote:Thank you Andrei! I thought because I had imported libraw_c_headers.d in myfile.d that I didn't need to do that. Thank you, it works perfectly. P.S. Sorry, perhaps this question should have been posted in D.Learn?
rdmd takes care of figuring out dependencies: http://www.digitalmars.com/d/2.0/rdmd.html If you just say $ rdmd --build-only myfile.d $ _ then rdmd will figure out that myfile.d depends on libraw_c_headers.d and link it in automatically. See http://www.digitalmars.com/d/2.0/rdmd.html. Andrei
Nov 02 2010
That's great--thanks Nick, Andrei.
I tried it and it looks like I haven't configured something right. I'm
building a sample
project with my program, my utility class library and libraw. I've added the
path to
libraw_c_headers.d to dmd.conf, now that I don't have a -I switch any more
(using
rdmd).
When I use rdmd, something like my original error seems to have returned: :(
rdmd --build-only helloworld.d
Undefined symbols: "_D4hecl4base8HECLBase11__InterfaceZ", referenced from:
_D4hecl4base12__ModuleInfoZ in helloworld.d.old: symbol(s) not foundcollect2: ld
returned 1 exit status
--- errorlevel 1
My project is organized as follows:
root/
stuff_i_made/
my project/
helloworld.d
my class library/
hecl*.d
stuff_I_didnt_make/
libraw/
lib/
libraw_r.a
src/
libraw_c_headers.d
Using --dry-run seems to show everything except the libraw_r.a. Since I don't
have a
-L switch with rdmd, I assume this is the problem?
Nov 02 2010
"scrappylildude" <sdl yahoo.com> wrote in message news:iaqu6l$2sq5$1 digitalmars.com...That's great--thanks Nick, Andrei. I tried it and it looks like I haven't configured something right. I'm building a sample project with my program, my utility class library and libraw. I've added the path to libraw_c_headers.d to dmd.conf, now that I don't have a -I switch any more (using rdmd). When I use rdmd, something like my original error seems to have returned: :( rdmd --build-only helloworld.d Undefined symbols: "_D4hecl4base8HECLBase11__InterfaceZ", referenced from: _D4hecl4base12__ModuleInfoZ in helloworld.d.old: symbol(s) not foundcollect2: ld returned 1 exit status --- errorlevel 1 My project is organized as follows: root/ stuff_i_made/ my project/ helloworld.d my class library/ hecl*.d stuff_I_didnt_make/ libraw/ lib/ libraw_r.a src/ libraw_c_headers.d Using --dry-run seems to show everything except the libraw_r.a. Since I don't have a -L switch with rdmd, I assume this is the problem?
Oh that's right, I forgot you said you were linking against a static C lib. There's currently three bugs in RDMD relating to what you're doing here, two of them have patches though: http://d.puremagic.com/issues/show_bug.cgi?id=3564 http://d.puremagic.com/issues/show_bug.cgi?id=4672 http://d.puremagic.com/issues/show_bug.cgi?id=4928 Until those get sorted out (or at least the first one, and then apply the patches from the other two), then yea, you'll probably have to work around it by just passing everything to dmd directly: dmd "stuff_i_made/my project/helloworld.d" "stuff_i_made/my class library/hecl*.d" stuff_I_didnt_make/libraw/lib/libraw_r.a stuff_I_didnt_make/libraw/src/libraw_c_headers.d If you're using D1, you could probably use xfbuild (don't have link offhand, but should be easy to google).
Nov 02 2010
--001485f89468ea5e27049420067b Content-Type: text/plain; charset=ISO-8859-1 Any options with just one dash afaik (ala -L) will pass through to dmd. On Wed, Nov 3, 2010 at 2:07 AM, scrappylildude <sdl yahoo.com> wrote:That's great--thanks Nick, Andrei. I tried it and it looks like I haven't configured something right. I'm building a sample project with my program, my utility class library and libraw. I've added the path to libraw_c_headers.d to dmd.conf, now that I don't have a -I switch any more (using rdmd). When I use rdmd, something like my original error seems to have returned: :( rdmd --build-only helloworld.d Undefined symbols: "_D4hecl4base8HECLBase11__InterfaceZ", referenced from: _D4hecl4base12__ModuleInfoZ in helloworld.d.old: symbol(s) not foundcollect2: ld returned 1 exit status --- errorlevel 1 My project is organized as follows: root/ stuff_i_made/ my project/ helloworld.d my class library/ hecl*.d stuff_I_didnt_make/ libraw/ lib/ libraw_r.a src/ libraw_c_headers.d Using --dry-run seems to show everything except the libraw_r.a. Since I don't have a -L switch with rdmd, I assume this is the problem?
--001485f89468ea5e27049420067b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Any options with just one dash afaik (ala -L) will pass through to dmd.<br>= <br><div class=3D"gmail_quote">On Wed, Nov 3, 2010 at 2:07 AM, scrappylildu= de <span dir=3D"ltr"><<a href=3D"mailto:sdl yahoo.com">sdl yahoo.com</a>= ></span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex;">That's great--thanks Nick, Andrei.<br> <br> I tried it and it looks like I haven't configured something right. =A0 = I'm building a sample<br> project with my program, my utility class library and libraw. =A0I've a= dded the path to<br> libraw_c_headers.d to dmd.conf, now that I don't have a -I switch any m= ore (using<br> rdmd).<br> <br> When I use rdmd, something like my original error seems to have returned: = =A0:(<br> <br> rdmd --build-only helloworld.d<br> <br> Undefined symbols: =A0"_D4hecl4base8HECLBase11__InterfaceZ", refe= renced from:<br> _D4hecl4base12__ModuleInfoZ in helloworld.d.old: symbol(s) not foundcollect= 2: ld<br> <div class=3D"im">returned 1 exit status<br> --- errorlevel 1<br> <br> </div>My project is organized as follows:<br> root/<br> =A0 =A0stuff_i_made/<br> =A0 =A0 =A0 =A0my project/<br> =A0 =A0 =A0 =A0 =A0 =A0helloworld.d<br> =A0 =A0 =A0 =A0my class library/<br> =A0 =A0 =A0 =A0 =A0 =A0hecl*.d<br> =A0 =A0stuff_I_didnt_make/<br> =A0 =A0 =A0 =A0libraw/<br> =A0 =A0 =A0 =A0 =A0 =A0lib/<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0libraw_r.a<br> =A0 =A0 =A0 =A0 =A0 =A0src/<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0libraw_c_headers.d<br> <br> Using --dry-run seems to show everything except the libraw_r.a. =A0Since I = don't have a<br> -L switch with rdmd, I assume this is the problem?<br> <br> <br> <br> <br> <br> </blockquote></div><br> --001485f89468ea5e27049420067b--
Nov 02 2010
Any options with just one dash afaik (ala -L) will pass through to dmd.
Yes, although they have to come before the main D file, so it has to be like this: rdmd -Lwhatever main.d NOT: rdmd main.d -Lwhatever
Nov 02 2010









Mike Chaten <mchaten gmail.com> 