C++ error when compiling Orbiter sample - LNK2019 unresolved external symbol - c++

I have a very specific problem when trying to compile a 'sample' project for the Orbiter space flight simulator. I'm trying to compile the sample for the space shuttle 'Atlantis' using the preview version of Visual Studio 2019, and I'm getting an error like:
LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall VESSEL2::VESSEL2(class VESSEL2 &&)" (__imp_??0VESSEL2##QAE#$$QAV0##Z) referenced in function "public: __thiscall Atlantis_SRB::Atlantis_SRB(class Atlantis_SRB &&)" (??0Atlantis_SRB##QAE#$$QAV0##Z)
This is happening in the Atlantis_SRB project. My code is located at:
C:\Orbiter2016\Orbitersdk\samples\Atlantis\
I have a lot of experience in software engineering, but I'm a C++ noob. I've looked at general help for this error, so I understand that there is something that needs to be linked, but I'm not sure what, or how to do it.
I looked at this question on the Orbiter forum:
https://www.orbiter-forum.com/showthread.php?t=24247
It suggests checking the following under project > properties:
Linker - Input - Additional libraries
and
Linker - Advanced - Library search paths
When I check under the 1st one, I have the following under Linker > Input > Additional Dependencies:
orbiter.lib;orbitersdk.lib;%(AdditionalDependencies)
The 2nd location (Linker - Advanced - Library search paths) doesn't exist.
I'm used to C# reference errors when dlls are missing from 'references' and know how to solve them quickly, but I'm not sure what to do with this type of C++ issue.
How do I identify what the specific problem is, and what do I need to link, where (and how?!)

I posted this problem on the excellent Orbiter forum, and cyph0r provided a fix there which works with VS2017:
https://www.orbiter-forum.com/showthread.php?p=589264&posted=1#post589264
Basically orbiter.lib seems to only be fully compatible 'out of the box' up to VS2013, and apparently the Atlantis sample compiles fine using VS2013. (I went back to using VS2017 and implemented cyph0r's fix, which works - I haven't tried VS2019):
This is the significant part of the error:
__declspec(dllimport) public: __thiscall VESSEL2::VESSEL2(class VESSEL2 &&)" (__imp_??0VESSEL2##QAE#$$QAV0##Z) referenced in function "public: __thiscall Atlantis_SRB::Atlantis_SRB(class Atlantis_SRB &&)
It's indicating that a move constructor is being referenced by the Atlantis_SRB class declaration, which can't be found in VS2017. This is the part that's indicating that the move constructor is being referenced:
__declspec(dllimport) public: __thiscall VESSEL2::VESSEL2(class VESSEL2 &&)
The fix is to remove the expectation that this move constructor exists, by editing the Atlantis.h file within the Atlantis sample. The link to the question on the Orbiter forum gives full details of what you need to do.

Related

Including Lua in VS2015 C++ Project

I would like to integrate Lua into my current C++ application I build with VisualStudio 2015 (x64 mode).
I grabbed a simple Lua wrapper from here, and the Lua binaries for windows x64 from here (the lua-5.1.5_Win32_dll14_lib.zip one).
Next, I added the include and library path to the project preferences. Works so far in the IDE. However, when I try to compile the code it throws 24 errors (like these first two):
1>LuaScript.obj : error LNK2019: unresolved external symbol "lua_close" referenced in function ""public: __cdecl LuaScript::~LuaScript(void)" (??1LuaScript##QEAA#XZ)".
1>LuaScript.obj : error LNK2019: unresolved external symbol "lua_gettop" referenced in function ""public: void __cdecl LuaScript::clean(void)" (?clean#LuaScript##QEAAXXZ)".
which tells me next to nothing. Seems that the linker is unable to find the library but the includes are working and the path to library is set, too. Any suggestions what I might have missed or should look into? Any hint would be appreciated!

SFML and VS2013 - WinMain/main linker error

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.

Building and linking test code for Crypto++

