Visual Studio Building static lib gets unresolved external symbol - c

I am statically building LibSSH on Windows and managed to build it with cmake-gui. If I build the resulting Visual Studio project, I get the ssh.lib file. However, if I link this .lib file to another project where I need it, I receive following errors:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _BN_bn2hex referenced in function _ssh_print_bignum Project1 C:\Users\User\Desktop\Project1\Project1\ssh.lib(bignum.obj) 1
Error LNK2019 unresolved external symbol _DH_new referenced in function _ssh_dh_set_parameters Project1 C:\Users\User\Desktop\Project1\Project1\ssh.lib(dh_crypto.obj) 1
Error LNK2019 unresolved external symbol _DH_free referenced in function _ssh_dh_cleanup Project1 C:\Users\User\Desktop\Project1\Project1\ssh.lib(dh_crypto.obj) 1
And like ~250 more of these.
I found these object files on my system in another directory of the LibSSH project, but don't know what to do with these.
Can anybody help me with this problem?

Related

Cannot solve LNK 2001 error in Visual Studio

I am working on a very big project, some hundred of .c and .h files, so I just cannot upload them here. I am running the Release in Visual Studio.
I am getting these errors:
Severity Code Description Project Path File Line Source Suppression State Tool
Error LNK2001 unresolved external symbol _drawExitSurface raytrace C:\Users\Winter\Desktop\Newfolder C:\Users\Winter\Desktop\Newfolder\ray-main.obj 1 Build Link
Severity Code Description Project Path File Line Source Suppression State Tool
Error LNK2001 unresolved external symbol _calcDampingandImpulseResponse raytrace C:\Users\Winter\Desktop\Newfolder C:\Users\Winter\Desktop\Newfolder\ray-main.obj 1 Build Link
And others, as shown in the picture below:
I found that that the ray-main.obj, Raytrace-SINGLE.obj and Raytrace-STRAYL.obj are in Release folder, so I did this: search them down in the solution explorer, right click and click Include in Project. Also, in the Property->Linker-> Input-> Additional Dependencies, I included the paths to the mentioned obj files.
Can anyone please help?
Thank you!
The error unresolved external symbol _drawExitSurface means that you forgot to link the obj or lib file which contain the symbol _drawExitSurface. Or you forgot to compile the source that include the symbol.

Why am I getting Error LNK2019 unresolved external symbol when calling a function which is statically linked?

I've built a statically linked library from a project which I downloaded from here InfinityHook project
I'm getting the following two (2) errors in Visual Studio 2017 when I reference any of the functions which are available for export.
Error LNK2019 unresolved external symbol IfhInitialize referenced
in function
DriverEntry HelloWorld_Driver C:\Users\MYSELF\Documents\Visual Studio
2017\Projects\HelloWorld_Driver\HelloWorld_Driver\Driver.obj
Error LNK1120 1 unresolved externals
HelloWorld_Driver C:\Users\MYSELF\Documents\Visual Studio
2017\Projects\HelloWorld_Driver\x64\Debug\HelloWorld_Driver.sys
I get the same type of error when I reference another function from the same infinityhook.h header file and which is statically built in the libinfinityhook.lib file. So basically none of the functions that are "exported" are available to be called and are giving linking errors when referenced from the main project. Before arriving at this conclusion I tried several possible solutions found on StackOverflow but none of them have worked. I've added the statically linked file libinfiinityhook.lib in Visual Studio 2017 Configuration Properties->Linker->Input->Additional Dependencies and the file is located in the correct directory on disk so the linker can find it. But I also added the directory path to this library file to the following settings in VS2017 Configuration Properties->Linker->General->Additional Library Directories.
If anyone else is having the same issue the problem was that I was calling the two C++ defined functions, declared as C++ functions from a "C" based module. Recompiled the static library with the keyword extern and all is working as it should.

Windows SDK issue linking 64-bit exe on Windows 7

