Compile/Link on Unix question

Hi, I wonder if you can help me with a development issue related to "libcurl".  I am an experienced Windows developer but I need to do something on a BSD Unix system, and I am basically a novice with that.  I am trying to write a C program that links with this
open source library for doing http requests.  I have uploaded the libcurl  tar file, uncompressed it, and I believe I successfully built the library.  I have the directory /home/comaxis/curl/lib in which are contained the files libcurl.a,,, and From the directory /usr/home/comaxis, I use the command:
 cc demo.c -Lcurl/lib -lcurl, and receive no errors.  But when I try to run a.out, I get the
error "Shared object not found, required by a.out".

Now, following directions from the libcurl web site, I do instead:
cc demo.c /Lusr/local/lib -lcurl.  The executable produced by that works fine.

The problem is that the libcurl version that is in /usr/local/lib is older, and I would prefer to use the version that I just made.  What is the problem?

Another question, I don't really understand what I am doing with the -l switch.  There is nothing in the directory that I specify named "curl" - so how does the link even work?
Who is Participating?
jkrConnect With a Mentor Commented:
Then it does not place the files under '/usr/lib'? See what you '_LD_LIBRARY_PATH' is made up of, and if the directory where resides is not among the ones listed there, add it using

export _LD_LIBRARY_PATH=$_LD_LIBRARY_PATH:[path_to_libcurl]
mccarlConnect With a Mentor IT Business Systems Analyst / Software DeveloperCommented:
I believe I successfully built the library
It seems as though this is true, but the "building" step is all you have done. You probably should "install" it also, by doing a "make install" from the libcurl directory. Check the output of that to see exactly where it installs it (should be /usr/local/lib be check to make sure). Then you should be able to use the second version of the "cc" command that you posted, and it should use this updated libcurl library.

I don't really understand what I am doing with the -l switch
The -L and the -l switches work together to specify the library to use. -L specifies a path to search for library files, and -l (with a "lib" prefix and a ".so" suffix) specifies the library that you want. So in your example....

(Where the bold items below indicates the values entered for -L and -l)

/usr/local/lib/    +      lib    +      curl    +     .so


jmckay321Author Commented:
Yes I did do a make install, as in:

 ./configure --prefix=/usr/home/comaxis/curl
 make install

That is what created the directory /curl/lib and populated it with the .so file.

By the way, this is on a system owned by my ISP, so I don't have root and can't do anything to /usr/local/lib.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
this is on a system owned by my ISP
Ah, there's the missing link. So you could try and get the dynamic library loader to load your shared library (.so file) but the easiest way might be to just link your demo against the static version of libcurl (.a file). Try this line to compile the demo program...
cc demo.c -Lcurl/lib -Wl,-static -lcurl

Open in new window

It forces it to use the static library in that directory rather than the shared library.
>>I have the directory /home/comaxis/curl/lib in which are contained the files libcurl.a,

If the static lib suggestion by mccarl does not work (which I doubt) you should try to download libcurl as a source package, unzip it and then do a './configure' and then 'sudo make install'. That will place the shared binary in the correct location and create the symlink ''. As a side note, another possibility would be to create the link manually and set '_LD_LIBRARY_PATH' to point to the directory it resides in.

BTW, your build does work because - in an analogy to Windows - you have the import library, but the system can't find the DLL at runtime.
jmckay321Author Commented:
The command: cc demo.c -Lcurl/lib -Wl,-static -lcurl

results in:

/usr/bin/ld: cannot find -lgcc_s

Sorry, I know I should be able to work it out myself at this point, and I will keep at it, but if there is some obvious solution to this let me know.
No static version of the CRT installed? Hm, that's bad...

Can you try to rebuild/install libcurl then?
jmckay321Author Commented:
Yes I can recompile and install - that is what I did originally.  Not sure what "sudo" is but I did do a "make install" which resulted in it creating the curl/lib directory for me, where it put the files libcurl.a,,, and also the link: ->
jmckay321Author Commented:
Thanks for your help.  I think I'm going to give up on this for now, as I'm chasing a problem that doesn't exist - I can use the already installed libcurl and it works fine.  Hopefully I won't need a feature in a newer version.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.