I'm trying to write some simple test code for the Crypto++ library for a project. I have yet to manage to get my own code to build though. It compiles fine, the problem comes in linking. I'm still pretty new to Visual Studios, but I'm using VS10. The errors I'm getting are:
1>sec_test.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CryptoPP::DES::Base::ProcessAndXorBlock(unsigned char const *,unsigned char const *,unsigned char *)const " (?ProcessAndXorBlock#Base#DES#CryptoPP##UBEXPBE0PAE#Z)
1>sec_test.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CryptoPP::DES::Base::UncheckedSetKey(unsigned char const *,unsigned int,class CryptoPP::NameValuePairs const &)" (?UncheckedSetKey#Base#DES#CryptoPP##UAEXPBEIABVNameValuePairs#3##Z)
I've tried everything I can find in the documentation in terms of linking. I've never linked against a DLL before, but these are the errors I get when I try to. If I try to do what I think is linking against the static library version, I get even more.
I should note, I'm trying to test pure DES at the moment. In particular, here are the API calls I'm making, just to be safe:
DES::Encryption DES_encrypt;
DES_encrypt.SetKey(key, 64);
DES_encrypt.ProcessAndXorBlock(plaintext, NULL, ciphertext);
DES::Decryption DES_decrypt;
DES_decrypt.SetKey(key, 64);
DES_decrypt.ProcessAndXorBlock(ciphertext, NULL, decrypted);
If anyone can help, or point me in the right direction, I'd be much obliged.
First thing to check is your project properties (right click on project, click Properties).
External libraries need to be specified in the Linker->Input->Additional Dependencies field, either by absolute path or in conjunction with the other VS path properties.
You can look in Linker->Command Line and check that the .lib files you want are actually being passed to the linker.
An alternate method is to turn off the Suppress Startup Banner option in the Linker->General options, and then check the build output to make sure it has what you want.
If you know that the libraries you want are being linked, another useful trick is to check the output of the strings command (in linux or cygwin) or dumpbin /HEADERS in the VS command prompt. You can look through the output of these commands for the symbol VS claims is missing to verify that it really is defined in the .lib file. Sometimes larger software packages have multiple .lib files, so this can help make sure you are linking the one that has the symbol you want.

Linking error: LNK2019 & LNK1120

First I had some OpenCL code and when I put it away in another function, I got this error, then I thought maybe its something with OpenCL, but now even my every normal code suddenly appears to report this error whenever I make new function and put main function code in those functions. I have rechecked that prototypes, functions calls and function definitions are exactly same and matches, also since I have this problem with those functions in which there are more arguments like upto 8 or 10 but I read that C/C++ functions supports more 50 or so arguments passing. The error information is:
ImgConv.obj : error LNK2019: unresolved external symbol "void __cdecl function(.............) (?conv_ser##YAXPBMPAM10HHH#Z) referenced in function _main
fatal error LNK1120: unresolved externals
I am reporting error that has lot of forum entries and solution information such as linking some library function or functions prototyping mistakes etc, I have read them but there is non related to my problem.
Check the linker input settings in your project configuration and make sure that the appropriate libraries are included (or add them to the project itself). Visual Studio doesn't do this automatically just because you add the source code to your project.
If 'conv_ser' is a function that you created make sure that the implementation for that function is available in the project. Double check to make sure that the arguments in the prototype (typically in the header) match that of the any implementation you have added.
Have you tried deleting all instances of void __cdecl function? Just search through your project and comment it out. See if your code will compile after this.

MSVS2010 linker error sadness - not entirely sure what is wrong

