nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Library Linking in GCC

This is a discussion on Library Linking in GCC within the Coding in General forums, part of the Development/Scripting category; Ok, I know I am missing something truly elemental but I need help. First off, let me apologize for my ...


Go Back   nixCraft Linux Forum > Development/Scripting > Coding in General

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-17-2006, 09:38 PM
Junior Member
 
Join Date: Oct 2006
Posts: 1
Rep Power: 0
newbie-wan
Default Library Linking in GCC

Ok, I know I am missing something truly elemental but I need help. First off, let me apologize for my inexperience. I am just starting use of Linux and gcc and know enough to be dangerous.

That being said, I've created a shared object library from a series of c source files in gcc. I now have a libraray libName.so in my working directory. To make sure this library works I have a test program (testprog.c) that calls the library. When I compile that file using: gcc -o testprog.c -l Name, I get the error /usr/bin/ld: cannot find -lName. I cannot seem to copy the library to any of the library directories (get an error in Unbutu that says I can't) so I would like to have the compiler pick up the library from my working directory. How do I do that? Is there anything else I am missing or any mistakes that could be causing this?

Thanks for your help!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-18-2006, 02:28 AM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 557
Rep Power: 6
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Hi!

Well I am not pro @ C/C++ I have just started to learn for my college studies. Here is what we do in lab:

After creating shared lib you need to execute command (note . after -n option):
Code:
ldconfig -v -n .
Then setup linker name (for exmple if your lib name is libmyapp then it should be as follow
Code:
ln -sf libmyapp.so.0 libmyapp.so
Now compile your program
Code:
gcc -Wall -g -c mytestprog.c -o mytestprog.o
Now build and link (note . after -L option)
Code:
gcc -g -o mytestprog mytestprog.o -L. -llibmyapp
To execute program (note . )
Code:
LD_LIBRARY_PATH="."
./mytestprog
Read man page of ldconfig and gcc for more info.
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
gcc linking error kavi Coding in General 9 09-30-2005 05:25 AM


All times are GMT +5.5. The time now is 02:19 AM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36