LinuxQuestions.org
Help answer threads with 0 replies.
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 01-31-2005, 09:04 AM   #1
johnnyde
LQ Newbie
 
Registered: May 2003
Location: India
Distribution: Fedora Core 1
Posts: 17

Rep: Reputation: 0
Question Library source in c and QT in c++ Will it work ??


hi
we are currently having a source code of a library in c. but according to the project we have to use QT interfac which is basically c++. so how do we integrate c in c++ or how to create a c library and use it in c++ programs??
thanks in advance
Johnny
 
Old 01-31-2005, 09:22 AM   #2
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
I don't see any problems I had personally used this kind of stuff in past. Write code in QT/C++ call the functions from C++ code here is simple example:

my.c
… some code

my.h

void testme(){
}


qt.cpp
#include “my.h”

void myClass::test(){
testme();
}


main.cpp
main and other stuff

Run commands to build new project (QT/C++)
qmake –project
qmake
make

And you are done
 
Old 02-01-2005, 01:32 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
There's no problem. You include header file for the library and can use its functions. Need only to make sure the program is linked with the library (so it usually means a need to modify program's Makefile).
 
Old 02-02-2005, 06:16 AM   #4
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
Quote:
Originally posted by Mara
There's no problem. You include header file for the library and can use its functions. Need only to make sure the program is linked with the library (so it usually means a need to modify program's Makefile).
qmake -project
qmake

does this for you!
 
Old 02-02-2005, 10:23 AM   #5
johnnyde
LQ Newbie
 
Registered: May 2003
Location: India
Distribution: Fedora Core 1
Posts: 17

Original Poster
Rep: Reputation: 0
Did some research !!

Ok. Thanks for the help guys. This is the spirit of open source . I did google and found some answers.
If you are including a C header file that isn't provided by the system, you may need to wrap the #include line in an extern "C" { /*...*/ } construct. This tells the C++ compiler that the functions declared in the header file are C functions.


Code:
  // This is C++ code   
 extern "C" { 
   // Get declaration for f(int i, char c, float x)  
  #include "my-C-code.h" 
 }
    int main() 
 { 
   f(7, 'x', 3.14);   // Note: nothing unusual in the call    ... 
 }

here is the link for the page.
http://www.inf.uni-konstanz.de/~kueh...c-and-cpp.html

http://gcc.gnu.org/ml/gcc-help/2001-11/msg00092.html - this page has a good explanation of technical complexities involved in mixing c and c++ and tells how to that too.

Thanks
I Salute the open source community

Johnnyde
 
Old 02-03-2005, 01:54 PM   #6
Genjix
Member
 
Registered: Oct 2003
Location: Pico
Distribution: SUSE 9.1
Posts: 83

Rep: Reputation: 15
actually its good practice to include the wraps inside the header files themselves. you can also use gcc to compile the c files, g++ to compile the c++ files, then link with a linker (just use g++).
 
  


Reply



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
creating shared library from C++ source Darkfalz Linux - Software 3 11-03-2005 11:34 AM
source for xlib / libx11 library source? Whatsisname Linux - Software 7 02-18-2005 03:23 PM
Source Function Library dadepfan Linux - General 2 08-22-2004 11:06 PM
Open source Digital Library jgnasser Linux - Software 0 03-16-2004 12:15 AM
Source for RPM library saravanan1979 Linux - Software 15 06-19-2002 06:56 AM

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

All times are GMT -5. The time now is 04:30 PM.

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