digitalmars.D - Linking to C
- scrappylildude (17/17) Nov 02 2010 Hello,
- Mike Chaten (4/26) Nov 02 2010 How are you compiling & linking the files? I've gotten this error before
- Andrei Alexandrescu (16/33) Nov 02 2010 Say you used htod obtaining libraw_c_headers.d and then used import in
- scrappylildude (5/5) Nov 02 2010 Thank you Andrei!
- Nick Sabalausky (5/10) Nov 02 2010 If you use something like rdmd or xfbuild then you can just specify the
- Andrei Alexandrescu (10/15) Nov 02 2010 rdmd takes care of figuring out dependencies:
- scrappylildude (26/26) Nov 02 2010 That's great--thanks Nick, Andrei.
- Nick Sabalausky (16/49) Nov 02 2010 Oh that's right, I forgot you said you were linking against a static C l...
- Mike Chaten (2/34) Nov 02 2010
- Nick Sabalausky (4/5) Nov 02 2010 Yes, although they have to come before the main D file, so it has to be ...
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
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.
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
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?
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