LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-10-2006, 05:29 AM   #1
George2
Member
 
Registered: Oct 2003
Posts: 354

Rep: Reputation: 30
strange linking error -- can not find shared library


Hello everyone,


I am meeting with a strange linking error when linking with a shared library on Linux platform. I use goo.c to generate libgoo.so, then write an application foo.c and link it with libgoo.so. The error occurs when linking with libgoo.so. The strange point is that, the LD_LIBRARY_PATH is not working, but -L option to gcc works -- I think they should be the same, but in my case below, it seems only -L works.

Here are the source codes,

goo.c

Code:
int goo_export()
{
	return 10;
}
goo.h

Code:
int goo_export();
foo.c

Code:
#include "goo.h"

int main()
{
	goo_export();
}
Error messages,

[root@localhost shared_goo]# gcc -shared goo.c -o libgoo.so
[root@localhost shared_goo]# export LD_LIBRARY_PATH=.
[root@localhost shared_goo]# gcc -I. -lgoo foo.c
/usr/bin/ld: cannot find -lgoo
collect2: ld returned 1 exit status
[root@localhost shared_goo]# gcc -I. -L. -lgoo foo.c


thanks in advance,
George
 
Old 07-10-2006, 11:24 AM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
I believe LD_LIBRARY_PATH is for use at execution time, not at linking time. (To determine when to use LD_LIBRARY_PATH, call ldd on the binary. If it can't find a shared lib, you have to set LD_LIBRARY_PATH to tell the kernel where to look.)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find what shared library is in memory Patrick Bulteel AIX 3 10-26-2005 10:35 AM
Commandline legth problem linking a shared library DavePrince Linux - Software 0 07-20-2005 08:19 AM
Shared library error olscratch Slackware 3 11-05-2004 03:46 PM
Linking a platform independent shared library rozeboom Programming 3 11-18-2003 02:10 PM
gnome shared library error mismacku Linux - Software 1 05-03-2003 04:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration