Thread overview
Compilation problems with GDC/GCC
Apr 14, 2017
DRex
Apr 14, 2017
Nicholas Wilson
Apr 14, 2017
DRex
Apr 14, 2017
DRex
Apr 14, 2017
Johannes Pfau
Apr 15, 2017
DRex
Apr 15, 2017
DRex
Apr 15, 2017
DRex
Apr 15, 2017
DRex
Apr 16, 2017
Johannes Pfau
April 14, 2017
I have project which involves both C and D code.  For reasons that are much too long to explain, I have to use GCC to compile the C code into object files (GDC to compile the D code into object files) and then ld to link all the object files together.  Now (unless I am missing something) ld cant link D object files (a whole bunch of errors about undefined references to a million different things) which I can only assume is attributed to ld not knowing about the D libraries and runtime.  GDC can link D object files just fine, but again for reasons too long to explain, I cannot use GDC to link the object files together.

I need to take a handful of specific C files and a handful of Specific D files and link them together (and redirect it into another .o object file using the -r switch of ld) but again, ld can't deal with D object files.  I have tried using the -Xlinker as well as -Wl switches from GDC to pass the -r switch to the linker, but GDC just spews out "/usr/bin/ld: cannot find -lgcc_s" and fails.

Sorry if I am making no sense, if I am not being clear, let me know and I will try to re-explain, hoping someone can help me.

Cheers.


April 14, 2017
On Friday, 14 April 2017 at 11:32:57 UTC, DRex wrote:
> I have project which involves both C and D code.  For reasons that are much too long to explain, I have to use GCC to compile the C code into object files (GDC to compile the D code into object files) and then ld to link all the object files together.  Now (unless I am missing something) ld cant link D object files (a whole bunch of errors about undefined references to a million different things) which I can only assume is attributed to ld not knowing about the D libraries and runtime.  GDC can link D object files just fine, but again for reasons too long to explain, I cannot use GDC to link the object files together.
>
> I need to take a handful of specific C files and a handful of Specific D files and link them together (and redirect it into another .o object file using the -r switch of ld) but again, ld can't deal with D object files.  I have tried using the -Xlinker as well as -Wl switches from GDC to pass the -r switch to the linker, but GDC just spews out "/usr/bin/ld: cannot find -lgcc_s" and fails.
>
> Sorry if I am making no sense, if I am not being clear, let me know and I will try to re-explain, hoping someone can help me.
>
> Cheers.

It is most likely the druntime libraries the linker is complaining about, ld most certainly can deal with D object files. You could try passing them to the linker, but I'm not familiar with the -r option and how that would interact.

One of the verbose flags of gdc will probably allow you to see the linker invocation (or strace or the like) and you could replicate that.
April 14, 2017
On Friday, 14 April 2017 at 11:51:54 UTC, Nicholas Wilson wrote:
> On Friday, 14 April 2017 at 11:32:57 UTC, DRex wrote:
>> I have project which involves both C and D code.  For reasons that are much too long to explain, I have to use GCC to compile the C code into object files (GDC to compile the D code into object files) and then ld to link all the object files together.  Now (unless I am missing something) ld cant link D object files (a whole bunch of errors about undefined references to a million different things) which I can only assume is attributed to ld not knowing about the D libraries and runtime.  GDC can link D object files just fine, but again for reasons too long to explain, I cannot use GDC to link the object files together.
>>
>> I need to take a handful of specific C files and a handful of Specific D files and link them together (and redirect it into another .o object file using the -r switch of ld) but again, ld can't deal with D object files.  I have tried using the -Xlinker as well as -Wl switches from GDC to pass the -r switch to the linker, but GDC just spews out "/usr/bin/ld: cannot find -lgcc_s" and fails.
>>
>> Sorry if I am making no sense, if I am not being clear, let me know and I will try to re-explain, hoping someone can help me.
>>
>> Cheers.
>
> It is most likely the druntime libraries the linker is complaining about, ld most certainly can deal with D object files. You could try passing them to the linker, but I'm not familiar with the -r option and how that would interact.
>
> One of the verbose flags of gdc will probably allow you to see the linker invocation (or strace or the like) and you could replicate that.

