LinuxQuestions.org
Visit Jeremy's Blog.
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 06-11-2009, 08:30 AM   #1
morty346
Member
 
Registered: Feb 2009
Posts: 52

Rep: Reputation: 15
I created a c .so object, and can link successfully, now I want to make it for c++


I created a c .so object, and can link successfully, I now need it to work with a cpp, so I converted my .so into a cpp, I added extern "C" to all of my functions that are needing exported, and it seems to be fine, except when its time to link it with a .cpp main

I can compile it with a .c main file, I do get warnings, but it does work

When I switch my main to a cpp the warnings seem to turn into errors

Warning in C:
implicit declaration of "Function"

Error in C++:
"Function" was not declared in scope

To Compile the c or cpp i use
Code:
$ gcc -o client client.cpp -L. -lprint
or
$ gcc -o client client.c -L. -lprint
I have followed this tutorial almost verbatim
http://www.ibm.com/developerworks/library/l-shobj/
 
Old 06-11-2009, 08:34 AM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
It's hard to say anything without reading your code, but with C++ it's a little bit trickier. You might want to take a look at this tutorial.
http://tldp.org/HOWTO/C++-dlopen/
 
Old 06-11-2009, 09:20 AM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Quote:
Warning in C:
implicit declaration of "Function"

Error in C++:
"Function" was not declared in scope
This is a compiler error: you need to *declare* a function before you use it. For example:
Quote:
myheader.h =>
Code:
#ifdef __cplusplus
  extern "C" {
#endif

int MyFunction (int x, int y);

#ifdef __cplusplus
  }
#endif
myprogram.c =>
Code:
   ...
   int i = MyFunction (2, 3);
In other words:
1. Be sure to declare your functions before you use them (e.g. with a "function prototype")
2. Ideally, you should be able to put all your prototypes in a header file
3. Be sure to use "extern C" in your prototype declaration.

This link explains further:
http://www.parashift.com/c++-faq-lit...c-and-cpp.html

'Hope that helps .. PSM
 
Old 06-11-2009, 10:18 AM   #4
morty346
Member
 
Registered: Feb 2009
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by paulsm4 View Post
Hi -



This is a compiler error: you need to *declare* a function before you use it. For example:


In other words:
1. Be sure to declare your functions before you use them (e.g. with a "function prototype")
2. Ideally, you should be able to put all your prototypes in a header file
3. Be sure to use "extern C" in your prototype declaration.

This link explains further:
http://www.parashift.com/c++-faq-lit...c-and-cpp.html

'Hope that helps .. PSM
Thank you
however, we are using a .h, and everything has extern "C" infront of it, both declaration and definition
 
Old 06-11-2009, 10:24 AM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

1. If you're getting 'implicit declaration of "Function"', then "Function()" doesn't have a prototype - or at least the prototype isn't visible to the guy who needs it.

2. If you have an 'extern "C" {}' for your declaration ... then you don't need it for the definition.

So check again: you're probably missing something very, very simple.

PS:
Try hedging your bets, and compile with "g++" instead of "gcc". Can't hurt; might help. At least help track down the actual problem...
 
  


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
I created a link but it doesn't work. Gins Linux - General 12 09-26-2008 08:33 PM
is anyone able to successfully make an installation package with gambas? aznboi12321 Programming 1 02-25-2006 08:43 PM
PHP & MYSQL => session object using db link resource ldp Programming 2 03-19-2005 02:38 AM
how can .ko object be created?? hiteshmaisheri Linux - Software 3 04-26-2004 12:02 AM
How does VC link a dll created by cygwin? chuanyung Programming 1 02-25-2004 12:06 PM

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

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