Installing Glog linking error - c++

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!

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)

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

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/

Link against a 3rd-party library with Visual Studio

I'm trying to create a .dll with Visual Studios 2013. The project includes libpq functionality.
Per other stackoverflow posts, and other sources I've found on the internet, I've (as far as I'm aware) correctly added the postgres lib and include directories to the project. However, when I go to build the project, it returns a number of "unresolved external symbol" errors.
My paths are C:\Program Files\PostresSQL\9.3\... so I have them surrounded by quotation marks in the Additional Library/Include Directory fields. I've included the libpq-fe.h header file in the project... I'm just not sure what I'm doing wrong.
Another note, I can compile a test program from the command line using g++ with the -I, -L, and -lpq flags, but I'm not sure how to compile to a .dll from the command line (plus it adds complexity that I just don't want to deal with).
These are the specific errors I'm getting:
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQconnectdb
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQstatus
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQerrorMessage
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQfinish
1>C:\Users\tills13\documents\visual studio 2013\Projects\sql_arma\Release\sql_arma.dll : fatal error LNK1120: 4 unresolved externals
I have, as suggested below, included #pragma comment(lib, "libpq.lib") in the source file for my project, I still receive these errors.
I've successfully compiled the sample program by setting these project properties:
Add <pgsql install path>\include and \lib to VC++ Directories->Include and ->Library, correspondingly
Add libpq.lib to Linker->Input->Additional dependencies
This is the standard way to reference 3rd-party libs. It's just that they recommend using environment variables for their "base dirs" to avoid patching the project when it's under a VCS.
To be able to run the app from VS (both with and without debugging), I also specified PATH=%PATH%;<pgsql install path>\bin in Debugging->Environment since this dir isn't in PATH on my system.
It's not sufficient add the postgres lib directory to the project, you must also add
reference to libpq.lib. Just add this line to one of your source .cpp files:
#pragma comment(lib, "libpq.lib")
As noted by Marco A. the library must match a program bitness (32 or 64 bit): if you build 32-bit DLL (referred as Win32) you must use 32 bit library; if 64-bit (x64) - 64-bit library.
I have also faced same issue. Then I realized that I was building my application as a 32bit. I changed the target of my application to x64 and it compiled successfully

Why am I getting error LNK2001 when linking to zlib.lib?

I'm working on a project that already contains the gzip library as follows:
zlib\zlib.h
zlib\zlib.lib
zlib\zconf.h
I would like to use the gzip functions from this .lib but am getting the following errors:
Compress.cpp
Linking...
Compress.obj : error LNK2001: unresolved external symbol _gzclose
Compress.obj : error LNK2001: unresolved external symbol _gzerror
Compress.obj : error LNK2001: unresolved external symbol _gzwrite
Compress.obj : error LNK2001: unresolved external symbol _gzopen
.\Debug/files.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
The link settings include:
Object/library modules: zlib.lib
Project Options:
zlib.lib
In the file using the gzX() functions, it
#include "zlib/zlib.h"
What else needs to be done here to use these functions?
Thank You.
EDIT: Using Visual Studio 6.0 C++
EDIT2: It turned out the static library I was using had the gz() functions taken out of them. The header file still had them which was misleading.
I grabbed the one off here to get zlib to build in windows. If you did the same, you may have forgotten to #define ZLIB_WINAPI before including zlib.h
you also need to add zlib.lib to your project's libraries:
Project properties->Linker->Input->Additional Dependencies.
When the build stops, ctrl-click on the URL to see the more verbose form of the log and check the actual command line passed to the linker. That at least will tell you whether the option to link against zlib is being respected. You may get other useful diagnostic output. One possibility could be that the architecture is different (eg you're building x64 but the lib is x86)
It turned out the static library I was using had the gz() functions taken out of them. The header file still had them which was misleading.