link against a shared library in KDevelop 3.3

  • nhatkhang
  • Born
  • Born
  • nhatkhang
  • Posts: 2

Post 3+ Months Ago

--------------------------------------------------------------------------------

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
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • nhatkhang
  • Born
  • Born
  • nhatkhang
  • Posts: 2

Post 3+ Months Ago

hi
i got the solution
for the C++ project, i need to edit the .h file (BkTransLib.h).
i added extern "C" {all the functions}; into it,
thanks you all

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 134 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.