LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-19-2005, 07:13 AM   #1
tristanm
Member
 
Registered: Jun 2005
Location: Pretoria, South Africa
Distribution: Ubuntu, Fedora Core, RHEL
Posts: 37

Rep: Reputation: 15
Angry Linking static and shared libraries in the KDevelop Environment


Right here goes...

I am using the KDevelop environment to write simulation software on SuSE 9.2 Pro. I am using third party libraries for the mathematics and would lke to do so for the plotting.
The math library is static(.a). The only way I can get it to link is by placing its full path in "Project -> Project options -> Configure Options -> Linker flags (LDFLAGS):". I then include the header files by using the Automake Manager and right clicking "src" selecting the "Includes" tab and adding the relevant directory to the "Directories outside project" pane. This works fine.

I also tried another method of linking the static library: in the Automake manager I right click on the program and select "Options". I then select the Libraries tab and add the full path of the library to the "Link libraries outside project (LDADD)" window. When I try and compile with this method the error messages stating "undefined reference to ..." dissapear and instead I get "Exited with status: 2".

The exact same thing happens when I try to link a shared library in this fashion. However I cannot seem to add multiple libraries to the Linker flags box as described above. I have tried space, coma and semi-colon seperated lists with no success. I get "Exited with status: 77" from autoconf.

I have no idea what to do now and am intensly frustrated. I need to link more than one library and just cannot seem to do it. The documentation for Kdevelop is very poor being significantly incomplete!

I would appreciate some help on this matter. Am I going about the linking the correct way or is there a better way to do it?

Regards
Tristan
 
Old 10-20-2005, 01:24 AM   #2
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
First of all i know that this is a problem in KDevelope3, but you can do it.
In Kdevelop3 on the left of you kdevelope editor there is an menu for automake menager, go to that menu and go to options by left click on your project. on the first tab i.e Flags there are some check boxes and then there you will find a field with text:
other $(KDE_RPATH) $(all_libraries)


just append it with the path of your libs and it will work fine. for example:
other $(KDE_RPATH) $(all_libraries) ../../MyLib.a ../../StaticLib.a

and do not use semi-colon or comma to seperate multiple libraries. Just use space to seperate two libs.

wish you all the best!!

Last edited by cppkid; 10-20-2005 at 01:31 AM.
 
Old 10-20-2005, 01:38 AM   #3
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
If you didn't find it you can do it manually by.
You can also do it by changing the make file, After compiling the project go to the debug or optimized folder whatever you configure for, and open the make file. and then search for macro LIB and you will find it nearly about line # 310 to 315, you will find it as:
LIB =
just wite your libs with reletive path and run your project, like.
LIB = ../../libs/myLib.a ../../libs/math.a ../LastLib.a

Again keep in mind that do not use comma or semi-colon. Just use space to seperate two libs.
 
Old 10-20-2005, 03:51 AM   #4
tristanm
Member
 
Registered: Jun 2005
Location: Pretoria, South Africa
Distribution: Ubuntu, Fedora Core, RHEL
Posts: 37

Original Poster
Rep: Reputation: 15
Thanks for the help cppkid. Your first solution works great for static libraries. Now I am trying to link shared libraries and once again I get left with "Exited with status:2". I wonder if perhaps I am missing some of the libraries which should be linked. But if this was the case, wouldnt the compiler tell me where the errors lie?
 
Old 10-21-2005, 05:28 AM   #5
tristanm
Member
 
Registered: Jun 2005
Location: Pretoria, South Africa
Distribution: Ubuntu, Fedora Core, RHEL
Posts: 37

Original Poster
Rep: Reputation: 15
I have fixed the library linking problem. The solution I found was as follows:

In the Automake Manager pane called "Link Libraries Outside of Project": the full path of a static library including the file name and extension should be added without any preceding "-l".

To link a shared library one should add the path to LDFLAGS as follows: "-L/path/to/library". Then one should add the name of the library to the "Link Libraries Outside Project" pane as "-lnameoflibrary". This should not contain the lib prefix or .so extension.

Automake Manager then constructs the line in the makefile which will look as follows:
LDFLAGS = /path/to/static.a -L/path/to/shared -lshared

Hope this helps anyone else out there who may have experienced this problem.

Cheers
Tristan
 
Old 05-12-2006, 03:10 AM   #6
punx120
Member
 
Registered: May 2004
Distribution: Debian sid amd64
Posts: 35

Rep: Reputation: 15
Hello,

I'm also trying to link static and shared libraries.

In my kdevelop project, I create 4 libtool sub project. The problem is that, those libraries are dynamically linked, and I don't know how to link statically.

I tried to add .la files (generated y libtool) to the command lines, but libtool told me that it couldn't find those files.


Thanks for your help.
 
Old 05-12-2006, 11:25 AM   #7
tristanm
Member
 
Registered: Jun 2005
Location: Pretoria, South Africa
Distribution: Ubuntu, Fedora Core, RHEL
Posts: 37

Original Poster
Rep: Reputation: 15
Question

I am not really sure what your problem is punx120. Please describe specifically what you are trying to do and what you have done that won't work. Are the libtool libraries part of your project or are they 3rd party? What command lines are you adding them to?

I have not really tried linking libtool libraries. I generally just link static libraries with the .a extension in which case you need to specify the full path as I have already noted. Don't forget that all you are really doing is creating a makefile with a gui. If you are not sure where to add something in the automake gui in kdevelop, then I suggest that you add it and take at the look at the makefile which is generated. Knowing where it ends up in the makefile should help enourmously.

A query for anyone else out there reading this thread... Has kdevelop made the compiling and linking of your own shared libraries any easier lately? The last time I tried was at the end of last year and I wasn't very succesful. All I managed to do was create static libraries with .so extensions!
 
