Re: Compilation problems with GDC/GCC

2017-04-15 Thread DRex via Digitalmars-d-learn

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?





Re: Compilation problems with GDC/GCC

2017-04-15 Thread DRex via Digitalmars-d-learn

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 :/ ..


Re: Compilation problems with GDC/GCC

2017-04-15 Thread DRex via Digitalmars-d-learn

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 +
schrieb DRex :


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.


Re: Compilation problems with GDC/GCC

2017-04-15 Thread DRex via Digitalmars-d-learn

On Friday, 14 April 2017 at 18:00:22 UTC, Johannes Pfau wrote:

Am Fri, 14 Apr 2017 13:03:22 +
schrieb DRex :


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'`






Re: Compilation problems with GDC/GCC

2017-04-14 Thread DRex via Digitalmars-d-learn

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


Re: Compilation problems with GDC/GCC

2017-04-14 Thread DRex via Digitalmars-d-learn

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?




Compilation problems with GDC/GCC

2017-04-14 Thread DRex via Digitalmars-d-learn
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.




Re: Comparing Instances of Classes

2017-03-10 Thread DRex via Digitalmars-d-learn

On Friday, 10 March 2017 at 20:27:09 UTC, Meta wrote:

On Friday, 10 March 2017 at 17:08:42 UTC, Whatsthisnow wrote:
I guess i am just too used to the java way of x.equals(object) 
which at the source  is exactly 'return this == object'


Java would return false here too, though, if it actually did 
`this == object` in its default compare method. If I remember 
correctly, comparing two objects with == in Java compares their 
addresses, not their contents.


I must be losing my mind then


Re: Comparing Instances of Classes

2017-03-10 Thread DRex via Digitalmars-d-learn

On Friday, 10 March 2017 at 16:30:00 UTC, Adam D. Ruppe wrote:

On Friday, 10 March 2017 at 16:22:18 UTC, DRex wrote:
Error: function app.A.opEquals does not override any function, 
did you mean to override 'object.Object.opEquals'?


Oh sorry, maybe I messed up the const. Try:

override bool opEquals(A rhs) { ... }


and if the compiler still complains change the A to Object and 
cast it inside (but I'm pretty sure that will work, I think it 
is just const it is picky about)


Thanks.

I'm fairly new to D, but this seems to be quite a pain in the 
rear for a simple comparison of instances of classes...really odd 
that comparing instances of classes in D requires that messing 
around when D seems all about simplifying things...


Re: Comparing Instances of Classes

2017-03-10 Thread DRex via Digitalmars-d-learn

On Friday, 10 March 2017 at 16:13:21 UTC, Adam D. Ruppe wrote:

On Friday, 10 March 2017 at 16:08:05 UTC, DRex wrote:

Am I missing something here?


Yeah, you need to implement a custom equality operator.

class A {
   int member;
   override bool opEquals(const A rhs) {
return this.member == rhs.member; // and other members 
that need to be equal

   }
}


The default opEquals sees if they are the same *instance* (same 
as `a is b`), and does not look at contents. You need to define 
that yourself.


I tried the above class A, and now the compiler fails with the 
following error:


Error: function app.A.opEquals does not override any function, 
did you mean to override 'object.Object.opEquals'?


My A class appears exactly as mentioned in your comment...


Comparing Instances of Classes

2017-03-10 Thread DRex via Digitalmars-d-learn

Hi,

I am trying to compare two instances of a class.  I created a 
test program to try this, but every method I use to compare the 
instances always returns false.


this is my code to test comparison

class A
{
this()
{

}
}

void main()
{
A a = new A();
A a2 = new A();

writeln(equals(a, a2));
}

bool equals(Object obj1, Object obj2)
{
return (obj1 is obj2);
}

I have tried 'a is a2', I have tried 'a1 == a2' and many other 
ways (including opEquals from object.d) among other things and 
every single time the comparison returns false.  The comparison 
always fails and never returns true.


I am trying to do something like Object.equals(Object o) in java, 
but so far, no success.


Am I missing something here?


Linking C Headers to D

2017-01-11 Thread DRex via Digitalmars-d-learn

Hi,

I am trying to link C and D (using GCC and GDC) and I am 
wondering (I could find no answers on google) if it is possible 
to compile C headers into object files and link them to D?  I 
have a large code base of C headers and am not at a point where I 
can translate them all to D in one go, so I need to be able to 
link to the headers.


Thanks.