Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Compile/Link on Unix question

Posted on 2013-11-18
9
Medium Priority
?
785 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 36

Assisted Solution

by:mccarl
mccarl earned 750 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 36

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 

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 750 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

715 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