I am using a library of code from a tutorial for providing functionality for passing function points of non-static member functions to a function that expects a static function pointer, probably helps to know what I am suing, so here is the link http://www.codeproject.com/KB/cpp/thunk32.aspx This code uses the Boost library, which I have downloaded and set-up more or less everything from.
In the Thunk library, one of the header files has a section that reads
#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,THUNK32_MAX_ARGS,"Thunk32_template.h"))
??=include BOOST_PP_ITERATE()
#undef BOOST_PP_ITERATION_PARAMS_1
but this gives me epic amounts of errors, which I can solve by changing it to
#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,THUNK32_MAX_ARGS,"Thunk32_template.h"))
#include BOOST_PP_ITERATE()
#undef BOOST_PP_ITERATION_PARAMS_1
This code that is downloaded is included in my solution as a second project, which is able to compile and build happily. But my project that is using this code has issues linking, to save people asking, I get these error messages
1>WebCamera.obj : error LNK2019: unresolved external symbol "protected: __thiscall indev::Thunk32Base::Thunk32Base(void)" (??0Thunk32Base#indev##IAE#XZ) referenced in function "public: __thiscall indev::Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>::Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>(void)" (??0?$Thunk32#VWebCamera##$$A6AXPAUHWND__##PAUvideohdr_tag###Z#indev##QAE#XZ)
1>WebCamera.obj : error LNK2019: unresolved external symbol "protected: __thiscall indev::Thunk32Base::~Thunk32Base(void)" (??1Thunk32Base#indev##IAE#XZ) referenced in function "public: __thiscall indev::Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>::~Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>(void)" (??1?$Thunk32#VWebCamera##$$A6AXPAUHWND__##PAUvideohdr_tag###Z#indev##QAE#XZ)
1>WebCamera.obj : error LNK2019: unresolved external symbol _capCreateCaptureWindowA#32 referenced in function "public: bool __thiscall WebCamera::Init(struct HWND__ *)" (?Init#WebCamera##QAE_NPAUHWND__###Z)
I think this is trying to say that the constructor and destructor are not declared and that my WebCamera.Init()is messed up as well. I have made sure that the library that the Thunk32 project exports is included in my other project, but still I get these errors.
I would like to know if I have made the correct assumption that ??=include should have been changed to #include and if I have, what have I done wrong or failed to do that results in these linker errors. Or if you can provide me with a different way of being able to pass a function pointer to a non-static member function that would be awesome.
Thanks
??= is a "trigraph" sequence for the # character. according to the standard, trigraphs are supposed to be handled as one of the first steps in processing (in phase 1 - before the preprocessor handles directives),so:
??=include "whatever"
Should be equivalent to:
#include "whatever"
so you should be able to use that form (I wonder why the trigraph was put there in the first place - some sort of evil joke perhaps?)
However, trigraphs cause problems and confusion (probably more than they help), so compilers seem to be moving towards warning about them and/or defaulting to not handling them. The compiler in VS 2010 has trigraph processing turned off by default - you have to use the /Zc:trigraphs option to turn it on.
See Purpose of Trigraph sequences in C++? for more details.
Ah, Einar, good man. Doing flash and Sharepoint stuff these days, ouch. Norwegian, might explain the trigraphs.
Anyhoo, nothing complicated, you just forgot to tell the linker to look at some libraries. Right-click your project, Project Dependencies, tick the Thunk project. That makes sure that Thunk32.lib gets looked at and resolves the ctor and dtor.
Right-click again, Properties, Linker, Additional dependencies, add "winmm.lib". That resolves the capCreateCaptureWindow symbol.
Do you have a constructor and a destructor declared in the indev::Thunk32Base class that you forgot to define in its cpp file?
Ok, so I have managed to solve this now.
Michael Burr nicley said that ??= is basically the same as typing # but in a way that people who dont have the hash symbol can type it, see Purpose of Trigraph sequences in C++?
Hans Passant then got the ball rolling for me buy letting me know that I had not fully linked in stuff. I needed to right click on my main project, select 'Project Dependencies' and select my other project that has the thunk32 code. I also needed to tell my main project to look at where the Thunk project is saving the lib, which turned out to be in a folder in my documents (explain that one!). I also needed to add the Thunk32d.lib (note the 'd' because I was/am in debug mode. Hans said that I needed winmm.lib but it turned out (when googling the function that was giving me the error that I needed Vfw32.lib instead.
Thanks guys! I hope that by giving the full answer like this it can help some one else who has a similar problem.