SFML and VS2013 - WinMain/main linker error - c++

I am trying to use SFML with Visual Studio 2013 using the tutorial on the SFML website and using their sample code (replacing main() with WinMain()) but I'm getting the linker error:
Error 1 error LNK2019: unresolved external symbol _main referenced in function _WinMain#16
I am referencing the libs:
sfml-graphics-d.lib
sfml-window-d.lib
sfml-main-d.lib
sfml-system-d.lib
and I am pointing correctly to the 'include' and 'lib' folders in my Project Properties.
I have tried using 'main()' with sfml-main-d.lib referenced and 'WinMain()' without it referenced and I still get the linker error.
Any suggestions?
Thank you for your time

Okay I seem to have solved it but don't know how. I'll do my best to explain to anyone else who is stuck:
I started a new project again with a fresh download of SFML 32-bit for VS2013.
I added sfml-main-d.lib and sfml-main.lib to my referenced libs (for debug and release respectively) and then use "int main()..." instead of "int __stdcall WinMain()" and it linked and compiled correctly.
I thought I had already tried this combination but I guess maybe not.
Thanks to anyone who took the time to read this question and to Elried for commenting.

Related

Updated Visual Studio, now wxWidgets complains about unresolved symbols

Problem description:
I have a Visual Studio 2012 C++ project which uses wxWidgets. It compiles and links perfectly.
For reasons we won't go into, I now need to make this work with Visual Studio 2015.
Having twiddled the settings and got all the code to compile, it now refuses to link because all the libraries it uses are compiled for VS 2012. OK...
I replaced all the libraries with ones compiled for VS 2015. Everything works again... except wxWidgets.
I have now spent multiple days fruitlessly trying to force wxWidgets to work. It just won't do it.
Here's what I've done so far:
Looking at the instructions at https://github.com/wxWidgets/wxWidgets/releases/, it appears I'm supposed to download and unpack two files:
wxWidgets-3.1.1-headers.7z (which contains an include folder)
wxMSW-3.1.1_vc140_Dev.7z (which contains a lib folder).
I deleted the old wxWidgets stuff, and unpacked these two new zips.
Hundreds of preprocessor errors saying it can't find some include file. It looks like the old directory structure had ...\lib\vc_lib\... rather than ..\lib\vc140_dll\..., so I tried renaming the folder. Now everything compiles successfully.
Next the linker complains that it can't find wxbmsw28ud_core.lib — which makes sense, considering I just deleted it. I changed all the filenames to be *31 rather than *28, and no more file-not-found errors.
Now I have hundreds of LNK2001 errors. For example:
Error LNK2001 unresolved external symbol "protected: static struct wxEventTable const wxDialogBase::sm_eventTable" (?sm_eventTable#wxDialogBase##1UwxEventTable##B)
I don't understand this though. If I run DumpBin.exe against wxmsw31ud_core.lib, it dumps out several megabytes of text, including:
5146A2 __imp_?sm_eventTable#wxDialogBase##1UwxEventTable##B
and also
29C0 __imp_?sm_eventTable#wxDialogBase##1UwxEventTable##B
and also
Version : 0
Machine : 14C (x86)
TimeDateStamp: 5A8A0543 Sun Feb 18 22:59:15 2018
SizeOfData : 00000049
DLL name : wxmsw311ud_core_vc140.dll
Symbol name : ?sm_eventTable#wxDialogBase##1UwxEventTable##B (protected: static struct wxEventTable const wxDialogBase::sm_eventTable)
Type : data
Name type : name
Hint : 14306
Name : ?sm_eventTable#wxDialogBase##1UwxEventTable##B
In other words, the exact symbol that VS says it can't find!
So if the symbol is in the .lib file and I can see it there, why is VS complaining that it's not in the .lib file?
Just to be 100% certain, I made a table of every single symbol that VS claims it can't find and which .lib file it's actually in:
LNK2001 ?sm_eventTable#wxDialogBase##1UwxEventTable##B wxmsw31ud_core.lib
LNK2001 ?wxTheAssertHandler##3P6AXABVwxString##H000#ZA wxbase31ud.lib
LNK2001 ?wxTrapInAssert##3_NA wxbase31ud.lib
LNK2001 ?wxConvLibcPtr##3PAVwxMBConv##A wxbase31ud.lib
LNK2001 ?wxEmptyString##3PB_WB wxbase31ud.lib
LNK2001 ?npos#wxString##2IB wxbase31ud.lib
LNK2001 ?sm_first#wxClassInfo##0PAV1#A wxbase31ud.lib
LNK2001 ?wxNullBitmap##3VwxBitmap##A wxmsw31ud_core.lib
LNK2001 ?wxNullIcon##3VwxIcon##A wxmsw31ud_core.lib
LNK2001 ?wxDefaultSize##3VwxSize##B wxmsw31ud_core.lib
LNK2001 ?wxDefaultPosition##3VwxPoint##B wxmsw31ud_core.lib
LNK2001 ?wxEVT_NULL##3HB wxbase31ud.lib
LNK2001 ?wxEVT_BUTTON##3V?$wxEventTypeTag#VwxCommandEvent####B wxmsw31ud_core.lib
LNK2001 ?wxDefaultValidator##3VwxValidator##B wxmsw31ud_core.lib
LNK2001 ?wxButtonNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?ms_classInfo#wxDialog##2VwxClassInfo##A wxmsw31ud_core.lib
LNK2001 ?wxStaticTextNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?wxListCtrlNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?wxConvUTF8Ptr##3PAVwxMBConvStrictUTF8##A wxbase31ud.lib
LNK2001 ?ms_appInitFn#wxAppConsoleBase##1P6APAVwxAppConsole##XZA wxbase31ud.lib
LNK2001 ?ms_appInstance#wxAppConsoleBase##1PAVwxAppConsole##A wxbase31ud.lib
LNK2001 ?ms_idMainThread#wxThread##0KA wxbase31ud.lib
LNK2001 ?wxEVT_CLOSE_WINDOW##3V?$wxEventTypeTag#VwxCloseEvent####B wxmsw31ud_core.lib
LNK2001 ?wxEVT_SIZING##3V?$wxEventTypeTag#VwxSizeEvent####B wxmsw31ud_core.lib
LNK2001 ?wxEVT_COMMAND_ENTER##3V?$wxEventTypeTag#VwxCommandEvent####B wxmsw31ud_core.lib
LNK2001 ?wxTextCtrlNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?wxGaugeNameStr##3QBDB wxmsw31ud_core.lib
LNK1120 28 unresolved externals
As you can see, every single symbol is listed in either wxmsw31ud_core.lib or wxbase31ud.lib, which are both configured in the project (along with several additional wxWidgets libraries as well).
I don't understand what the problem is. I don't get why it's complaining at me. But I need to make this work. Any suggestions?
Mixing compiled files from different VS versions will lead to errors ("not found" or "incompatible") in the linking stage. Also, mixing 32/64 versions will fail.
Delete (or move to a different dir) all of [old] wxWidgets stuff, specially the generated dirs and objects during a previous wxWidgets building.
Download current wxWidgets sources from official page, or the Windows installer.
Build using the proper VS solution. Taken from wxdir\docs\msw\install.txt:
Ready to use project files are provided for VC++ versions 7, 8, 9, 10,
11, 12, 14 and 15 (also known as MSVS 2003, 2005, 2008, 2010, 2012,
2013, 2015 and 2017 respectively).
Simply open wx_vcN.sln (for N=7, 8, 9, 10, 11, 12, 14, or 15) file,
select the appropriate configuration (Debug or Release, static or DLL)
and build the solution. Notice that when building a DLL configuration,
you may need to perform the build several times because the projects
are not always built in the correct order, and this may result in link
errors. Simply do the build again, up to 3 times, to fix this.
So, simply open wx_vc14.sln and build your solution. It seems you want static library, so wx gets embedded into your app; if not, select the DLL solution.
Notice that in that wxWidgets download page you can directly get the headers and the static ("Development") or dynamic ("Release DLL") already compiled files, so as to avoid wxWidgets compilation itself.
Your link error is due to the linker looking for the function in a static library, while you're linking with DLL import libraries. IOW when you write
In other words, the exact symbol that VS says it can't find!
it is just wrong because there is clearly a difference: one symbol has the __imp__ prefix and the other one doesn't.
Either rebuild your application with WXUSINDLL defined or link with static wx libraries.
And, honestly, all of us make mistakes and it may happen that you spend hours or even days on something that can be solved in minutes, but blaming your tools really doesn't help when the problem is not with them.
On top of a great help from Vadim and Ripi2, I think you are also trying to upgrade wxWidgets from version 2.8 to 3.0. This is in itself a huge task and you should consider do one properly then the other.
I'd start with the building 2.8 source statically with the compiler at hand and then try to ujpgrade the version of wxWidgets very carefully.
Thank you.
I eventually gave up and attempted to build wxWidgets from source.
It took many, many attempts, but eventually I was able to compile wxWidgets in such a way that my application now builds successfully. It seems you have to check that all the hundreds of thousands of compilation settings in VS are identical to the target application. No, it doesn't seem to be possible to automate that.
(Having said all that, compared to how nightmarishly difficult it usually is to build anything C-related from source, this was comparatively easy...)

Once again including library and Error LNK2001: unresolved external symbol

I have a problem with Visual Studio 2013 and Error LNK2001.
I tried to linking Zbar Library - I have downloaded, instaled and linked this library
I tried to run this simple program:
#include "zbar.h"
using namespace zbar;
int main()
{
ImageScanner scanner;
return 0;
}
I can compile this, but can't build it.
I can see this:
Error 1 error LNK2001: unresolved external symbol zbar_image_scanner_destroy C:\Users\n\Documents\nn\ZBar_detektor\Opencv_projekt\main.obj Opencv_projekt
Error 2 error LNK2001: unresolved external symbol zbar_image_scanner_create C:\Users\n\Documents\nn\ZBar_detektor\Opencv_projekt\main.obj Opencv_projekt
I know that except include directory, I have to link lib files
I did it this way:
Except that, I copy everything from /bin directory, and paste it to /Windows/System
In some cases, in the past this operation helped, but not this time - still can see Error LNK2001
Any clues or advices? Help please
Best regards, Fidor
In general: Thanks you! Zbar include sample VS project, but it required strange additional libraries. But that gave me a solution: Problem was, that my project was x64, and zbar are x32, and need kernel32.dll. When I changed my project configuration ewerything started work

Static linking on Windows OS

I am using LunarG SDK.I found VKstatic.1.lib in the Lib directory.When linking with that lib instead of vulkan-1.lib I am getting the following linker error:
VKstatic.1.lib(loader.obj) : error LNK2019: unresolved external symbol
__imp_PathIsRelativeA referenced in function loader_platform_is_path_absolute
Using VS2013 and VS2015,64bit project.
I see that the PathIsRelativeA comes from WIndows SDK.I set Linker->System to be Windows (/SUBSYSTEM:WINDOWS),but it doesn't solve the error.
Does static linking require some preprocessor flag?I haven't found any docs on how to link Vulkan statically.
UPDATE:
Added Shlwapi.lib ,as suggested by Richard Critten. That solved the linker errors for v120 compiler,but brought more errors for v140.
I found a way to fix the error on Visual Studio 2017 here (in one of the comments):VKstatic.1.lib not linking
You basically just need to link to cfgmgr32.lib as well (I did not need to link to Shlwapi.lib).

OpenSSL - LNK 2019

I'm getting LNK 2019 when trying to link in the OpenSSL libraries for a project I'm working on. I compiled the OpenSSL libraries and ran the test and all of them passed. I played with openssl.exe and got it to correctly create and MD5 hash. When I try to use the functions provided by the API though, it just won't recognize them. I even used dumpbin -headers on the .lib files to make sure that the ones I was using contained the correct references for the functions I was using.
I made sure to include the correct files and paths (I also included the header which isn't pictured here).
Here are the actual files and their paths
Here's the actual errors.
error LNK2019: unresolved external symbol _EVP_MD_CTX_create referenced in function _main
error LNK2019: unresolved external symbol _EVP_DigestInit_ex referenced in function _main
error LNK2019: unresolved external symbol _OpenSSL_add_all_digests
referenced in function _main error LNK2019: unresolved external symbol
_EVP_get_digestbyname referenced in function _main error LNK1120: 4 unresolved externals
How do I fix this? Did I put the files in the right place or did I forget an include? I've spent a few days trying to fix this already, this is my last resort :/
Im using Microsoft Visual Studio 2012
This can be problem with calling conventions.
Please check the project setting regarding calling convention.
OpenSSL compiles with /Gd option that means function will be of __cdecl calling convention.
You can either change your calling convention to /Gd or prefix OpenSSL function signatures which you are using with __cdecl.
I believe that this might help. This link explains how to change calling convention.
Please confirm if this can help you.
I was building for x86 when I should have been building with x64. As the x64 option did not show up in the menu, I thought it was unavailable to me. I realized that I had to add it under the project properties and now everything works fine.
Thanks for all the help.

Linking error while trying to build Boost.Log example

I have successfully built the Boost.Log library on Windows 7 for VS 2010. When I tried to run the simplest example, my program could not find the symbols for Boost.System and Boost.Filesystem, and I got the 'undefined external symbol' errors. I have coped with that issue by manually including libboost_filesystem-vc100-mt-gd-1_48.lib and libboost_system-vc100-mt-gd-1_48.lib in the project.
Nevertheless, now I have another problem: while trying to build the "basic_usage" example for Boost.Log I get the error
error LNK2019: unresolved external symbol "private: void __thiscall boost::log_mt_nt5::sinks::basic_text_file_backend<char>::construct(class boost::filesystem3::path const &,int,unsigned __int64,class boost::function0<bool> const &,bool)"
How can I solve this problem?
I have found the solution!
The reason was that I've built the Boost.Log with the Boost.Filesystem v2, while it was supposed to built with v3. I have rebuilt it correctly and now it works perfectly.