the -r option redirects the linked object files into another object file, so the point being I can pass a D object and a C object to the linker and produce another object file.

As for linking D files, do you mean passing the druntime libraries to ld?  I used gdc -v and it gave me a whole bunch of info, it showed the an entry 'LIBRARY_PATH' which contains the path to libgphobos and libgdruntime as well as a whole bunch of other libs, i'm assuming that is what you are telling me to pass to the linker?

April 14, 2017
On Friday, 14 April 2017 at 12:01:39 UTC, DRex wrote:
>
> the -r option redirects the linked object files into another object file, so the point being I can pass a D object and a C object to the linker and produce another object file.
>
> As for linking D files, do you mean passing the druntime libraries to ld?  I used gdc -v and it gave me a whole bunch of info, it showed the an entry 'LIBRARY_PATH' which contains the path to libgphobos and libgdruntime as well as a whole bunch of other libs, i'm assuming that is what you are telling me to pass to the linker?

I have tried passing libgphobos2.a and libgdruntime.a (and at one point every library in the folder I found those two libs in) to ld to link with my D source, but it still throws a billion 'undefined reference' errors.

I really need help here, I have tried so many different things and am losing my mind trying to get this to work.

the problem I have with passing the -r option to ld through gdc is that -Wl is looking for libgcc_s.a which doesnt even exist on the computer, which is annoying
April 14, 2017
Am Fri, 14 Apr 2017 13:03:22 +0000
schrieb DRex <armstronga94@hotmail.com>:

> On Friday, 14 April 2017 at 12:01:39 UTC, DRex wrote:
> >
> > the -r option redirects the linked object files into another object file, so the point being I can pass a D object and a C object to the linker and produce another object file.
> >
> > As for linking D files, do you mean passing the druntime libraries to ld?  I used gdc -v and it gave me a whole bunch of info, it showed the an entry 'LIBRARY_PATH' which contains the path to libgphobos and libgdruntime as well as a whole bunch of other libs, i'm assuming that is what you are telling me to pass to the linker?
> 
> I have tried passing libgphobos2.a and libgdruntime.a (and at one point every library in the folder I found those two libs in) to ld to link with my D source, but it still throws a billion 'undefined reference' errors.
> 
> I really need help here, I have tried so many different things and am losing my mind trying to get this to work.
> 
> the problem I have with passing the -r option to ld through gdc is that -Wl is looking for libgcc_s.a which doesnt even exist on the computer, which is annoying

GDC should generally only need to link to -lgdruntime (and -lgphobos if you need it). However, if you really link using ld you'll have to provide the C startup files, -lc and similar stuff for C as well, which gets quite complicated.

You'll have to post the exact commands you used and some
of the missing symbol names so we can give better answers.

-- Johannes

April 15, 2017
On Friday, 14 April 2017 at 18:00:22 UTC, Johannes Pfau wrote:
> Am Fri, 14 Apr 2017 13:03:22 +0000
> schrieb DRex <armstronga94@hotmail.com>:
>
>
> GDC should generally only need to link to -lgdruntime (and -lgphobos if you need it). However, if you really link using ld you'll have to provide the C startup files, -lc and similar stuff for C as well, which gets quite complicated.
>
> You'll have to post the exact commands you used and some
> of the missing symbol names so we can give better answers.
>
> -- Johannes

okay so here is an outline of the situation:

The project is a rather large C project that is being ported to D (small pieces at a time) and as I said before, it's make files are simply way too complicated t unravel and rewrite (the main make file has 5000 some lines of code).

