Solved

Compile/Link on Unix question

Posted on 2013-11-18
9
741 Views
Last Modified: 2013-11-19
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, libcurl.la, libcurl.so, and libcurl.so.7. 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 libcurl.so.7 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?
0
Comment
Question by:jmckay321
  • 4
  • 3
  • 2
9 Comments
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 250 total points
ID: 39658419
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

=

/usr/local/lib/libcurl.so
0
 

Author Comment

by:jmckay321
ID: 39658469
Yes I did do a make install, as in:

 ./configure --prefix=/usr/home/comaxis/curl
 make
 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.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39658733
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.
0
 
LVL 86

Expert Comment

by:jkr
ID: 39659524
>>I have the directory /home/comaxis/curl/lib in which are contained the files libcurl.a,
>>libcurl.la, libcurl.so

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 'libcurl.7.so'. 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.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:jmckay321
ID: 39659558
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.
0
 
LVL 86

Expert Comment

by:jkr
ID: 39659568
No static version of the CRT installed? Hm, that's bad...

Can you try to rebuild/install libcurl then?
0
 

Author Comment

by:jmckay321
ID: 39659609
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, libcurl.la, libcurl.so.7, and also the link: libcurl.so -> libcurl.so.7
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 39659630
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 libcurl.so.7 resides is not among the ones listed there, add it using

export _LD_LIBRARY_PATH=$_LD_LIBRARY_PATH:[path_to_libcurl]
0
 

Author Closing Comment

by:jmckay321
ID: 39660034
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now