Unix makefile help



  • I have a project that currently links against libcurl. I do this by passing in -lcurl. The system has both libcurl.a and libcurl.so. How do I know which it used? And can I force it to use the .a?

    I'd like to do this without specifying the full path. The compiler "just knows" where it is (/usr/lib/x86_64-linux-gnu/ in this case, I suspect my Mac will be different but it's turned off right now).


  • ♿ (Parody)

    @dcon

    It is possible of course, use -l: instead of -l. For example -l:libXYZ.a to link with libXYZ.a. Notice the lib written out, as opposed to -lXYZ which would auto expand to libXYZ.



  • @boomzilla Cool! Thx! (I tried googling, but it was lost in the noise probably...)



  • Oh dang. Of course, nothing on unix is that simple. Now I have pages and pages of undefined linkage errors. googling suggests using the output of curl-config --static-libs. But that generates lots of "cannot find" errors.

    Hell, guess I'll just leave it as -lcurl and document 'if you have an error, sudo apt install curl'. Or document how to compile curl and what needs to be done in my project to link to that... I'm not really concerned about linux - anyone using my stuff there is already compiling it themselves. I'm more concerned that my OSX build works on 10.10 and later...


  • Java Dev

    @dcon That's probably wise.

    Remember static linking means you need to rebuild every time there is a security patch for one of your dependencies.



  • @dcon said in Unix makefile help:

    Now I have pages and pages of undefined linkage errors.

    When linking against the .a, you probably need to pull in additional dependencies that the .a has. (That's probably what curl-config returns in addition, and what causes the "cannot find" errors.)

    I don't have a static build of libcurl here; looking at the dynamic library (via ldd), it additionally depends on libnghttp2, libssl, and so on. You would have to pass those to the linker as well.



  • @cvi said in Unix makefile help:

    @dcon said in Unix makefile help:

    Now I have pages and pages of undefined linkage errors.

    When linking against the .a, you probably need to pull in additional dependencies that the .a has. (That's probably what curl-config returns in addition, and what causes the "cannot find" errors.)

    I don't have a static build of libcurl here; looking at the dynamic library (via ldd), it additionally depends on libnghttp2, libssl, and so on. You would have to pass those to the linker as well.

    I put the curl-config cmd into the makefile. That generated many 'cannot find' errors for various libs. Maybe if I wade thru them, I can apt install some other packages, but right now, :kneeling_warthog: - too much magic involved.


Log in to reply