Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


Closed Thread
  Search this Thread
Old 08-25-2009, 01:56 AM   #1
LQ Newbie
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
Question undefined refrence while reverse dependency in shared library..

Hi everyone ,
I am using loading a shared library dynamically in my code using dlopen() & then calling a function of it which in turn calling the function of my own program .But this is giving "undefined reference" problem .Please see the following snap of the code :

Code for main Program :
#include <dlfcn.h>
#include "sample_header.h"
void main_fun(int k)
printf("\n ***** In Main Fun : %d",k);
void main()
char *error;
void (*sample_fptr)(int);
void *handle = dlopen ("./", RTLD_LAZY);
if (!handle)
printf ("\n%s\n", dlerror());

sample_fptr = dlsym(handle, "shared_fun");
if ((error = dlerror()) != 0)
printf ("\n%s\n", dlerror());

printf("Done ........\n");

compilation command used : gcc -ldl sample.c
//sample_header declaration is :

#include <stdio.h>
void main_fun(int k);


Code for sample_shared.c :
#include "sample_header.h"
void shared_fun(int k);
void shared_fun(int k)

compilation command : gcc -shared -Wall sample_shared.c -o

Result : ./ undefined symbol: main_fun

Any suggestion to resolve this issue is appreciated.

Thanx in Advance
Old 08-25-2009, 04:24 AM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

In this case I'm closing the original because the dupe is more sensibly placed.

Closed Thread

dependency, library, reverse, shared

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
Shared Library error : undefined reference xs2harpreet Programming 6 03-11-2009 05:55 PM
'Undefined refrence to main error' in winavr gcc compiler???? zack670303 Programming 1 02-26-2009 12:47 PM
undefined symbol, compiler version? shared library troubles? thewtex Programming 6 02-25-2007 04:32 PM
undefined refrence return status link error azucarmom Programming 7 03-30-2005 11:15 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:53 AM.

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