I already included Rpc.h, but I am still receiving error LNK2019: unresolved external symbol __im__RpcServerListen#12 referenced in function _main. Is there anything else I need to do to be able to call this function?
It's not enough to include the header file, that just tells the compiler about the types, functions and so on, that you want to use.
You also have to link with the relevant object files or libraries since they contain the actual code that you will be calling. You can tell this because the error starts with LNK, meaning you have a linker issue rather than a compiler one.
The actual files that you need to link to should be specified for the linking phase. For Windows RPC, this appears to be rpcrt4.lib (see here).
Related
I have researched more into the problem and posted a more detailed question with my findings here: Rust, how to use global variable from DLL? C++ equivalent requires __declspec(dllimport)
Original question:
Summary:
When linking my project with MSVC 2019's link.exe, I am getting errors such as unresolved external symbol jl_module_type. These symbols are defined in a file julia.lib, which I have verified using dumpbin /exports julia.lib. This file is passed as an argument to link.exe, and yet, it still complains about unresolved symbols. It looks like all the symbols that failed to be linked are variables rather than functions.
More information:
julia.lib has been renamed from libjulia.dll.a, and it corresponds to another file libjulia.dll. They were built with Cygwin/MinGW, but AFAIK this should not affect things. The actual project this is being used in is written in Rust, so link.exe is being invoked automatically by Rust's cargo tool. It is configured to build my project as a DLL.
I am trying to link against a dll, which is accompanied by a header file. Since there were no *.lib file available, I made one by manually creating a *.def file (Ref)
Now the problem is, my test program is __cdecl and the methods in the dll are __stdcall.
Is there a way to force __stdcall for specific methods when they are dynamically linked?
Even though its not an option, tried changing the calling convention (/Gd) to /Gz, but the name mangling came up saying the linker failed to find the slightly mangled method as shown below.
LNK2019 unresolved external symbol _TSTInitialize#24 referenced in function
The function signature in header file is,
#define TSTPERC_API /*__declspec( dllimport ) __stdcall */
TSTHandle cOpts;
//call native methods
TSTFunctionResult cResult = ::TSTInitialize(
p_strPathToLib.c_str(), p_strConfigStruct.c_str(), p_strLic.c_str(),
p_strRFU1.c_str(), p_strRFU2.c_str(), &cOpts );
Well, you don't force stdcall on methods with incorrect .def or incorrect .lib files.
The #24 in this case is the bytes on the stack the callee needs to cleanup. So there is no way around stripping it off (in case you do, then there is no way for the callee to know how many bytes to cleanup from the stack!! ).
The real problem was with the *.def file I created. The syntax is the other way around in my comment to #hans-passant,
TSTInitialize#24=TSTInitialize
This will make the correct export symbol, _TSTInitialize#24 in the lib file linker is looking for. This helps reverting the program to use /Gd instead of /Gz
I have a tlb files that contains some function declaration that I need to use.
If I use
#import "type_library.tlb"
I can correclty reference the function from my code:
tlb_namespace::required_function();
But when I compile the project the linker says that tlb_namespace::required_function is an unresolved external symbol.
How can I succesfully build this kind of project?
EDIT:
I have used the same type library in a Dummy VBA access project. I have added the reference to the type library and I have noticed that some of the function contained in the type library are correctly called. But some of them are not. VBA says It can't locate their entry point in the related dll.
Can this explain the unresolved external symbol when building c++ app?
I have also noticed that the failing function are declared in the tlb like this:
UPPER_function_name
but in the dll are declared like this:
Upper_function_name
Can this be the issue?
Is it possible to solve this kind of error directly modifying the binary tlb file or dll?
Use IDE to view TLB information.
Use this help : How to: View Type Library Information
At IDE : View-> Object Browser, click "..." Edit Custom Component Set, browse your TLB file and Add to view information.
Confirm namespace used for.
use the namespace to resolve the linker error:
example:
#import "<>" raw_interfaces_only
using namespace <>
this will resolve the problem
I'm using a library to generate multimodal optimization functions using VS2010. I include the header file of the library and tell VS where the library directory is; however, there is no *.lib file that comes with it, just source files and header files, so I can't point VS to "Additional Library Directories".
If I just include the header file and run my code it works fine. If I call any method from that library I get the LNK2019 error:
error LNK2019: unresolved external symbol "void __cdecl g_initialize(char *)" (?g_initialize##YAXPEAD#Z) referenced in function main".
I looked around and everyone is saying I should link the library, but I don't have a library file to begin with. What should I do??
Regards,
There're 2 ways if you have implementation of those header files.
1) You can add it to you project.
2) To compile library yourself, and you will get *.lib files. After this add it to you project.
Read documentation of this library how to use it.
Also you can check if there's implementation methods/functions which declared in header files.
I needed help making sense out of the following LNK error which i am getting.
SwitchFunctions error LNK2019: unresolved external symbol "__declspec(dllimport) ??$?8DU?$char_traits#D#std##V?$allocator#D#1##std##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##0#PBD#Z" (__imp_??$?8DU?$char_traits#D#std##V?$allocator#D#1##std##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##0#PBD#Z) referenced in function "??$find#Viterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##std##PBD#std##YA?AViterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##0#V120#0ABQBD#Z" (??$find#Viterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##std##PBD#std##YA?AViterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##0#V120#0ABQBD#Z)
Have you checked whether you have included all necessary dlls or lib files in your project settings?
Such an error usually indicate that you have used a function which definition is found, but implementation is not. Usually in the case of external libraries, the implementation is inside a dll or a static lib. Failure to provide the dll or the static lib will cause the linking to fail.
Which version of Visual Studio are you using? This might be relevant for VS2005:
Link error using a CString derived class from a DLL