I'm using Microsoft Visual Studio and an SDK to develop an app. The SDK includes the files listed above. I'm coding in C++. I'm not sure what I need to include to be able to use the SDK.
I did the things below and tried building a simple hello world app but I keep getting the error LNK2019: unresolved external symbol_WinMain#16 referenced in function __tmainCRTStartup
What I've Done:
1)Right Click-Properties-Linker-Additional Library Directories-Changed path to where I have the lib folder on my computer.
2)Same but added the Inc folder that came with the SDK to C/C++ Additional Include Directories.
By doing the above I assume I am linking the lib and .h files to the project that came with the SDK. The SDK also came with .dll files which I have done nothing with. You can use a few different languages with the SDK so I'm not sure what I need to use and not use.
However, the header files are not showing up under external dependencies.
I guess I should note that I have tried to run it a couple times before this and am not sure if that could be causing an issue building it.
Thanks.
The error you're seeing has nothing to do with header files or source code. The error is due to you not choosing the correct Visual Studio project.
If you are writing a console program, and you defined a main() function as the entry point, then you should be choosing a Win32 Console Application project from Visual Studio.
The error stems from the program looking for the WinMain function, and that function exists when you choose a Win32 Project. Usually these projects are for building GUI-based Win32 apps.
Related
I'm trying to create a native HoloLens 2 C++ application with OpenXR. In the Microsoft OpenXR-MixedReality example I discovered the XrSceneLib_uwp project which has the configuration type set as static library (.lib) in the Visual Studio properties. Accordingly to that I tried to add it as a library in my solution which also has a Core Application (C++/WinRT) in it where I want to use the functions from XrSceneLib_uwp. In my thinking it makes sens because I can use the library for example to create a holographic title scene without much effort. The problem here is that when I build my solution I'm getting linker errors and I don't know how to fix them. I'm also relatively new to Visual Studio (22 in my case) and most likely I'm just doing someting wrong in the linking process.
Linker error when I try to build:
Error LNK2019 unresolved external symbol xrGetInstanceProcAddr referenced in function "public: __cdecl `anonymous namespace'::ImplementXrApp::ImplementXrApp(struct engine::XrAppConfiguration)" (??0ImplementXrApp#?A0x934f03db##QEAA#UXrAppConfiguration#engine###Z) CoreApp3 \repos\CoreApp3\CoreApp3\XrSceneLib_uwp.lib(XrApp.obj) 1
My solution explorer
Here is what I do:
I copy and paste the shared and openxr_preview folders from the OpenXR-MixedReality .zip file in my project folder.
Add XrSceneLib_uwp.vcxproj in /shared/XrSceneLib as an existing project to my solution.
Add the path to the copied shared and openxr_preview folders in Properties->Configuration Properties->C/C++->General->Additional Include Directories.
Add also the path to XrSceneLib_uwp.vcxproj in Additional Include Directories in my main project (CoreApp).
Add reference in CoreApp to XrSceneLib_uwp (Add->Reference->Projects).
After that everything works fine and I can even build the solution. But when I try to use the library I'm getting these linker errors. I don't understand why it works in the OpenXR-MixedReality examples but not when I try to implement it on an different project. What am I missing? I assume that XrSceneLib may not have been designed to be used externally in other projects but at the same time I think it should be possible somehow.
I also tried to add Additional Library Directories and the missing object files but either I have done something wrong or it just simply does not work.
I really appreciate any help.
I think the linker is failing to find the OpenXR Loader. The sample projects in the microsoft/OpenXR-MixedReality github repo link to the OpenXR Loader using the NuGet package manager. I get the same linker error if I purposely remove the NuGet package references from the sample projects.
You can either link to the OpenXR Loader using NuGet or you can build the OpenXR Loader youself. Take a look at the "Using OpenXR in an existing project" section on the microsoft site:
https://learn.microsoft.com/en-us/windows/mixed-reality/develop/native/openxr-getting-started#using-openxr-in-an-existing-project
I have problems building my code that is using static lib detours. I am trying to do an old basic CTF. For that I want to get into detours.
Whenever I try to build my .dll file I get an issue
LNK2019 unresolved external symbol _DetourTransactionBegin#0 referenced in function _DllMain#12
Now, I have built the detours library using 3 different version of the visual studio dev console.
I have tried firing 'vcvars32.bat' and then using nmake to build the library which was able to build it, but I get the above error during linking my .dll. I have also tried building it with 'vcvarsamd64_x86.bat' and then using nmake to build it which also was able to build the library, but I still get the same error as above during linking.
I have tried the usual stuff: the include folder for detours.h is added to C++/General/Additional Include Directories.
Under Linker/Additional Library Directories I added them as follows: "C:\temp\det_retry\lib.X64";"C:\temp\det_retry\lib.X86";%(AdditionalLibraryDirectories).
And also under Linker/Input/Additional Dependencies I have the following: detours.lib;%(AdditionalDependencies)
What am I missing here? This is a blocker for me for a couple of days and I am reiterating the same steps trying to figure out what's missing but I cannot see. I'd really appreciate the input.
I am sure I am using the newest version because I have downloaded (cloned) detours from the ms github page.
It appears your "Additional Library Directories" are setup incorrectly or contain invalid entries rather. They look like actual library file entries (i.e. pointing to some specific files) versus being only directories (e.g. "my/lib/path/for/my_project/"). Visual Studio's naming conventions are somewhat cryptic but they should be directory entries only. There should be an entry to whatever directory contains the detours.lib file (e.g. "MyProject/Libs/MSDetour" ... where MSDetour is a folder with the "detours.lib" in it) and then Visual Studio should find the library and link everything correctly.
As a side note, if you are using the Visual Studio developer console for building your project/solution you might want to look into CMake ... it is, in my opinion, significantly easier to work with (less "settings" digging) and maintain in the long-run.
I'm using Visual Studio 2015. I always uncheck "Precompiled header" whenever I create a new project, but Visual Studio still creates the file and adds it to my project. I've tried just creating an empty project, but that also gets rid of the external dependencies, which I need for my projects.
I've tried searching the internet but couldn't find anything about this. Is there a way to prevent Visual Studio from generating stdafx.h but keep the rest of the core libraries at project creation?
Haven't used VS since 2010 but from what I recall you cant get rid of stdafx.h as thats the standard way VS makes a non-empty project for you (it might be just winapp projects, console projects did not have it in VS2010). It wants you to place all your includes into there. Your best bet is to create an empty project and manage the dependencies yourself. Its not too bad.
Just create an Empty Project.
The External Dependencies "folder" in the Solution Explorer will populate itself as you start including external dependencies.
When you create a Win32 Console Application, the External Dependencies will be prepopulated with a handful of headers at first; this is because the Win32 Console Application project includes a few source files that include external headers. When you create an Empty Project, the External Dependencies will be empty at first because there are no external dependencies yet.
Try creating an empty project and place your important libraries manually. I don't think you can start VS non-empty project without a header file.
So first I'll say I've looked in a ton of places to no success.
This PDF is where I started:
http://curl.haxx.se/libcurl/c/visual_studio.pdf
It seems outdated and does not include instructions for statically linking libraries. Or at least, I've tried following all of the instructions without any success.
I've tried following answers in
Installing LibCurl on Visual Studio 2010
error LNK2019: unresolved external symbol libcurl Visual studio
Building libcurl library in Visual Studio 2008
and other areas, but have not made any progress.
I will also say that I am NOT a Windows user by any stretch of the imagination. With that said I will lay out what I have done so far.
I am porting over an application I made in a Unix environment, specifically OSX. I've made a lot of progress with the exception of using libcurl. I need to statically link LibCurl so that the executable built by Visual Studio can be moved to other Windows devices as necessary without needing dlls for libcurl or MySQL (which I am also linking statically).
Anyway, with the gracious help of this repository:
https://github.com/blackrosezy/build-libcurl-windows
I was able to build libcurl onto my Windows device. This was a difficult process before I found this repository. Now I have a lib and an include folder. Inside the lib folder there are release and debug folders for dll and static builds each. Inside the static-release folder I have ONLY libcurl_a.lib. Inside the dll-release folder I have libcurl.dll, libcurl.lib, and libcurl.pdb.
I have gotten the program to SUCCESSFULLY build when dynamically linking from the dll-release folder. However, when I try to link statically from the static-release folder, I get 11 or so linker errors.
I have also included "libcurl_a.lib", "wldap32.lib", "ws2_32.lib", "winmm.lib", "libeay32.lib", and "ssleay32.lib" as dependencies.
In addition to all of this, I used NuGet to get libssh2.1.4.3.1, openssl.1.0.1.21, zlib.1.2.8.1 along with redist versions of all of these. I have included the following paths in my library directories as well:
path_to_libssh\build\native\lib\v110\Win32\Release\static\cdecl\<br>
path_to_openssl\build\native\lib\v110\Win32\Release\static\cdecl\<br>
path_to_zlib\build\native\lib\v110\Win32\Release\static\cdecl\<br>
I have also put the /include/ paths from these folders in my list of include directories.
In my preprocesser definitions I have "CURL_STATICLIB".
However, despite all of these steps that I have taken from multiple sources including some great answers on this site, and the PDFs and some answers on the LibCurl site, I am still having these linker errors.
As an example, one of the errors that I feel is slightly indicative (sorry I cannot copy and paste all of these errors from VS2013 that I can tell) says:
"error LNK2019: unresolved external symbol curl_easy_setopt referenced
in function 'public:__cdecl Curler::Curler(char*)'(??0Curler##QEAA#PEAD#Z)"
All of these errors are laid out similarly, pointing to some sort of __cdecl Curler function, with the error code LNK2019.
Anyway, my question is basically: what am I doing wrong? I am sorry if this is a vague question, or if you feel as though this is a repeat. But I can assure you that I have looked at a large list of Stack Overflow questions and other areas of the internet with no success, and I've begun to feel very lost. Things that seem to work for so many others I just cannot get to work. I think a large portion of the problem is my newness to Windows. If there is any other information that I can provide in order to help you help me, then I will gladly provide it. I really appreciate any help you can give me. Thanks.
First of all, thank you to user Pawan who edited my post; it was my first post and he helped make it up to standards aesthetically with the community so I know what to do in the future.
Anyway, I think I solved my problem. It's probably a bit of an edge case, but it worked for me anyway.
After a while, I decided to build libcurl for Win64 using Visual Studio. To do this, I grabbed the code from this helpful repository:
https://github.com/bagder/curl
I cloned it, and navigated to that directory. I then ran the following commands (this is in Powershell so I used unix-esque commands, but I did not use MinGW for this):
mkdir build
cd build
cmake .. -G "Visual Studio 12 2013 Win64"
This built a Visual Studio Solution that I could open in Visual Studio 2013. In Visual Studio, I went to
Project Properties -> C/C++ -> Code Generation
And switched the Runtime Library option to "Multi-threaded (/MT)"
Then I built the project, which outputted the following files in the following path:
path_to_pulled_code\build\lib\Release\libcurl.dll
path_to_pulled_code\build\lib\Release\libcurl_imp.exp
path_to_pulled_code\build\lib\Release\libcurl_imp.lib
So, now I had the lib file I needed. Now, in:
Project Properties -> Linker -> Input
I put "libcurl_imp.lib" and "ws2_32.lib" under Additional Dependencies.
As I've said before, I made sure that I had "CURL_STATICLIB" in Preprocessor Definitions. I also switched Runtime Library to "Multi-threaded (/MT)" for this project.
After all that, well, it compiled! For some reason I needed to copy libcurl.dll that the aforementioned Visual Studio build of bagder's repo made into my executable path in order for the solution to actually work. But it seems to be working now at least!
Thanks guys. Hopefully this answer will help anyone else who stumbles onto this problem like I did.
I walked through this tutorial and tried to recreate the example I get this error:
Error 1 error LNK2019: unresolved external symbol __imp__GetXyz#0 referenced in function _main app.obj app
If I download the source from the website and run the project in visual studio it works, but If I even copy the code from the original project in my own visual studio solution it still doesn't work. I guess it must be some project settings, I don't know. What do do?
You need to add the XyzLibrary.lib to your Linker settings within project settings.
You can also do it directly in code by using #pragma comment(lib,"xyzlibrary.lib") if you are using VisualStudio.
The reason why it works in the given sample without these 2 approaches is that in the solution file, the dependencies are set from XyzExe to XyzLib, and XyzProject has 'Link Library Dependencies' in Linker settings set to true. However, I am not too keen on this approach, as I don't like to store data important for building inside solution files (for larger projects, developer's solution files can differ from build system solution files)
Seems like you are missing some external library that needs to be linked in. Whatever provides the GetXyz function is missing.
Open the Solution that works, right click the project, Properties, Linker, Input, and check what their Additional Dependencies list up. You need to add the same to your own project.