W
wojtek.fedorko
Hi,
I have a 3rd party c library which has some functions I'd like to use
inside my c++ prorgam.
I have the source code for this library but would not like to touch it
if possible.
the c library has files that look something like this:
header.h:
extern void foo();
--------------------------------------
lib.c:
#include "header.h"
void foo(a,b)
int a; // - btw I didn't know you could 'type'
your variables like this in c...
int b;
{
//do stuff
}
-------------------------------------
-So the prototype in the header doesn't match that in the .c file in
terms of number of parameters.
I'm writing my program like this:
extern "C" {
#include "header.h"
}
int main(){
int a,b;
foo(a,b);
}
This does not compile. The compiler complains that foo is called with
wrong number of parameters.
If write I something like this like this instead:
extern "C" {
#include "header.h"
}
extern "C" {
void foo(int,int);
}
int main(){
int a,b;
foo(a,b);
}
compiler complains about multiple definitions of foo.
For now I worked around this by editing header.h like this:
extern void foo(int,int)
but I would really like to avoid this as I don't control the library
code...
thanks a lot,
Wojtek
I have a 3rd party c library which has some functions I'd like to use
inside my c++ prorgam.
I have the source code for this library but would not like to touch it
if possible.
the c library has files that look something like this:
header.h:
extern void foo();
--------------------------------------
lib.c:
#include "header.h"
void foo(a,b)
int a; // - btw I didn't know you could 'type'
your variables like this in c...
int b;
{
//do stuff
}
-------------------------------------
-So the prototype in the header doesn't match that in the .c file in
terms of number of parameters.
I'm writing my program like this:
extern "C" {
#include "header.h"
}
int main(){
int a,b;
foo(a,b);
}
This does not compile. The compiler complains that foo is called with
wrong number of parameters.
If write I something like this like this instead:
extern "C" {
#include "header.h"
}
extern "C" {
void foo(int,int);
}
int main(){
int a,b;
foo(a,b);
}
compiler complains about multiple definitions of foo.
For now I worked around this by editing header.h like this:
extern void foo(int,int)
but I would really like to avoid this as I don't control the library
code...
thanks a lot,
Wojtek