C++: Unresolved external symbol _sprintf and _sscanf in Visual Studio 2015 - c++

For a research project, I'm writing a C++ add-on to a scientific computing language. Unfortunately the library that allows users to do this is not kept very well up-to-date.
I started the project in XCode, where it built fine. Later I had to move to a PC, so I migrated the code to Visual Studio 2015. Since doing this, I haven't been able to build due to the following errors:
LNK2001 : unresolved external symbol _sprintf
LNK2019 : unresolved external symbol _sscanf referenced in function _GetDDouble
LNK2019 : unresolved external symbol _sprintf referenced in function _CheckRunningInMainThread
An attempted fix was to add the header #define _CRT_SECURE_NO_WARNINGS. However, this a) fixed no errors and b) added the warning C4005 : '_CRT_SECURE_NO_WARNINGS': macro redefinition. I assume the library already defined this macro, anticipating this problem. Regardless, it didn't solve the problem.
How should I proceed?

Add the following library to the linker input files:
legacy_stdio_definitions.lib
VS 2015 now uses inline definitions that call internal functions for many of the stdio.h functions. If an object file (or library member) depends on one of those functions, then the legacy_stdio_definitions.lib provides an externally linkable version of the function that can be linked to.
Your other option is to recompile the unit that depends on those functions with VS 2015 (this is probably the preferred option).

I got this error compiling cycling max plugins against version 5 max sdk (pure c api). The legacy library fix didn't work for me (it should have, and if anyone had any idea why it mightn't I'd be curious), but I defined _NO_CRT_STDIO_INLINE before stdio was loaded and that did do the trick.

I recently encountered this and was able to add User32.lib to Linker > Input > Additional Dependencies.
You could also include #pragma comment (lib, "User32.lib") in your code.

Related

error LNK2019 unresolved external symbol when trying to link dll

I know many people have asked about this error and trust me I've read ALL of them and followed all the steps! But I'm still getting the unresolved external symbol error.
I'm trying to use the dll of lp_solve (a linear programming package) in my c++ code in visual studio 2012.
The error message I'm getting is:
Error 80 error LNK2019: unresolved external symbol _make_lp#8 referenced in function "void __cdecl my_solve(BLAH BLAH)
The function make_lp() is from the lp_solve package and I'm calling it from my_solve() in my code. This error message pops up for each solver function I call. Seems the linker just couldn't find any of the implementation of these functions.
I've done the following
put #include "lp_lib.h" in my source code
put the .dll, .h and .lib files from the lp_solve package in the working directory and
added the path under Linker:General:Additional Library Directories.
added the lib under Linker:Input:Additional dependency
What's wrong?
Thanks for your help!
The problem I had was solved after realizing I downloaded the WIN64 package for lp_solve but my visual studio is using WIN32 as build platform (even though my machine is x86_64).
Using extern "C" may be helpful while including lp_lib.h in your .cpp as follows:
extern "C"
{
#include "lp_lib.h"
}
For more information, please check this link:
http://www.geeksforgeeks.org/extern-c-in-c/

Google Protocol buffer c++ link error when trying to use it in project

I am trying to get protocol buffer to work but linking problems occurs.
All the errors looks something along like this
error LNK2019: unresolved external symbol "public: bool __cdecl google::protobuf::MessageLite::ParseFromArray(void const *,int)" (?ParseFromArray#MessageLite#protobuf#google##QEAA_NPEBXH#Z) referenced in function "void __cdecl ReceiveRequest(bool *)" (?ReceiveRequest##YAXPEA_N#Z)
I am using visual studio pro 2013 and this is what I have done:
I compiled the protocol buffer and added the libprotobuf.lib to the project(Add->Existing Item->libprotobuf.lib)
I've added the header files in C/C++ -> General -> "Additional Include Directories"
I have tried to add the library all the different ways I know but I still get these linking errors...
Any idea what I might have done wrong?
// Eric
You need to include the generated protocol buffer .cc (and maybe the .h) file (ie the file with the specific getters and setters for your specific proto) in your VS project (ie there has to be a little icon for them in the solution explorer) or else visual studio won't generate the code for it and thus there's nothing to link to.
Make sure you have the correct libraries for your architecture (e.g. x86 / x64).
That has caught me out a few times.

SOCI external symbol unresolved "struct soci::mysql_backend_factory const soci::mysql"

I'm really confused, i'm stuck with this problem, i hope you can help me :
I use : Windows 8.1, Visual Studio Express 2013 and SOCI 3.2.2
I have compiled both libsoci_mysql and libsoci_core and linked them into my project, but when i launch the compilation this error appear :
Error 1 error LNK2001: external symbol unresolved "struct soci::mysql_backend_factory const soci::mysql" (?mysql#soci##3Umysql_backend_factory#1#B) dbConnection.obj Server
I'm a little bit lost with Window, but i'm praticly sure libsoci_mysql.lib is found and (i have open the .lib with GNU emacs) contains the symbols.
Looks like it's a known problem with MSVC. The proposed workaround is to replace soci::mysql usage with *soci::factory_mysql().
In case someone else stumbles upon this I ran into a similar problem where odbc_option_driver_complete was undefined.
The issue was that this is defined in the header as an external and implemented in DLL. By default when building the DLL the code sets up a #define to eventually set __declspec(dllexport) for the external.
However, when you include the header in your code it does NOT by default set __declspec(dllimport) for the external! To trigger this you must #define SOCI_DLL in YOUR project to set this up.
Ideally your should set this in Project Properties -> C/C++ -> Preprocessor -> Preprocesor Definitions

LNK2019 error building ZeroMQ Hello World example. VS2012 RC

I get the following error trying to build the "hello world" example from ZeroMQ.
Error LNK2019: unresolved external symbol __imp__zmq_msg_init
referenced in function _wmain
I've added the library and header paths to the project (BTW how do I add them to the default settings?) and I've tried adding "libzmq-v100-mt.lib" (and "libzmq-v100-mt-gd.lib") to the linker additional inputs property. This didn't help.
Any other ideas?
The ZeroMQ headers (zmq.h in particular), by default, appear only to support dynamic linking on win32.
Try #define-ing ZMQ_EXPORT. That way, it won't see the __declspec(dllimport) declaration and won't expect to link against a .dll.

Debugging Visual Studio linker

I am trying to build an xll addin for Excel using appropriate framwork downloaded from MS website. I am getting the following linker errors:
1>FRAMEWRK.obj : error LNK2001: unresolved external symbol _Excel4
1>FRAMEWRK.obj : error LNK2001: unresolved external symbol _Excel4v#16
I think that these should be defined in XLCALL32.LIB included in the package from MS, but I don't know how to check it. Moreover, added the folder containing this library to the Additional Library Directories, without luck.
Hence my questions:
(1) How can I check what is in XLCALL32.LIB?
(2) How can I see which files the linker is using to see if my library is actually included?
In your project properties, Under Configuration Properties->Linker->Input, you will see 'Additional Dependencies' - these are the files the linker is using. Assuming that _Excel4 and _Excel4v are defined in XLCALL32.LIB (which I think they are), you simply need to ensure that this file is specified in this list.