07-29-2005, 01:02 AM
I'm a C/C++ programmer and have very little knowledge about FB or BASIC in general, so please bear with me.
In my project, I need to write C/C++ program that'll call routines implemented by someone else in FB, since static libs and dlls can be created using FB. As a beginner trying to take the first step, I created the sample mydll.dll using fbc (fbc -dll mydll.bas) and am now trying to call the AddNumbers sub from my C code in VC++ on a windows system. VC++ cannot resolve AddNumbers even though I'm linking it with the mydll import library. To make sure that its not a naming convention issue, I tried renaming libmydll.dll.a to mydll.lib. VC++ will still not link it, giving me the error "error LNK2001: unresolved external symbol _AddNumbers".
Here's my C program that I'm using to test calling VB Subs from C code:
#include <stdio.h>
extern "C" {
int AddNumbers(int a, int b);
int main(int argc, char* argv[])
{
int a = 5;
int b = 7;
int sum = 0;
sum = AddNumbers(a, b);
printf("AddNumbers returned the sum = %d\n", sum);
return 0;
}
}
I can't figure out what the problem is. Is it that I need to create a header file from the mydll.bi file, but I guess thats what I'm effectively doing by declaring AddNumbers at the beginning of the C prgram. Please help.
thanks
gaurav
In my project, I need to write C/C++ program that'll call routines implemented by someone else in FB, since static libs and dlls can be created using FB. As a beginner trying to take the first step, I created the sample mydll.dll using fbc (fbc -dll mydll.bas) and am now trying to call the AddNumbers sub from my C code in VC++ on a windows system. VC++ cannot resolve AddNumbers even though I'm linking it with the mydll import library. To make sure that its not a naming convention issue, I tried renaming libmydll.dll.a to mydll.lib. VC++ will still not link it, giving me the error "error LNK2001: unresolved external symbol _AddNumbers".
Here's my C program that I'm using to test calling VB Subs from C code:
#include <stdio.h>
extern "C" {
int AddNumbers(int a, int b);
int main(int argc, char* argv[])
{
int a = 5;
int b = 7;
int sum = 0;
sum = AddNumbers(a, b);
printf("AddNumbers returned the sum = %d\n", sum);
return 0;
}
}
I can't figure out what the problem is. Is it that I need to create a header file from the mydll.bi file, but I guess thats what I'm effectively doing by declaring AddNumbers at the beginning of the C prgram. Please help.
thanks
gaurav