I have re-written some small elements of C code so far in D.  I need to compile the D code into object (*.o) files, and simply including them as references in the make files doesn't work because ld on its own doesn't know how to link D files (as I assume it doesn't by default know to link the object files with the D runtime).

On small projects with C and D (test projects for including D with C) showed that I can simply replace ld with gdc when I go to link, i.e. instead of `ld cfile.o dfile.o -o foo` I can use `gdc cfile.o dfile.o -o foo` and it will link the objects together and make the program.  However this is not a viable solution to the project without navigating through the make files, as there are some options that are passed to the linker that GDC doesn't seem to recognize, and this build fails.

After reading the above comment, I have tried linking with `ld *options* -lgdruntime`, which failed, I also tried specifying the druntime lib with its full path '-l:/usr/gcc/x86_64-linux-gnu/5/libgdruntime.a' and derivatives thereof and ld says it cannot find it.  UPDATE: using -L instead of -l seems to have worked, but I am now recieveing a lot of 'undefined referece' errors, so many that I wont write them here, but some of them are:

`test.o: In function `main':
test.d:(.text+0x21): undefined reference to `_d_run_main'

`test.o: In function `_D4test9__modinitFZv':
test.d:(.text+0xaa): undefined reference to `_Dmodule_ref'`

`test.o:(.data+0x10): undefined reference to `_D3std5stdio12__ModuleInfoZ'`



April 15, 2017
On Saturday, 15 April 2017 at 12:45:47 UTC, DRex wrote:
> On Friday, 14 April 2017 at 18:00:22 UTC, Johannes Pfau wrote:
>> Am Fri, 14 Apr 2017 13:03:22 +0000
>> schrieb DRex <armstronga94@hotmail.com>:
>>
>>
>> GDC should generally only need to link to -lgdruntime (and -lgphobos if you need it). However, if you really link using ld you'll have to provide the C startup files, -lc and similar stuff for C as well, which gets quite complicated.
>>
>> You'll have to post the exact commands you used and some
>> of the missing symbol names so we can give better answers.
>>
>> -- Johannes
>
> okay so here is an outline of the situation:
>
> The project is a rather large C project that is being ported to D (small pieces at a time) and as I said before, it's make files are simply way too complicated t unravel and rewrite (the main make file has 5000 some lines of code).
>
> I have re-written some small elements of C code so far in D.  I need to compile the D code into object (*.o) files, and simply including them as references in the make files doesn't work because ld on its own doesn't know how to link D files (as I assume it doesn't by default know to link the object files with the D runtime).
>
> On small projects with C and D (test projects for including D with C) showed that I can simply replace ld with gdc when I go to link, i.e. instead of `ld cfile.o dfile.o -o foo` I can use `gdc cfile.o dfile.o -o foo` and it will link the objects together and make the program.  However this is not a viable solution to the project without navigating through the make files, as there are some options that are passed to the linker that GDC doesn't seem to recognize, and this build fails.
>
> After reading the above comment, I have tried linking with `ld *options* -lgdruntime`, which failed, I also tried specifying the druntime lib with its full path '-l:/usr/gcc/x86_64-linux-gnu/5/libgdruntime.a' and derivatives thereof and ld says it cannot find it.  UPDATE: using -L instead of -l seems to have worked, but I am now recieveing a lot of 'undefined referece' errors, so many that I wont write them here, but some of them are:
>
> `test.o: In function `main':
> test.d:(.text+0x21): undefined reference to `_d_run_main'
>
> `test.o: In function `_D4test9__modinitFZv':
> test.d:(.text+0xaa): undefined reference to `_Dmodule_ref'`
>
> `test.o:(.data+0x10): undefined reference to `_D3std5stdio12__ModuleInfoZ'`

Update: using the --verbose option of ld, it has printed out attempts to open the library (when using `-lgdruntime` the output is as follows:

attempt to open //usr/local/lib/x86_64-linux-gnu/libgdruntime.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libgdruntime.a failed
attempt to open //lib/x86_64-linux-gnu/libgdruntime.so failed
attempt to open //lib/x86_64-linux-gnu/libgdruntime.a failed
attempt to open //usr/lib/x86_64-linux-gnu/libgdruntime.so failed
attempt to open //usr/lib/x86_64-linux-gnu/libgdruntime.a failed
attempt to open //usr/local/lib64/libgdruntime.so failed
attempt to open //usr/local/lib64/libgdruntime.a failed
attempt to open //lib64/libgdruntime.so failed
attempt to open //lib64/libgdruntime.a failed
attempt to open //usr/lib64/libgdruntime.so failed
attempt to open //usr/lib64/libgdruntime.a failed
attempt to open //usr/local/lib/libgdruntime.so failed
attempt to open //usr/local/lib/libgdruntime.a failed
attempt to open //lib/libgdruntime.so failed
attempt to open //lib/libgdruntime.a failed
attempt to open //usr/lib/libgdruntime.so failed
attempt to open //usr/lib/libgdruntime.a failed
attempt to open //usr/x86_64-linux-gnu/lib64/libgdruntime.so failed
attempt to open //usr/x86_64-linux-gnu/lib64/libgdruntime.a failed
attempt to open //usr/x86_64-linux-gnu/lib/libgdruntime.so failed
attempt to open //usr/x86_64-linux-gnu/lib/libgdruntime.a failed

I don't see why it is failing, because the second attempt is the right path, the libgdruntime.a file is exactly at "/usr/local/lib/x86_64-linux-gnu/libgdruntime.a", although I do not know why it is using double forward slash as the root :s, which I cannot seem to stop it from doing.
April 15, 2017
On Saturday, 15 April 2017 at 13:02:43 UTC, DRex wrote:
> On Saturday, 15 April 2017 at 12:45:47 UTC, DRex wrote:

Update to the Update,

I fixed the lib failing to open by copying it to the location of my sources, and setting the ld to use libraries in that folder, however I am still getting the aforementioned undefined references :/ ..
April 15, 2017
On Saturday, 15 April 2017 at 13:08:29 UTC, DRex wrote:
> On Saturday, 15 April 2017 at 13:02:43 UTC, DRex wrote:
>> On Saturday, 15 April 2017 at 12:45:47 UTC, DRex wrote:
>
> Update to the Update,
>
> I fixed the lib failing to open by copying it to the location of my sources, and setting the ld to use libraries in that folder, however I am still getting the aforementioned undefined references :/ ..

Okay, so I decided to link using GDC in verbose mode to figure out what gdc is passing to gcc/the linker, and I copied the output and ld linked the files, but I still have a problem.  The program is linked and created but cant run, and ld produces the following error:

ld: error in /usr/lib/gcc/x86_64-linux-gnu/5/collect2(.eh_frame); no .eh_frame_hdr table will be created.

I haven't the foggiest what this means, and no Idea how to fix it.  Does anyone know how to fix this issue?


April 16, 2017
Am Sat, 15 Apr 2017 14:01:51 +0000
schrieb DRex <armstronga94@hotmail.com>:

> On Saturday, 15 April 2017 at 13:08:29 UTC, DRex wrote:
> > On Saturday, 15 April 2017 at 13:02:43 UTC, DRex wrote:
> >> On Saturday, 15 April 2017 at 12:45:47 UTC, DRex wrote:
> >
> > Update to the Update,
> >
> > I fixed the lib failing to open by copying it to the location of my sources, and setting the ld to use libraries in that folder, however I am still getting the aforementioned undefined references :/ ..
> 
> Okay, so I decided to link using GDC in verbose mode to figure out what gdc is passing to gcc/the linker, and I copied the output and ld linked the files, but I still have a problem.  The program is linked and created but cant run, and ld produces the following error:
> 
> ld: error in /usr/lib/gcc/x86_64-linux-gnu/5/collect2(.eh_frame); no .eh_frame_hdr table will be created.
> 
> I haven't the foggiest what this means, and no Idea how to fix it.  Does anyone know how to fix this issue?
> 
> 

Are there any additional warnings? Maybe try running in verbose mode to get some more information?

-- Johannes