-1

I am trying to access the .lib file using visual studio 2012. below are the steps I followed

  1. Created a class library, and included header(.hpp) and .lib file

    Header file :- extern "C" unsigned int GetKey();

    Class library

    public: static unsigned int GetKey1() { return GetKey(); }

  2. Built the application and it is successful, lets call it as classlibrary

  3. Created a win 32 console application and added the above dll as reference, tried to access the method in dll, built got succeed, but when i tried to run it , it showing file not found exception in classlibrary.dll or its dependencies like below.

Source file

using namespace ManagedMathFuncsLib;

int main()
{

   Class1 cs;

   cout<<"default value of variable from dll : "<< cs.GetKey1()<<endl;

   return 0;
}

Error An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.

Additional information: Could not load file or assembly 'XXXXXXX.dll' or one of its dependencies. The specified module could not be found.

If there is a handler for this exception, the program may be safely continued.

         **Do i need the dll related to .lib file? Please help.**
Jim Mischel
  • 131,090
  • 20
  • 188
  • 351

1 Answers1

0
  1. You have no lib file. This seams to be a managed assembly with .NET.
  2. A static function inside a class cannot be referenced as a function with extern "C" linkage.
  3. Libs are included into a project in defining them as an input file, or you add them to the linker options.

If you want to create a static C/C++ library (.lib) without a DLL.

  1. Launch the project Wizard
  2. Select Win32 projects
  3. In the Wizard select "Static library"

With such a static lib, you just need a header file and the lib to include it into another project.

There is no when you use a static lib.

PS: You should create a static libs for Debug and Release mode. Also you need to take care about the switches that control how the CRT is used inside the Lib. This Compiler switches should be identical in the lib and in the project were you use the lib.

xMRi
  • 14,982
  • 3
  • 26
  • 59
  • I have a lib file with header file. COde of the header file i posted above. The Class library code is the one which i wrote to access the methods in lib file.. have a .lib file, that is a static library and a header file.. Now how to access the methods inside – prasanna kumar Nov 20 '14 at 09:11
  • As I wrote. A managed routine in C++/CLI can never be accesses via extern "C". Show us code of your lib. AFAIK static libraries are no intended to be used with C++/CLI. Also you error message shows that the linker didn't resolved any external linkage from the lib. The application is "linked to" the .Net assembly. – xMRi Nov 20 '14 at 10:19
  • THanks for you reply ..i dont have the .lib code.. This is the 3 rd party .lib and .hpp file. i tried to access it through win 32 console application but its also showing "The program can't start because XXXX.dll is missing from your computer." – prasanna kumar Nov 20 '14 at 11:32
  • Than this third party lib is not a static library. You need the corresponding DLL for it. – xMRi Nov 21 '14 at 15:57