Old 05-13-2006, 05:24 AM   #8
punx120
Member
 
Registered: May 2004
Distribution: Debian sid amd64
Posts: 35

Rep: Reputation: 15
Actually, I create a simple C++ project. Then I'd like to make sub directory, so I find the solution to add new targets (libtool library). It works well. But it doesn't create classic .a file, but .la (libtool .a I guess). And as you said, I create static libraries with .so extensions !

So I can't find any solutions, I will take a look to the Makefile this afternoon.
 
Old 05-14-2006, 02:00 PM   #9
tristanm
Member
 
Registered: Jun 2005
Location: Pretoria, South Africa
Distribution: Ubuntu, Fedora Core, RHEL
Posts: 37

Original Poster
Rep: Reputation: 15
There should be two library options. A library and a libtool library. Select just the library to create a .a static library.
 
Old 05-14-2006, 02:24 PM   #10
punx120
Member
 
Registered: May 2004
Distribution: Debian sid amd64
Posts: 35

Rep: Reputation: 15
Thanks, I found the good target.
 
Old 10-30-2006, 04:34 AM   #11
muttley.82
LQ Newbie
 
Registered: Oct 2006
Posts: 1

Rep: Reputation: 0
Hi, i've the same problem with a kdevelop C++ project organized in more than one directory.
I associate a library no-inst target(.a) for each subdirectory but at linking time of the project i receive these errors:

...
classX::methodsY() undefined reference to classZ::methodsW()
...

where classX and classY reside in two different subdirectory.

Thank, Antonio.
 
Old 10-30-2006, 04:42 AM   #12
punx120
Member
 
Registered: May 2004
Distribution: Debian sid amd64
Posts: 35

Rep: Reputation: 15
Are you sure to link with all static libs ?
 
Old 10-30-2006, 08:48 AM   #13
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Quote:
Originally Posted by muttley.82
Hi, i've the same problem with a kdevelop C++ project organized in more than one directory.
I associate a library no-inst target(.a) for each subdirectory but at linking time of the project i receive these errors:

...
classX::methodsY() undefined reference to classZ::methodsW()
...

where classX and classY reside in two different subdirectory.

Thank, Antonio.
did you tell your project to link the libraries into it? you have to specify that those libs are linked in, because it is not done automatically..

i cant remember off the top of my head but its and option on the automake config panel somewhere..
 
Old 10-30-2006, 10:07 AM   #14
tristanm
Member
 
Registered: Jun 2005
Location: Pretoria, South Africa
Distribution: Ubuntu, Fedora Core, RHEL
Posts: 37

Original Poster
Rep: Reputation: 15
Originally posted by muttley.82:
Quote:
Hi, i've the same problem with a kdevelop C++ project organized in more than one directory.
I associate a library no-inst target(.a) for each subdirectory but at linking time of the project i receive these errors:
Er... Its been a while since I last worked with this stuff but I'll try to help.

First of all, whay are you making your libraries no-inst targets? I have no idea how the no-inst tag really works but I have never used it for libraries before (not even for static libraries).

Secondly: right click on the project targets for the main project and each sub-project. Under the libraries linker make sure that there are internal links to all the internal libraries necessary for that sub-project to compile. Also right click on the project tree and make sure that all the internal include directories are setup in much the same way.

If my explanation is unclear or you continue to have trouble I will try and give more precise directions or post some screen shots (if I can do that here).
 
Old 11-27-2006, 12:33 AM   #15
nhatkhang
LQ Newbie
 
Registered: Oct 2006
Posts: 9

Rep: Reputation: 0
hi ! sorry for the lenght of this post.
i'm using KDevelop 3.3.1 on Ferdora Core 5
i create a C project with Automanke Manager, add main.c ,LibBkTrans.h into it.
//main.c
#include "BkTransLib.h"
int main() {
if (BKInit())
{
//do nothing
}
}
//BkTransLib.h
int BKInit();

a shared library libbktrans.so.0.0 contains the implementation of BKInit(), i put it in /usr/local/lib and install it correctly
i build the project --> error: "undefined reference to BKInit(), it's because i haven't linked against the shared library
so i right-click on the project name (Program in bin)in Automake Manager window, choose Options, in the tab Libraries i add
-lbktrans into the box "Link libraries outside the project(LDADD)"
at last i rebuid the project --> Success

now i delete file /path_to_project/src/Makefile.in and the whole directory /path_to_project/debug
then i remove the main.c from the project, go to /path_to_project/src and rename main.c to main.cpp, no problem, cause the main.c is very simple like above.
i add this main.cpp into the project and rebuid --> error: "undefined reference to BKInit()"
i don't know why.

i try another approach: create a C++ project, add main.ccp and BkTransLib.h into it
build --> error: "undefined reference to BKInit()"
i link the library by adding -lbktrans into the box "Link libraries outside the project(LDADD)"
rebuild --> error: "undefined reference to BKInit()".

perhaps, the shared library can't link into a C++ project.(this is my very stupid idea !)
because i was successful to link against a simple shared library to both C and C++ project.
does anyone have a better idea ?
Regards
nhatkhang
 
  


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
any links on linking, loading shared libraries, shared objects. etc? ananthbv Programming 0 02-03-2005 07:47 AM
Finding and Linking Static Libraries with gcc neorich Programming 15 08-10-2003 04:03 PM
Shared libraries and linking., devin Programming 3 04-08-2003 03:18 PM
Linking to shared libraries? Griffon26 Programming 1 10-20-2001 05:29 PM
linking with shared libraries kobilevi Programming 0 03-01-2001 10:09 AM


All times are GMT -5. The time now is 09:39 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration