GorillaApe
GorillaApe

Reputation: 3641

Cannot link to a library no way...VS 2010 lib

I can successfuly build and use a library. The later only if both the library and the other project is in the same solution....
I copied the isam.lib isam.dll isam.exp isam.h under a folder called lib...

Then i created a new solution..

Set linker -> Input to use my isam.lib ... Building fails, cant find that file...
Set VC++ Directories Include Directories and Library Directories to the lib folder...

Build is successful..

Also i set path for C/C++ General Additional include Directories
Set Linker General Additional library directories

Build is ok....

Then i include my isam file..

    #include "stdafx.h"
#include <isam.h>

    int _tmain(int argc, _TCHAR* argv[])
    {
        isopen("lamogio",2);
        return 0;
    }

Building fails...

Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl isopen(char const *,int)" (_imp?isopen@@YAHPBDH@Z) referenced in function _wmain C:\Users\Parhs\documents\visual studio 2010\Projects\testdll2\testdll2\testdll2.obj testdll2

Error 2 error LNK1120: 1 unresolved externals C:\Users\Parhs\documents\visual studio 2010\Projects\testdll2\Debug\testdll2.exe 1 1 testdll2

Upvotes: 2

Views: 667

Answers (1)

Hans Passant
Hans Passant

Reputation: 941218

Well, let's assume you told the linker to link to isam.lib with the Linker, Input, Additional Dependencies setting. Then the possible cause of the linker error is that you wrote the isam code in C and you are using it in a C++ program. You have to tell the compiler that the code was written in C:

#include "stdafx.h"
extern "C" {
    #include <isam.h>
}

The more typical solution is to put that in the isam.h file so that it is usable either way. Like this:

#ifdef __cplusplus
  extern "C" {
#endif

// The declarations
//...

#ifdef __cplusplus
}
#endif

Upvotes: 3

Related Questions