I have an exe written in C (not C++ or C#) to call a dll. It compiles with Clang and I'm linking it from the Visual Studio command line using link.exe. This build is on Windows 7. My command string is:
link.exe SxSv.obj /nologo /subsystem:console /MACHINE:X64 /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64\" /OUT:SxSv.exe kernel32.lib
Link.exe gives me these errors:
SxSv.obj : error LNK2019: unresolved external symbol __imp_LoadLibraryA referenced in function WinMain
SxSv.obj : error LNK2019: unresolved external symbol __imp_GetProcAddress referenced in function WinMain
SxSv.obj : error LNK2019: unresolved external symbol __imp_FreeLibrary referenced in function WinMain
SxSv.obj : error LNK2019: unresolved external symbol __stdio_common_vsprintf referenced in function _vsnprintf_l
LINK : error LNK2001: unresolved external symbol mainCRTStartup
C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x86\uuid.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
SxSv.exe : fatal error LNK1120: 5 unresolved externals
The problem seems to be this line:
/LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64\"
and I think the problem is the Windows SDK that is installed. This computer has Visual Studio 2017 CE installed.
My questions are:
It looks like there is only one SDK for Windows 7, released in 2010. Where would I expect to see it if it is installed?
Can I use it to link a 64-bit exe?
3, There are a lot of uuid.lib files installed on this Windows 7 box. Which one would I use for Windows 7 for a 64-bit exe?⌈
I am doing this from the Visual Studio Developer command line, not from the IDE.
Thanks for any help.
EDIT: the question suggested as the duplicate of this one is very helpful but it's not the complete solution to this problem as it does not explain what libraries to link to. The comment below by Hans Passant helps best. First I will transfer this project to Visual Studio and go from there to find the right libraries to link this to.

C - Unable to use MSVC linker to link .obj files from the command line

I have been trying to follow the instructions at http://llvm.org/docs/GettingStartedVS.html#an-example-using-the-llvm-tool-chain, but I run into errors at the linking stage. For some reason, I can compile the "hello world" program all the way to an .exe inside the Visual Studio GUI, but when I run the compiler (either clang or cl) from the command line, I get strange errors. I can create .obj objects just fine, but linking produces errors like the following:
link /DEFAULTLIB:libcmt /VERBOSE hello.obj
Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation. All rights reserved.
Starting pass 1
Searching libraries
Searching C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\libcmt.lib:
Finished searching libraries
Finished pass 1
Unused libraries:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\libcmt.lib
hello.obj : error LNK2019: unresolved external symbol printf referenced in function main
LINK : error LNK2001: unresolved external symbol mainCRTStartup
hello.exe : fatal error LNK1120: 2 unresolved externals
For some reason, it is ignoring the specified library and is unable to locate the relevant libraries for linking. How can I get the linker to resolve the symbols properly?

Getting linking errors when running C project in VS 2010 Professional on Windows

I am getting errors of the following type :
1>authenticate.obj : error LNK2001: unresolved external symbol _ldap_first_attribute#12
1>authenticate.obj : error LNK2001: unresolved external symbol _ldap_first_attribute#12
1>authenticate.obj : error LNK2001: unresolved external symbol _ldap_value_free#4
1>authenticate.obj : error LNK2001: unresolved external symbol _ldap_err2string#4
I have already added the header file folder to Project -> Properties->C/C++->General->Additional Include Directories.
Any ideas
This is a linker error. You need to provide the library where the _ldap_first_attribute and other functions listed can be found. This can be either a .lib static library or a .dll dynamic library
If this refers to this function then you have to add Wldap32.lib to Linker->Input->Additional Dependencies
edit:
if this is a external library, you don't have the lib and cannot rebuild the library yourself you can either create one or use explicit linking
You are missing LDAP lib.Try to configure your project correctly which points to include folder where LDAP.lib is present.
Linker --> Input --> Additional Dependencies will surely help.

Resources