Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker error when using curl #501

Closed
Ingrater opened this issue Oct 9, 2013 · 10 comments
Closed

Linker error when using curl #501

Ingrater opened this issue Oct 9, 2013 · 10 comments

Comments

@Ingrater
Copy link

Ingrater commented Oct 9, 2013

Using std.net.curl and compiling with ldmd2 causes a linker error because ldmd2 does not link automatically against libcurl (dmd does).

@redstar
Copy link
Member

redstar commented Oct 11, 2013

Confirmed. It happens with ldc2, too.
I don't know what is failing here right now. My proposed solution is #429 (which currently does not work, too).

@redstar
Copy link
Member

redstar commented Oct 11, 2013

Quite funny. I understand why ldmd2 and ldc2 causes a linker error. (The library name is not passed to the linker.)
But I don't understand why it works with dmd....

@redstar
Copy link
Member

redstar commented Oct 11, 2013

Which OS do you use?

With dmd automatic linking using pragma(lib) works on Windows because the linker command is stored in the object file. On ELF based systems (Linux, FreeBSD), this is not supported. In this case dmd fails with a linker error, too.

I am going to add the Windows behaviour to ldc. Does this fix your error?

@dnadlinger
Copy link
Member

@redstar: Wait a second: As far as I'm aware pragma(lib) is supposed to be picked up irrespective of the linker commands being stored into object files or not. The problem with std.net.curl, at least for DMD on Linux, is that it sits in the standard library, which is linked after the before-unused symbols from libcurl have already been discarded: http://d.puremagic.com/issues/show_bug.cgi?id=7044

@redstar
Copy link
Member

redstar commented Oct 14, 2013

How I understand the source is that the library name is only picked up for the module which is currently compiled.
What I have tried is:

  • compile std.net.curl unit test -> curl is added to global.params.linkswitches
  • compile a module importing std.net.curl -> curl is NOT added to global.params.linkswitches

I examined the source not too close so I may miss here something. And I only checked on FreeBSD as I messed up my Gentoo installation.

@Ingrater
Copy link
Author

I did use the windows 32bit mingw version.

@dnadlinger
Copy link
Member

@redstar: I just checked the behavior of DMD on OS X, and it seems as if you are indeed right, i.e. the linker flag is only added when the module containing the pragma(lib, …) declaration is compiled itself. Considering the documentation, this makes sense, as it speaks about "insert[ing] a directive in the object file".

I think what I was thinking of was some build tool (DSSS?) that actually read those directives from files you included and adjusted its actions accordingly.

redstar pushed a commit that referenced this issue Sep 27, 2014
do not only compile, but also run unittests on windows
@redstar
Copy link
Member

redstar commented Nov 14, 2014

The issue on mingw is fixed (long time ago, with #429). On ELF-based systems it can't be fixed because the feature is not supported.

@redstar redstar closed this as completed Nov 14, 2014
@dnadlinger
Copy link
Member

From what I gather from recent PR discussions, Martin is working on dynamic loading of libcurl in upstream Phobos. This will finally resolve this situation.

@redstar
Copy link
Member

redstar commented Nov 15, 2014

Clarification: this issue is fixed on platforms which have a toolchain which supports embedding of library references. This is only Windows with use of MS link. MinGW also uses COFF (the only object format which supports this) but uses the binutil ld which ignores this directive (Warning: .drectve '-lws2_32' unrecognized).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants