-
February 10th, 2021, 01:24 PM
#1
[RESOLVED] using a dll without the .lib file
I have a dll that I want to use in Visual C++ but I don't have the library file for it (.lib). When I try to compile I get "Error 2 error LNK1120: 1 unresolved externals"
Is there any way to use dllimport for this, like I can with C#? Or some other workaround? I have the header with the function prototypes.
TIA
-
February 10th, 2021, 02:17 PM
#2
Re: using a dll without the .lib file
Did you try using GetProcAddress?
Victor Nijegorodov
-
February 11th, 2021, 04:23 AM
#3
Re: using a dll without the .lib file
Just generate the .lib file from the .dll. See https://stackoverflow.com/questions/...ile-from-a-dll See the .bat file(s) that automate this process.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 11th, 2021, 03:30 PM
#4
Re: using a dll without the .lib file
Originally Posted by 2kaud
Thanks for that. So I used the batch file scripts from there and created a .lib file. I added that to my project under the linker's additional dependencies. But when I try to build the project I get unresolved external symbol errors for the DLL functions that I'm calling. Doesn't the lib file tell the compiler to use the DLL? Or do I need to do something else?
-
February 11th, 2021, 03:55 PM
#5
Re: using a dll without the .lib file
Well, did you try LoadLibrary/GetProcAddress?
And there is another interesting resource: https://www.xspdf.com/resolution/2263630.html
Victor Nijegorodov
-
February 12th, 2021, 04:30 AM
#6
Re: using a dll without the .lib file
Are you compiling as C or C++? If as C++, are the function declarations for the dll functions specified as extern "C" (capital C) to avoid name 'mangling'? See https://stackoverflow.com/questions/...-extern-c-in-c
Are you linking dynamically or statically?
Last edited by 2kaud; February 12th, 2021 at 04:33 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 12th, 2021, 11:12 AM
#7
Re: using a dll without the .lib file
Originally Posted by VictorN
I haven't tried that yet. If I can't get the .lib to work, I'll go that route. Thanks for the reference.
-
February 12th, 2021, 11:18 AM
#8
Re: using a dll without the .lib file
Originally Posted by 2kaud
Dynamic linking. The DLL is in the same directory as the .exe (debug). The header file for the dll definitions has the extern "C" -
#ifdef __cplusplus
extern "C" {
#endif
A typical function prototype looks like this:
void __cdecl C_2p_nominal(double z[], double theta[], double cc[],
int32_t C_fpp, int32_t C_out_hex[], double C_out[], int32_t n_samples,
int32_t n_cc);
[Are there CODE tags in this forum?]
Thanks for the help
-
February 12th, 2021, 11:53 AM
#9
Re: using a dll without the .lib file
Originally Posted by Dave C
[Are there CODE tags in this forum?]
Yes, of course! See https://forums.codeguru.com/misc.php?do=bbcode#code
Victor Nijegorodov
-
February 12th, 2021, 12:02 PM
#10
Re: using a dll without the .lib file
I get unresolved external symbol errors for the DLL functions that I'm calling.
What's an example of the external symbol that can't be found - and what is called in the .dll?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 12th, 2021, 03:06 PM
#11
Re: using a dll without the .lib file
Originally Posted by VictorN
OK, I did that and it worked. Thank you.
-
February 13th, 2021, 03:29 AM
#12
Re: using a dll without the .lib file
Originally Posted by Dave C
OK, I did that and it worked. Thank you.
You are welcome!
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|