CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2008
    Posts
    163

    DLL Creation and Linking Issue

    Hi,

    I am using VS 2005. First I create .lib project and prepare one application project. Both are running fine.

    Then i change the .lib project in to .dll project. It compiles fine but when i compile the application project it shows one issue [fatal error LNK1104 :: can not open the lib file]. My question is how i will link to .dll file correctly. Please give me the settings change for application project.

    Thanks
    Dave

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: DLL Creation and Linking Issue

    You still need .lib file for linking - add it to the list of linker dependencies. .lib file in this case is used as "proxy" which helps to open dll at runtime.
    Without .lib file, you can use LoadLibrary/GetProcAddress.

  3. #3
    Join Date
    Apr 2008
    Posts
    163

    Re: DLL Creation and Linking Issue

    Thanks for the replay, but it does not solve my problem.

    I have a dll project. Successfully creates the dll.

    I would like to create one application project using this dll.

    But i face the error as follows

    "fatal error LNK1104: cannot open file abc.lib"

    In this context i don't want .lib but why the application asks for .lib.

    So my question is what change i imposed in to my application project

    Thanks
    Dave

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    Re: DLL Creation and Linking Issue

    If you don't want .lib, exclude it from the linker list, and use LoadLibrary/GetProcAddress.
    If you want .lib, add it to the linker list and ensure that linker can find it (by providing full path, or adding .lib path to the list of linker directories, or by placing .lib file to the project directory.

    See Project - Properties - Configuration Properties - Linker.
    General - Additional Library Directories. Here you can add the path where abc.libfile is placed.
    Input - Additional Dependencies. Type abc.lib here.

  5. #5
    Join Date
    Apr 2008
    Posts
    163

    Re: DLL Creation and Linking Issue

    Hi,

    I am ok with .lib settings and my project is working in static library.

    But i want to create my application project using .dll.[Only the main and caller function in wrapper]

    I am preparing one dll

    Application project is also ready.

    I have .dll file and application project. Now i face an issue when the functions which def:: is present in dll is called then error has come.

    It means that my application does not read the .dll

    So how i achieve the .dll read from my win32 console application project

    what are the settings change needs in the VS 2005 editor

    Thanks
    Dave

  6. #6
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: DLL Creation and Linking Issue

    Even if you want to use a DLL at runtime, the linker still has to know where to find the functions in the DLL. Thus the corresponding .lib file is needed. That does not mean your app is statically linked with the .lib, the app is just "prepared" to use the DLL.

    HTH,
    Richard

  7. #7
    Join Date
    Apr 2008
    Posts
    163

    Re: DLL Creation and Linking Issue

    Still I have problem

    In My DLL project i build the function using the following way
    Code:
    extern "C" __declspec(dllexport) double AddNumbers(double a, double b)
    {
        return a + b;
    }
    DLL created successfully.
    Then close the project.

    I am creating an Application project. and the code is in this way
    Code:
    #include <windows.h>
    #include <stdio.h>
     
    // Import function that adds two numbers
    extern "C" __declspec(dllimport) double AddNumbers(double a, double b);
     
    int main(int argc, char *argv[])
    {
        double result = AddNumbers(1, 2);
        printf("The result was: %f\n", result);
        return 0;
    }
    but it showing the following errors

    1. error C2059: syntax error : 'string'
    2. error LNK2019: unresolved external symbol _AddNumbers referenced in function _main

    I placed my created dll in the Debug Folder [where the .exe is generated]

    Please help me to solve the issue.

    I am not using any MFC classes.

    Thanks
    Dave

  8. #8
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: DLL Creation and Linking Issue

    As Alex F already stated, add the .lib to the additional libraries in the Linker settings.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured