How to add a static library (.lib) to Visual Studio ?
-
Dienstag, 23. Juni 2009 08:32Hi.
I have a static library comipled in C and I want to add this libarry which is static (.lib) into my exsiting project.
The libraryu has two external functions that I need to call in order to do a task in the solution.
Can you please tell me what step I need to take to add this library in Visual Studio 2008?!
Thanks
Alle Antworten
-
Dienstag, 23. Juni 2009 09:41
reference the library headers in Project Properties->C/C++->General->Additional Include Directories
reference the .lib in Project Properties->Linker->Input
see http://msdn.microsoft.com/en-us/library/ba1z7822.aspx for more details
hope this helps- Als Antwort markiert yade Dienstag, 23. Juni 2009 13:46
-
Mittwoch, 24. Juni 2009 11:56
Hi !
I added the library just the way they should be. I have a problem now :
8>WiiRemoteThread.obj : error LNK2019: unresolved external symbol "void __cdecl GetPosePosOrient(struct Mat_t *,struct rigid_t *)" (?GetPosePosOrient@@YAXPAUMat_t@@PAUrigid_t@@@Z) referenced in function "void __cdecl handle_event(struct wiimote_t *)" (?handle_event@@YAXPAUwiimote_t@@@Z)
8>WiiRemoteThread.obj : error LNK2019: unresolved external symbol "void __cdecl InitPoseEst(double,double * const,double * const)" (?InitPoseEst@@YAXNQAN0@Z) referenced in function "unsigned int __cdecl WiiRemoteThread(void *)" (?WiiRemoteThread@@YAIPAX@Z)
In the beginning the linker complained about that it could not find the library. When I fixed that I got the above errors.
The functions listed there are the functions inside the library and the linker seems not to be able to have access to them.
I am not sure if the library is not loaded properly or there are other reasons for that?!!
I use the exact function implementation as I have in library.
% function declaration in the lib file and in my c file
void InitPoseEst(double focal,double din[],double r0in[]); void GetPosePosOrient(Mat_t* pPin,rigid_t* prigid);
-
Mittwoch, 24. Juni 2009 12:13
Quote>I have a static library comipled in C
You are trying to use it in a program compiled as C++. You need extern "C" on
the prototypes in your source code:
#ifdef __cplusplus
extern "C" {
#endif
void InitPoseEst(double focal,double din[],double r0in[]);
void GetPosePosOrient(Mat_t* pPin,rigid_t* prigid);
#ifdef __cplusplus
}
#endif
- Wayne- Als Antwort markiert yade Mittwoch, 24. Juni 2009 12:31
-
Mittwoch, 24. Juni 2009 12:31Great ! Exactly that solved the problem. Ah I chekced everything except this.
thanks alot -
Dienstag, 21. August 2012 06:13
hi yade
can you plz show me how did you implement this extern "C" in your code..
thanks
-
Donnerstag, 27. September 2012 06:06whoaa!!! i have done it!!!

