error LNK2019 unresolved external symbol when trying to link dll - c++

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/

Related

Unresolved external symbol symbol __imp_get_function_ptr when compiling a C++ MEX MATLAB API

I am trying to run one of the example codes from the CPP Mex Repository of Matlab R2021a in the VS2017 IDE. Specifically, I am running the phonebook.cpp one. I previously ran with no problems when compiling other solutions in VS2017 with the C Mex API following this guide. However, I get the following message when compiling phonebook.cpp:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol __imp_get_function_ptr referenced in function "int (__cdecl*__cdecl matlab::data::detail::resolveFunction<int (__cdecl*)(int,int,bool *)>(enum matlab::data::detail::FunctionType))(int,int,bool *)" (??$resolveFunction#P6AHHHPEA_N#Z#detail#data#matlab##YAP6AHHHPEA_N#ZW4FunctionType#012##Z) test C:\Users\DuuMushishi\Documents\test.obj 1
I am not sure what library needs to be added or if the error is due to something else
I fixed the issue. Turns out I had to include in additional dependencies "libMatlabDataArray.lib" (in my case, located in C:\Program Files\MATLAB\R2021a\extern\lib\win64\microsoft)

Installing Glog linking error

I am new to programming. I want to install Glog on my Windows 10 system. I have followed the instructions found in a Stack Overflow thread with the same name.
I used cmake and Visual Studio 2015 to build the project.
First anomaly of the built file: I noticed that in the glog directory the header file "log_severity.h" was missing. To alleviate this problem, I copied the "log_severity.h" from the GitHub repository and pasted it.
http://imgur.com/QeLTnat
I then created a sample program that just initializes the logger by only using
google::InitGoogleLogging(argv[0]);
in the main.
Before compiling I direct the linker to include an additional include directory. This include directory is the one with the header files as in the second image (with the log_severity.h etc.):
http://imgur.com/yrjOIot
Yet I still receive a linking error when compiling the code:
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl google::InitGoogleLogging(char const *)" (__imp_?InitGoogleLogging#google##YAXPEBD#Z) referenced in function main
1>D:\Documents\Programming\C++\Programme\GLogTest\GlogTest\x64\Debug\GlogTest.exe : fatal error LNK1120: 1 unresolved externals
What am I doing wrong?
Thanks a lot of any answers.
I solved it. When you build the project in visual studio, there is also an "Installation" folder inside the MS project. I forgot to build that as well!

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

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.

error LNK2019: unresolved external symbol. c file to cpp

There is a project made in C, its file is RawInput.c from http://www.codeproject.com/Articles/185522/Using-the-Raw-Input-API-to-Process-Joystick-Input. I have compiled it and it works perfect in vs2012. But when i pasted the same code within a cpp of a a new project i get 4 of these errors, just different decleration names.
error LNK2019: unresolved external symbol "long __stdcall HidP_GetCaps(struct _HIDP_PREPARSED_DATA ....
fatal error LNK1120: 4 unresolved externals
i guess it has something todo with me trying to run c code within a c++ compiler without telling it the right way. Perhaps there must be extern "C" somewhere? I wouldnt know even tho i tryed my best to search the webb for solutions. Help would be appreciated. Thank you.
It seems that Hidsdh.h is not a C++ compatible header. Include it like this:
//This is not a C++ header
extern "C"
{
#include <Hidsdi.h>
}
You probably need to add the library file hidparse.lib, which contains the HidP_GetCaps function. Right-click the project in the solution explorer, select Properties, and under the Linker section (Input) add hidparse.lib to the 'Additional Dependencies'.
Adds library paths for project properties as following.
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\um\x64
Add a library "hid.lib" file.

Ms Visual Studio 2012, "unresolved external symbol"

I am trying to compile a C++ application through Microsoft Visual Studio 2012. I have linked the Boost, Jni, Acml libraries to the application.
When I click on rebuild, the compilation does not finish.
This is the first error I get:
Error 28 error LNK2019: unresolved external symbol _sgesdd referenced
in function "void __cdecl testLapackDGESDD_EASY(void)"
(?testLapackDGESDD_EASY##YAXXZ) C:\Users\DavideChicco\Documents\Visual
Studio 2012\Projects\Solution\mainConsole.obj
Do you have any idea of what this is related to?
Thanks
Your compilation seems to have finished, but the error happens during linking: the definition of the function _sgesdd called in testLapackDGESDD_EASY is not found. So
- either this function is defined in an external dll, and you need to add the lib in your solution,
- or this function is supposed to be defined in your project, and you need to implement its definition.
aha, The compiler cant't find the function "_sgesdd", I recommend you that add the lib which is supplied by the author of DLL.