Win32 error LNK2019: unresolved external symbol - winapi

I'm currently trying to learn WinSock coding from http://johnnie.jerrata.com/winsocktutorial/ however when I compile my listening socket, I get 9 error LNK2019: unresolved external symbol errors. They all look to be the same function names that are used in the code prefixed with an underscore after the function name it says referenced in function _WinMain#16
This also happens when I run the code example that is available for download, so I don't think I've made a mistake.
What is an unresolved external and how do I go about fixing one? I can post the code if needed but it's all visibile on that link. I'm using Visual Studios 2010, Win32 project.

Unresolved external is linker error, telling you that you didn't link symbols you are getting those unresolved externals to into the binary.
Quoting from the site you linked:
Feel free to download the entire tutorial code listing. Remember that any code presented in this tutorial should be linked with the Winsock library, usually wsock32.lib or something similarly named. Also, when using code exactly as presented in the tutorial in your own IDE (Dev-C++, Microsoft VC++, C++ Builder, etc.), choose to build a Windows project with a WinMain() to avoid errors.
One of ways to link it is:
#pragma comment(lib, "wsock32.lib")
Also, consider using Boost.Asio instead of raw WinSock.

Related

can't build max/msp external with onnx-runtime, "LNK2019: unresolved external symbol..."

i am trying to write a max-external to do inference on an .onnx neural network on. i have followed several tutorials on certain steps but fail to combine them:
i managed to create a c++ console app in vs that loads my .onnx model and runs inference
(seting up vs-project and importing onnxruntime via nuget taken from here: https://levelup.gitconnected.com/onnxruntime-opencv-for-c-b19ef189d3a8)
i managed to setup a vs-project with cmake that builds a working max-external (.mxe64)
(https://github.com/Cycling74/min-devkit/blob/main/HowTo-NewObject.md)
when i import the onnxruntime nuget into the solution i created with cmake, i get linker errors as soon as i try to include the onnxruntime_cxx_api.h
mmm.hello-world.obj : error LNK2019: unresolved external symbol OrtGetApiBase referenced in function "void __cdecl `dynamic initializer for 'public: static struct OrtApi const * const Ort::Global<void>::api_''(void)" (??__E?api_#?$Global#X#Ort##2PEBUOrtApi##EB##YAXXZ) [C:\Users\misch\Documents\Max 8\Packages\mmm\source\projects\mmm.hello-world\mmm.hell o-world.vcxproj]
screenshot of error msgs
i'd guess that this is just an issue of a missing path/directory somewhere but i have honestly no idea where to start there... i tried comparing the project properties between the two working tutorial projects but couldn't spot any notable differences.
appreciate any help or pointers in the right direction.

vkCreateDebugReportCallback EXT not linking, but every other functions in vulkan.h works perfectly

So I have been trying to learn Vulkan lately, and while trying to get the validation layers to work, I got error LNK2019:
1>Renderer.obj : error LNK2019: unresolved external symbol vkCreateDebugReportCallbackEXT referenced in function "private: void __cdecl Renderer::_InitDebug(void)" (?_InitDebug#Renderer##AEAAXXZ)
Now the odd thing is that every other function in vulkan.h works perfectly.
I have vulkan-1.lib linked, and I run the AMD implementation of vulkan. The library is from the Vulkan SDK.
The debugging functions from debug_report_ext are not part of the Vulkan core. You need to dynamically load them from the instance via vkGetInstanceProcAddr after making sure that it's actually supported:
PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallback = VK_NULL_HANDLE;
CreateDebugReportCallback = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT");
See my Vulkan debugging helper unit for details.

Visual c++ unresolved external symbol _Direct3DCreate9#4

I have tried to find an answer for this for hours, and hours, and hours. This is frickin exhausting. In visual studio I keep having these library issues with DirectX and I think I have narrowed it down to a point where it is almost, almost solvable.
The error at compiling is in the title, here are images of some of my code and the dependencies and such:
Usually Unresolved External Symbol is thrown if you are using a function defined in a header, in your case I think d3d9.h, but you haven't linked the containing implementation lib. Right click on your project name under solution explorer and than Properties->Configuration Properties->Linker->Input, now on Additional Dependencies add your lib that I suppose it will be d3d9.lib or d3dx9.lib!

Old VS code not running with new VS

I have an old project that I need to revisit. It was built in some version of Visual C++ (prolly 2005) looking at the .sln file. The sln file wont get converted to a VS 2008 solution due to some corruption (dubug point -1). I imported the folder in VS as a new project and tried compiling.
It gave compilation errors for "lang/Typedefs.h/Assertions.h" not there. Removing the declarations I had errors for Uint8/16/32/64 not declared. So I added the typedefs and other macros (TOOLS_UNUSED_PARAMETERS(x) / TOOLS_FORBID_COPY()).
That being ironed out, I got errors for Gui/FileDlg.h and Gui/FolderDlg.h(debug point - 2).
I didnt find any of those header files from any resources online or in my current VS installation and so I am assuming that code is missing and I will have to redo it.
Even these could probably have been custom implemented by the earlier programmer. The current MFC uses CFileDialog and the code uses Gui::FileDlg.
I commented out the code for the time being to see where can I get to since gui is not that big a part of the application. Later I see linker errors corresponding to RegKeyOpenEx calls and outputstream calls(dubug point -3). Winreg.h was not included but windows.h was.
sample :
Error 2 error LNK2019: unresolved external symbol __imp__MessageBoxA#16
referenced in function "public: class std::basic_ostream<char,struct
std::char_traits<char> > * __thiscall FileManager::getOutputStream(class Interface
*,class LogPoint *)" (?getOutputStream#FileManager##QAEPAV?$basic_ostream#DU?
$char_traits#D#std###std##PAVInterface##PAVLogPoint###Z) filemanager.obj
PCAPGenerator
I am not a .Net programmer so can you please suggest what would be the right course of action here ?
which debug points should i be focussing on.
RegKeyOpenEx is a Winapi function defined in Advapi32.dll. To link that into a Visual C++ project:
If your project is a static library (right-click project->Properties->Configuration Properties->Configuration Type->Static Library (.lib), go to Configuration Properties->Librarian->General->Additional Dependencies and add Advapi32.lib.
If your project is a dll (same place, says Dynamic Library (.dll) instead), you'll have the Linker section instead of Librarian. Go to its Input subsection, and add Advapi32.lib to Additional Dependencies.
For your remaining linker errors, proceed in the same way: go to the MSDN doc for the function, check which dll/lib it belongs to and have your project link it in as described above.

Visual Studio Linking errors. Order in which MFC, CRT included?

This question has been brought up numerous times, but Visual Studio never ceases to challenge me.
We have an application that should be self-sufficient, i.e. not depend on any 3rd party libraries. This is why we build everything statically using the MT(d) code generation flags.
The app depends on Qt, zlib, OpenSSL and DCMTK. All of these libraries were built as static libs with MT(d). The app also uses some MFC-related code, so we also have to link against it.
MFC is included via
#include <afxwin.h>
I read somewhere that this should be the first include in every file, but I'm not sure if it is true. Anyway, the line is not included in every file, only one file includes it.
Here are the link-related errors:
Error 24 error LNK2005: "void __cdecl operator delete[](void *)" (??_V#YAXPAX#Z) already defined in LIBCMTD.lib(delete2.obj) uafxcwd.lib
Error 22 error LNK2005: "void __cdecl operator delete(void *)" (??3#YAXPAX#Z) already defined in LIBCMTD.lib(dbgdel.obj) uafxcwd.lib
Error 23 error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U#YAPAXI#Z) already defined in libcpmtd.lib(newaop.obj) uafxcwd.lib
Error 21 error LNK2005: "void * __cdecl operator new(unsigned int)" (??2#YAPAXI#Z) already defined in LIBCMTD.lib(new.obj) uafxcwd.lib
Here is the linker output.
I read many threads on many sites as well as this article from MSDN's KB. But they don't help me, as all of them keep saying that MFC libs should be linked before CRT, but I cannot find a way to alter the linking order.
Any help is greatly appreciated.
Edit 1:
Using the trick from this thread actually solves the problem, but I still want to know what's wrong here.
Edit 2:
Using Visual Studio 2008 SP1, on Windows 7 and Qt 4.6.3
The problem is clear: you are compiling CRT and MFC code together.
When you use the MFC libraries, you
must make sure that they are linked
before the CRT library is linked. You
can do this by making sure that every
file in your project includes
Msdev\Mfc\Include\Afx.h first, either
directly (#include ) or
indirectly (#include ). The
Afx.h include file forces the correct
order of the libraries, by using the directive:
#pragma comment (lib,"<libname>")
Microsoft has an article (link now gone, but check here) describing this problem and suggests 2 solutions step-by-step (the following steps are based on Visual C++ 6.0):
Solution One: Force Linker to Link Libraries in Correct Order
On the Project menu, click Settings.
In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
On the Link tab, click to select Input in the Category combo box.
In the Ignore libraries box, insert the library names (for example, Nafxcwd.lib;Libcmtd.lib).
Note: The linker command-line equivalent in /NOD:<library name>.
In the Object/library modules (VS2008: Properties->Configuration Properties->Linker->Input->Additional Dependencies)box, insert the library names. You must make sure that these are listed in order and as the first two libraries in the line (for example, Nafxcwd.lib Libcmtd.lib).
Solution Two: Locate and Correct the Problem Module
To view the current library link order, follow these steps:
On the Project menu, click Settings.
In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
On the Link tab, type /verbose:lib in the Project Options box.
Rebuild your project. The libraries will be listed in the output window during the linking process.
This was clarified to me on the MSDN Forumns:
http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/4e331cb3-e566-4ca6-b7d4-118c3bebd31a

Resources