0

I using Visual Studio 2019 with the latest FrameMaker Development Kit, creating plugins with C++. I can build the sample programs from the FDK so the environment setup is fine. Now I want to use functions from a DLL that already exists in the FrameMaker package. I inspected the DLL and all the functions I am calling from my code do exist in it.

I have the header files for the DLL, so the compiler is able to create the code. But I am unable to get the linker to integrate the existing DLL. In the error messages it shows that every reference to a function in the DLL is prepended with '__imp _'. Obviously, these renamed functions do not exist, so I cannot get a successful build.

Is there a setting I need to change in Visual Studio so that the function names are kept as they are? I tried to add the folder that contains the existing DLL to the Additional Library Directories but as long as the function names get mangled there is no way this is going to work.

4everJang
  • 321
  • 2
  • 12
  • Not sure but undefined reference errors usually mean libraries not linked properly or missing headers. – kiner_shah Nov 17 '21 at 11:41
  • 1
    When creating a DLL there are actually *two* files created: First the actual DLL itself, but then also a static library (`.lib`) which contains *import* functions. These are the `__imp` functions you see, and you must *link* with this library if you want to use the DLL. – Some programmer dude Nov 17 '21 at 11:42
  • Does this answer your question? [How to make a .lib file when have a .dll file and a header file](https://stackoverflow.com/questions/9360280/how-to-make-a-lib-file-when-have-a-dll-file-and-a-header-file) – user253751 Nov 17 '21 at 11:48
  • @user253751 - thanks for that pointer. I will check out if that is going to work for me. – 4everJang Nov 17 '21 at 12:01
  • I have now created a .lib file from my .dll but the linker error is the same: all function names from the DLL are prepended with "___imp_ " which causes them to be unresolved. Which setting prevents this in Visual Studio ? – 4everJang Nov 17 '21 at 13:28
  • Have you added the lib file as dependency? It will be better to tell us the type of error, such as Lnk2019. – Minxin Yu - MSFT Nov 18 '21 at 06:43
  • @Minxin Yu - It is LNK2019. I did add the header files to the source code. In the external dependencies of the original code (which worked) there are only header files. I also added the directory for the DLL and LIB to the library locations. Do I need to add a dependency to the .lib file explicitly? And where is that done? – 4everJang Nov 18 '21 at 09:37
  • Configuration Properties > Linker > Input->Additional Dependencies. – Minxin Yu - MSFT Nov 18 '21 at 09:40
  • I tried explicitly adding the reference to the lib file but I am getting the same error. It looks like maybe the compiler adds the _ _ _imp_ _ to the function call references so that they can never be found in the lib. But I don't know if there is a way to prevent this renaming from happening. – 4everJang Nov 18 '21 at 09:46
  • I finally figured out what the real problem was: I needed to explicitly name the lib file as Additional Dependencies for the linker input. If only the LNK2019 error description would hint at such a possiblity it would save newbies a lot of frustration and time. – 4everJang Nov 18 '21 at 18:36

0 Answers0