Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
}




........................................................................................
Posted
Updated 5-Apr-13 7:58am
v2
Comments
RedDk 5-Apr-13 14:16pm    
Offhand this error usually means te linker can't find the library to which you're attempting the link. There's a place in the VS interface to include path. Try Properties ... Since 2005, the location of this has changed so I could be all wet by now.

Might also try addding a /VERBOSE to the linker output. It's a switch. And it often grinds out information that, during compile and link, shows up in the output window; lists the "places" that the linker has searched for references to the "mangled" name (all that "@XYZ blurryjunk).
chandanadhikari 7-Apr-13 2:02am    
hi,
the linker is unable to find definition of twicenum so please check that in your cpp file you have included the header file which has definition of twicenum.

1 solution

I had the same problem once. This might help :
I have a linker problem when compiling my Win32 project written in C.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900