April 07, 2013
On 04/07/2013 07:38 PM, Johannes Pfau wrote:
> In theory: Add the .so directory to /etc/ld.so.conf, run ldconfig http://linux.die.net/man/8/ldconfig

Oh, of course.  I did once know this years ago, but I'd forgotten as it's so long since I last installed a shared library into anything other than /usr/local/lib.

> But: This usually requires proper version information in the .so library and a properly set soname. I doubt anyone has looked into that yet.

Well, I have had no problems with dmd, but when I tried also adding /opt/gdc/lib I got the following error message upon running ldconfig:

    /sbin/ldconfig.real: /opt/gdc/lib/libstdc++.so.6.0.18-gdb.py is not an ELF
file - it has the wrong magic bytes at the start.
April 08, 2013
On Sunday, 7 April 2013 at 06:03:38 UTC, Walter Bright wrote:
> On 4/6/2013 7:15 PM, Ellery Newcomer wrote:
>> dmd  -unittest -fPIC -defaultlib=phobos2so -shared test1.d -oflibtest1.so
>> gcc  test1.c `pwd`/libtest1.so -L/usr/lib64/dmd/ -L/usr/lib/dmd/ -o test1.x
>> /lib64/libphobos2so.so: undefined reference to `_Dmain'
>> collect2: error: ld returned 1 exit status
>>
>>
>> _Dmain? wat?
>
> _Dmain is the mangled name for main() in your program.

Yes, I know, but does it make sense to provide it when I call my shared lib from C?
April 08, 2013
On 4/7/2013 6:14 PM, Ellery Newcomer wrote:
> On Sunday, 7 April 2013 at 06:03:38 UTC, Walter Bright wrote:
>> On 4/6/2013 7:15 PM, Ellery Newcomer wrote:
>>> dmd  -unittest -fPIC -defaultlib=phobos2so -shared test1.d -oflibtest1.so
>>> gcc  test1.c `pwd`/libtest1.so -L/usr/lib64/dmd/ -L/usr/lib/dmd/ -o test1.x
>>> /lib64/libphobos2so.so: undefined reference to `_Dmain'
>>> collect2: error: ld returned 1 exit status
>>>
>>>
>>> _Dmain? wat?
>>
>> _Dmain is the mangled name for main() in your program.
>
> Yes, I know, but does it make sense to provide it when I call my shared lib from C?

Currently, I think you'll need a D main().
April 08, 2013
On Monday, 8 April 2013 at 01:14:19 UTC, Ellery Newcomer wrote:
> On Sunday, 7 April 2013 at 06:03:38 UTC, Walter Bright wrote:
>> On 4/6/2013 7:15 PM, Ellery Newcomer wrote:
>>> dmd  -unittest -fPIC -defaultlib=phobos2so -shared test1.d -oflibtest1.so
>>> gcc  test1.c `pwd`/libtest1.so -L/usr/lib64/dmd/ -L/usr/lib/dmd/ -o test1.x
>>> /lib64/libphobos2so.so: undefined reference to `_Dmain'
>>> collect2: error: ld returned 1 exit status
>>>
>>>
>>> _Dmain? wat?
>>
>> _Dmain is the mangled name for main() in your program.
>
> Yes, I know, but does it make sense to provide it when I call my shared lib from C?

DMD inserts some additional info in object file if main() is present and sometimes it is required. One of the solutions is to use dummy D module (with main function defined) which forwards startup arguments to C main function.
April 08, 2013
On 2013-04-08 06:35, Maxim Fomin wrote:

> DMD inserts some additional info in object file if main() is present and
> sometimes it is required. One of the solutions is to use dummy D module
> (with main function defined) which forwards startup arguments to C main
> function.

druntime already defines a C main function as well, which forwards to the D main function.

-- 
/Jacob Carlborg
April 08, 2013
On 2013-04-08 06:16, Walter Bright wrote:

> Currently, I think you'll need a D main().

I don't think that's a good solution. Currently a quick workaround is to declare D main as a weak symbol.

What I think could be a better choice, in the long run, is to put the C and D main functions in a separate file, compiled as its own object file. This object file will only be linked when DMD is linking an executable.

The "rt_info" and D "main" functions should also be refactored so D main calls "rt_info" to avoid duplicating code.

-- 
/Jacob Carlborg
April 08, 2013
Am Sun, 07 Apr 2013 19:56:15 +0200
schrieb Joseph Rushton Wakeling <joseph.wakeling@webdrake.net>:

> On 04/07/2013 07:38 PM, Johannes Pfau wrote:
> > In theory: Add the .so directory to /etc/ld.so.conf, run ldconfig http://linux.die.net/man/8/ldconfig
> 
> Oh, of course.  I did once know this years ago, but I'd forgotten as it's so long since I last installed a shared library into anything other than /usr/local/lib.
> 
> > But: This usually requires proper version information in the .so library and a properly set soname. I doubt anyone has looked into that yet.
> 
> Well, I have had no problems with dmd, but when I tried also adding /opt/gdc/lib I got the following error message upon running ldconfig:
> 
>     /sbin/ldconfig.real: /opt/gdc/lib/libstdc++.so.6.0.18-gdb.py is
> not an ELF file - it has the wrong magic bytes at the start.

Then ldconfig is less picky than I thought ;-) The other problem is actually a problem in gcc, not gdc specific: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41816

Most linux distributions move that file manually to a different location when creating the gcc package.
April 08, 2013
On Monday, 8 April 2013 at 06:29:33 UTC, Jacob Carlborg wrote:
> On 2013-04-08 06:35, Maxim Fomin wrote:
>
>> DMD inserts some additional info in object file if main() is present and
>> sometimes it is required. One of the solutions is to use dummy D module
>> (with main function defined) which forwards startup arguments to C main
>> function.
>
> druntime already defines a C main function as well, which forwards to the D main function.

C main function need to be renamed or D main function should be supplied (then a program would start from C code, not D, but this is not a problem)

By the way, druntime links to _Dmain, but does not necessarily forwards to it.
April 08, 2013
On 2013-04-08 11:51, Maxim Fomin wrote:

> C main function need to be renamed or D main function should be supplied
> (then a program would start from C code, not D, but this is not a problem)
>
> By the way, druntime links to _Dmain, but does not necessarily forwards
> to it.

The C main function defined in druntime forward to the D main function. The C main function calls "_d_run_main" and passes in a pointer to the D main function. "_d_run_main" then calls the d main function. Indirectly the C main forwards to D main.

-- 
/Jacob Carlborg
April 08, 2013
On 2013-04-08 13:21, Jacob Carlborg wrote:

> The C main function defined in druntime forward to the D main function.
> The C main function calls "_d_run_main" and passes in a pointer to the D
> main function. "_d_run_main" then calls the d main function. Indirectly
> the C main forwards to D main.

Forgot the link:

https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L348

-- 
/Jacob Carlborg