Linking static and shared libraries in the KDevelop Environment
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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?
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.
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.
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!
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.
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.
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..
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).
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.