0

I am trying to produce a dll from a static library + header file in order to make it as a plugin for another python project.

(https://github.com/muggot/myphone3/tree/master/h323plus/plugins/audio/VoiceAgeG729/va_g729)

But, I am getting linker errors which I can't figure the real reason behind them.

I tried the accepted answer in [1], but the librarian is not working ( unable to start correctly) so I couldn't make it.

Here is my code for the dll which will wrap one function as example

Win32Project2.h

#ifdef WIN32PROJECT2_EXPORTS
#define WIN32PROJECT2_API __declspec(dllexport)
#else
#define WIN32PROJECT2_API __declspec(dllimport)
#endif
#include <C:\Users\user name\Desktop\CELP/va_g729.h>
#pragma comment(lib, "va_g729.lib")

WIN32PROJECT2_API void fnWin32Project2(void);

dllmain.cpp

#include "stdafx.h"


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

Win32Project2.cpp

#include "stdafx.h"
#include "Win32Project2.h"
#include <C:\Users\user name\Desktop\CELP\va_g729.h>

// This is an example of an exported function.
WIN32PROJECT2_API void fnWin32Project2(void)
{
    return va_g729a_init_encoder(); // A function inside the .lib
}

I added the directory of the .h into project's properties->C/C++->general->Aditional include directories and added the lib path into linker->general->additional libraries directory Finally, added the .lib itself into linker->input->additional dependencies

but, I got the following linker errors: error LNK1120: 1 unresolved externals Error1 error LNK2001: unresolved external symbol "void __cdecl va_g729a_init_encoder(void)" (?va_g729a_init_encoder@@YAXXZ)

I understand that linker can't find the function, but why? did I mess something?


[1] How to import .lib into .dll?

Mohammed B.
  • 160
  • 1
  • 3
  • 13
  • 1
    In the dll you need to link to whatever library that implements `va_g729a_init_encoder()` – drescherjm Jul 16 '19 at 18:14
  • it is the library I added into the linker – Mohammed B. Jul 16 '19 at 18:23
  • why marked as duplicate? the duplicate question is talking generally about the error not fixing a specific case I faced and can't determine where is the problem. – Mohammed B. Jul 16 '19 at 18:28
  • The duplicate most likely covers your case. – drescherjm Jul 16 '19 at 18:29
  • ***it is the library I added into the linker*** The linker is saying that you did not do this step properly. Perhaps you added it for 1 configuration but not the other. Note that each configuration (debug / release ...) has independent settings. – drescherjm Jul 16 '19 at 18:31
  • What you are doing to make a `dll` looks correct. Make sure you define `WIN32PROJECT2_EXPORTS` when building the `dll` and don't define it when using the `dll`. However this has nothing to do with the linker error. – drescherjm Jul 16 '19 at 18:44

0 Answers0