LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 05-04-2010, 06:28 AM   #1
Learnit
LQ Newbie
 
Registered: May 2010
Posts: 2

Rep: Reputation: 0
Exclamation Cyclic dependency when using extern symbols from libraries


I have a shared library (built from C++ code) and a separate C program which calls (extern) functions from the said library.

Also one of the functions in that library needs to call a function in this C program by declaring it 'extern'. This sort of creates a cyclic dependency.

I am getting "unresolved references" error, as expected. How can I get this resolved in the best possible way?
 
Old 05-04-2010, 09:31 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Learnit View Post
I have a shared library (built from C++ code) and a separate C program which calls (extern) functions from the said library.

Also one of the functions in that library needs to call a function in this C program by declaring it 'extern'. This sort of creates a cyclic dependency.

I am getting "unresolved references" error, as expected. How can I get this resolved in the best possible way?
In 'man ld' read about '--start-group', '--end-group'.
 
1 members found this post helpful.
Old 05-05-2010, 07:18 AM   #3
Learnit
LQ Newbie
 
Registered: May 2010
Posts: 2

Original Poster
Rep: Reputation: 0
>
Quote:
Originally Posted by Sergei Steshenko View Post
In 'man ld' read about '--start-group', '--end-group'.
Thanks for the info.
Looks like it is indeed better to re-factor the code to avoid cyclic dependency.
 
Old 05-06-2010, 07:26 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You shouldn't have that problem if you enclose the declaration of the function in the C++ library with extern "C" {}, then have the executable link to the library. It also matters where you put the library on the command line during linking.
Kevin Barry
 
  


Reply

Tags
dependency



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
configure won't recognize Libraries; Always have a dependency problem theKbStockpiler Linux - Software 11 09-30-2009 03:11 PM
ndiswrapper-utils & ndiswrapper-modules cyclic dependency benoit808 Debian 4 02-19-2007 05:35 PM
Hiding Symbols in Static Libraries JCipriani Programming 2 03-03-2006 05:15 PM
Libraries |.so?| dependency ??? redhatrosh Linux - Software 3 07-03-2005 12:19 PM
Making static symbols private/local in shared libraries skoona Programming 1 02-18-2005 03:14 PM

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

All times are GMT -5. The time now is 12:10 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