Re: build 32-bit library on 64-bit OS

2019-03-20 Thread DFTW via Digitalmars-d-learn

On Tuesday, 19 March 2019 at 21:20:24 UTC, kinke wrote:

On Tuesday, 19 March 2019 at 20:56:47 UTC, DFTW wrote:
What package did you mean? that libphobos2 on the error 
messages from the ld?

I'm using dmd/dub on Ubuntu 18.


libphobos2-ldc-shared.so is definitely from LDC.


I hadn't noticied it was a ldc's library actually. I didn't set 
any compiler explicitly with dub so I assumed it was usind dmd 
and its libraries.


I'll give a try to ldc, does it still is binary compatible 
with C?


It's better suited for C(++) interop than DMD (ABI issues).


Only with ldc (downloaed from repo) I managed to build a 32-bit 
version successfully. Thanks!


Re: build 32-bit library on 64-bit OS

2019-03-19 Thread DFTW via Digitalmars-d-learn

On Tuesday, 19 March 2019 at 20:31:46 UTC, kinke wrote:

On Tuesday, 19 March 2019 at 17:23:21 UTC, DFTW wrote:
/usr/bin/ld: skiping 
//usr/lib/x86_64-linux-gnu/libphobos2-ldc-shared.so 
incompatible to -lphobos2-ldc-shared

/usr/bin/ld: couldn't find -lphobos2-ldc-shared


