I have just started to try to create my own library of functions in c++, using vs2008 express.
I know this is probably a simple problem to the experts out there but I started with a simple test example to see if I could manage.
I have put the paths to my include and library files into the ide compiler.
Any advice on what I have done wrong will be appreciated. Thanks in advance
I have included the code if this helps: (For some reason the submitted question has omitted #include <iostream>)
This is the error message:
1>functest.obj : error LNK2019: unresolved external symbol "int __cdecl twicenum(int)" (?twicenum@@YAHH@Z) referenced in function _main
1>C:\Users\Bill\Documents\Visual Studio 2008\New folder\testfunclib\Debug\testfunclib.exe : fatal error LNK1120: 1 unresolved externals
code for main (1), header (2) and function definition (3) modules follows:
................................................................................................(1)...
//main prg is called testfunclib
..........
#include <iostream>
#include "myfunclib.h"
using namespace std;
int main()
{
int b=twicenum(4);
cout<<b;
}
.....(2)....................................................................................
Header File myfunclib.h
//… Namespaces, variables, and function prototypes go here
/*You have to put extern before your prototyped function you want to use in your library*/
extern int twicenum(int);
(3).............................................................................................
function definition twicenum.cpp
#include "myfunclib.h"
#include <iostream>
using namespace std;
int twicenum(int x);
{
int res;
res=x*2;
cout<<res;
return (res);
}
........................................................................................