nixCraft Linux Forum

nixCraft

Linux / UNIX 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

Linux answers from nixCraft.


Coding in General Discussion on PHP/Perl/Python/Ruby/GNU C or C++. MySQL, PgSQL and (X)HTML or any other programming languages you want.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 17-10-2006, 09:38 PM
Junior Member
User
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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
  #2 (permalink)  
Old 18-10-2006, 02:28 AM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 708
Thanks: 15
Thanked 19 Times in 18 Posts
Rep Power: 10
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
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 follows)
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.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote
Reply


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 Off


Similar Threads

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


All times are GMT +5.5. The time now is 09:01 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 37 38