If possible, use an official package 
(https://github.com/ldc-developers/ldc/releases). What distro 
are you using? The packager apparently didn't create a multilib 
package.


What package did you mean? that libphobos2 on the error messages 
from the ld?

I'm using dmd/dub on Ubuntu 18.
I'll give a try to ldc, does it still is binary compatible with C?


build 32-bit library on 64-bit OS

2019-03-19 Thread DFTW via Digitalmars-d-learn
So I need to build a 32-bit version of a library on 64-bit 
system. I got some errors, which I get rid of after installing 
the gcc 32-bit tools (and gcc -m32 ran fine) but I still get 
errors about libraries not compatible.


the command:
dub --arch=x86

yield erros such:

/usr/bin/ld: skiping 
//usr/lib/x86_64-linux-gnu/libphobos2-ldc-shared.so incompatible 
to -lphobos2-ldc-shared

/usr/bin/ld: couldn't find -lphobos2-ldc-shared
//
collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1
/usr/bin/ldc2 failed with exit code 1.

How do I fix this?



Re: SEGFAULT when converting C string to string

2019-03-18 Thread DFTW via Digitalmars-d-learn

On Monday, 18 March 2019 at 22:33:21 UTC, H. S. Teoh wrote:
On Mon, Mar 18, 2019 at 10:20:35PM +, DFTW via 
Digitalmars-d-learn wrote:

[...]

[...]

Most likely explanation: you failed to call rt_init() before 
using a language feature that requires druntime to be 
initialized. In this case, a GC allocation by 
std.conv.to!string.


Call rt_init() immediately after loading the library, and 
calling

rt_term() after you're done with it, should fix this problem.


T


That's right. From the small code samples I've seen, they had no 
rt_init() usage, so I wasn't aware I've had to call it.

Thanks!


SEGFAULT when converting C string to string

2019-03-18 Thread DFTW via Digitalmars-d-learn
I'm writing a shared library in C to be used from a C program, so 
I went to my small tests. That one failed give a SEGFAULT on the 
std.conv.to call.


This is the pice of D code/the library:

extern(C) int foo(const char *name, int age)
{
import core.stdc.stdio : printf;
import core.stdc.stdlib;
import std.conv : to;
printf("printf() got called! age = %d\n", age);
printf("name = [%s]\n", name);
//auto nm = to!string(name); // <-- everything works until I 
uncomment this line.

return age * 2;
}

if matters, compiled with dub: "targetType" : "dynamicLibrary"
on 64-bit machine.

This is the piece of C code, foo.c:

#include 
#include 
#include 

int main(void)
{
  printf("+main();\n");
  const char* libpath = "mylib.so";
  void *lh = dlopen(libpath, RTLD_LAZY);
  if(!lh) {
fprintf(stderr, "dlopen error: %s\n", dlerror());
return EXIT_FAILURE;
  }

  int (*fn)(const char*, int) = dlsym(lh, "foo");
  char *err = dlerror();
  if(err) {
fprintf(stderr, "dlsym error: %s\n", err);
return EXIT_FAILURE;
  }
  const char *name = "jhon";
  int age = 18;
  int result = (*fn)(name, age);
  printf("unloading lib");
  dlclose(lh);
  printf("result = %d\n", result);
  printf("-main()\n");
  return 0;
}

compile as:

gcc foo.c -ldl

My OS is Ubuntu version 18

I'm assuming const char* both in C and D are raw pointers.



Re: what am I missing here with that working dir?

2019-03-18 Thread DFTW via Digitalmars-d-learn

On Monday, 18 March 2019 at 15:39:39 UTC, Andre Pany wrote:

On Monday, 18 March 2019 at 15:23:46 UTC, DFTW wrote:

On Saturday, 16 March 2019 at 07:27:43 UTC, FreeSlave wrote:

On Friday, 15 March 2019 at 21:48:50 UTC, DFTW wrote:

What am I missing here?


Maybe the terminal and your utility you run wkhtmltopdf from 
have different environment?


I guessed so, I've tried set the env as well:

enum env = ["LD_LIBRARY_PATH" :

"/path/to/wkhtmltox-0.12.4_linux-generic-i386/wkhtmltox/lib"];

import std.process : execute, Config;
auto conv = execute([app, html,pdf],
env,
Config.newEnv,
size_t.max,
workingDir);
but that doesn't work either.


My assumption is, the issue is not related to D or the working 
dir. It is more a linux thing. Maybe you also try function 
executeShell. Also did you have a look e.ghere
 
https://www.google.com/amp/s/www.cyberciti.biz/faq/debian-ubuntu-linux-wkhtmltopdf-error-while-loading-shared-libraries-libxrender-so-1/amp/


Kind regards
Andre


You're right, it's a linux issue. I did get rid of the binaries 
I've had and compile from the source code on my own, just passing 
the aditional LD_LIBRARY_PATH set to where the .so files were 
located, it worked fine!


Re: what am I missing here with that working dir?

2019-03-18 Thread DFTW via Digitalmars-d-learn

On Saturday, 16 March 2019 at 07:27:43 UTC, FreeSlave wrote:

On Friday, 15 March 2019 at 21:48:50 UTC, DFTW wrote:

What am I missing here?


Maybe the terminal and your utility you run wkhtmltopdf from 
have different environment?


I guessed so, I've tried set the env as well:

enum env = ["LD_LIBRARY_PATH" :
"/path/to/wkhtmltox-0.12.4_linux-generic-i386/wkhtmltox/lib"];
import std.process : execute, Config;
auto conv = execute([app, html,pdf],
env,
Config.newEnv,
size_t.max,
workingDir);
but that doesn't work either.


what am I missing here with that working dir?

2019-03-15 Thread DFTW via Digitalmars-d-learn
I'd like to call a executable which works fine on terminal if 
called within the bin directory otherwise it give missing issues. 
To archive the same on my D program, I did set the working dir 
but I get an error saying a .so file couldn't be found. What am I 
missing here?


enum app = 
"/path/to/wkhtmltox-0.12.4_linux-generic-i386/wkhtmltox/bin/wkhtmltopdf";

enum html = "/path/to/my/htmlFile.htm";
enum pdf = "/path/to/output/foo.pdf";
// is this the correct working dir?
enum workingDir = 
"/path/to/wkhtmltox-0.12.4_linux-generic-i386/wkhtmltox/bin";

import std.process : execute, Config;
auto conv = execute([app, html,pdf],
null,
Config.none,
size_t.max,
workingDir);
writeln(conv);

Gives the error:

Tuple!(int, "status", string, "output")(127, 
"/path/to/wkhtmltox-0.12.4_linux-generic-i386/wkhtmltox/bin/wkhtmltopdf" error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory\n")




am I using version right?

2019-03-12 Thread DFTW via Digitalmars-d-learn

version(Windows)
{
writeln("Hello from Windows system!");
}
else version(linux)
{
writeln("hello from linux!");
}
else static assert(0, "unknow system!");

In that code, the static assert() will run if and only if neither 
version condition is true, i.e, the OS is neither Windows nor 
linux. Correct?
My question is due version-else, I'm unsure if version-else works 
the way it does with regular if and the static assert() will not 
run at compile-time, regardless whether version is true