Problem compiling exiv2 code in VS 2022: Undefined Reference/symbol error - visual-c++

I have some code in Linux that uses exiv2 to read the metadata of a folder full of photos, depending on requirements it can reconstruct missing metadata, and stamp a logo as well as lat/long onto the photos. I'm trying to port it into windows visual studio so that I can make a GUI and let other people use it.
I downloaded the MSVS source code for exiv2, I've added the include folder and lib folders both in the include line and the linker line in the project properties dialogue. When I try to compile I get an undefined reference error whenever an EXIV2 object is called.
I'm guessing I have some sort of linking or library building issue. I built it on linux using g++ and had no problems. If I weren't trying to make a GUI I'd probably just get a windows version of g++ to compile with.
This is one of the error messages I'm getting.
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::_List_iterator<class std::_List_val<struct std::_List_simple_types > > __thiscall Exiv2::ExifData::begin(void)" (_imp?begin#ExifData#Exiv2##QAE?AV?$_List_iterator#V?$_List_val#U?$_List_simple_types#VExifdatum#Exiv2###std###std###std##XZ) referenced in function "int __cdecl uptake(class std::vector<struct EANphoto,class std::allocator > &,char *,char *)" (?uptake##YAHAAV?$vector#UEANphoto##V?$allocator#UEANphoto###std###std##PAD1#Z) CAPconsole C:\Users\ [redacted] \source\repos\CAPconsole\CAPconsole.obj 1
I've tried adding include files for both the "include" and the "lib" folders to both the include line and to the linker. I also tried to compile the sample program that came with Exiv2, and I get the same error,so I'm guessing it's a VS setting issue.

So, the way to do this is as follow:
In "Properties" … "C/C++" … "General" … "Additional Include Directories", add the include and lib folders, and do the same in
"Linker" … "Additional Library Directories".
Finally, in "Linker" … "Command Line" … "Additional Options", write in "exiv2.lib".

Related

Visual C++ linker complaining about the absence of a symbol that is not absent

In short: on Visual C++ 2015, I get a linker error complaining about the absence of symbols that are present in the .lib file I link against.
In long: While compiling-and-liking some program from the command line with cl.exe I get the following as the first of many errors:
main.obj : error LNK2001: unresolved external symbol "protected: static struct wxEventTable const wxApp::sm_eventTable" (?sm_eventTable#wxApp##1UwxEventTable##B)
AFAIK, this long line says that my main.obj refers to a function to which a symbol ?sm_eventTable#wxApp##1UwxEventTable##B is associated, but that the linker could not find this symbol in the (long) list of libs that I provided on the command line.
I compile in /MD mode. Don't know if it helps, hurts, or has no importance here.
One of the files I link with is wxmsw31u_core.lib and doing
dumpbin /headers wxmsw31u_core.lib > here.txt
gives a long file containting the following
Version : 0
Machine : 8664 (x64)
TimeDateStamp: 56D46194 Mon Feb 29 16:19:48 2016
SizeOfData : 00000045
DLL name : wxmsw310u_core_vc140_x64.dll
Symbol name : ?sm_eventTable#wxApp##1UwxEventTable##B (protected: static struct wxEventTable const wxApp::sm_eventTable)
Type : data
Name type : name
Hint : 14083
Name : ?sm_eventTable#wxApp##1UwxEventTable##B
From this I infer that wxmsw31u_core.lib this is an "import library" : in other words that means that this lib does not contain the code but just refers to the dll file wxmsw310u_core_vc140_x64.dll that actually contains the code.
The latter wxmsw310u_core_vc140_x64.dll file indeed mentions ?sm_eventTable#wxApp##1UwxEventTable##B as I checked:
dumpbin /EXPORTS wxmsw310u_core_vc140_x64.dll > here2.txt
gave
14084 3703 0057F008 ?sm_eventTable#wxApp##1UwxEventTable##B = ?sm_eventTable#wxApp##1UwxEventTable##B (protected: static struct wxEventTable const wxApp::sm_eventTable)
I note that the first number is equal to the hint of the previous header plus one. I suppose this is normal?
I took the time to check the DLL as above but AFAIK, the DLL is not required in the linking process (it is required when you call the .exe that is produced).
All in all, it seems everything is there and it should link, so I am at a loss to determine what's wrong here.
Edit
I partially solved the problem by compiling myself the libary instead of using the compiled binaires for Windows provided by wxWidgets: I can now compile my program and all is well.
Well, not all: the initial question remains. I had a situation where I tried to link an obj with a lib to get an exe, the obj refers to a symbol whose mangled name is present verbatim in the lib, the linker does load the obj and lib (confirmed using /VERBOSE), yet the linker refuses to consider the symbol as "resolved". Why?
I'll create a new question where I'll ask for explanations about the conditions to be resolved.
AFAIK, this long line says that my main.obj refers to a function to which a symbol ?
Yes, linker is not able to find sm_eventTable#wxApp##1UwxEventTable##B on your paths specified.
Check that you have properly setup Additional Library Path parameter and that target platform of your application is /Machine:X64

I can't understand why it has error LNK2019 "unresolvant external symbols"

I follow the insturction to compile glpk on windows, then I got glpk_4_52.lib and glpk_4_52.dll. In my VC 2010 project, I include head file
#include "glpk.h"
and I include glpk_4_52.lib in "additional library directory".
But after compiling it still shows:
error LNK2019, "unresolvant external symbols", _glp_create_prob, referenced in _main
and similar others.
Could anyone knows what the problem is here? Thanks!d
"Additional library directory" is not the right way to add a lib file to the link.
Either,
Add glpk_4_52.lib in Configuration Properties -> Linker -> Input -> Additional Dependencies
or
Make the glpk project a dependency of your EXE project, if they are in the same solution, bu using "Project Dependencies" and make sure that Configuration Properties -> Linker -> General -> Link library dependencies is set to Yes
I am able to reproduce your problem by using the H and LIB version 4_52 from the precompiled package on SourceForge, by forcing the calling convention of my EXE to __stdcall (/Gz) (In C++->Adanced).
You should use __cdecl (/Gd) instead!

Keep VC++ 2005 static library and your application in separate solutions

I have successfully built a static library as described in this walkthrough:
http://msdn.microsoft.com/en-us/library/ms235627%28v=vs.80%29.aspx
In the example above, both the static library and the application are located within the same solution but I prefer to keep them in separate solutions. After separation, I can compile but cannot link, here is the error:
main.obj : error LNK2019: unresolved external symbol…
Then I tried the project level setting of my application C/C++ / General / Additional include directories to where my .h file resides.
I also set .. Linker / General / Additional library directories to where my .lib file is at.
I finally set .. Linker / Input / Additional dependencies to where my .lib file is at.
Again, I could compile but not link. Here is the entire link error:
LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification
main.obj : error LNK2019: unresolved external symbol "public: static double __cdecl MathFuncs::MyMathFuncs::Add(double,double)" (?Add#MyMathFuncs#MathFuncs##SANNN#Z) referenced in function _main
Release\StaticLibraryApp.exe : fatal error LNK1120: 1 unresolved externals
Your project should link against the library project. In the 2nd project properties, add a library path where .lib file is stored and also include path for header path. This should resolve the issue. Also make 1st project dependent on 2nd solution.
Have a look at below article how to add libraries:
http://www.lavishsoft.com/wiki/index.php/Visual_Studio_Paths

Library linker errors driving me mad

It's me again. I'm back with an all new project and an all new problem.
I am trying to implement something for Growl. Either using a static or shared library (both are provided). I included the necessary header and linked to the library. (2 ways actually, once through the project properties and the other through a pragma statement). However, im still receiving the following linker errors:
error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall Growl::Growl(enum Growl_Protocol,char const * const,char const * const,char const * * const,int)" (__imp_??0Growl##QAE#W4Growl_Protocol##QBD1QAPBDH#Z)
error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall Growl::~Growl(void)" (__imp_??1Growl##QAE#XZ)
fatal error LNK1120: 2 unresolved externals
The line of code that is causing these linker errors is this line:
const char *n[2] = { "username" , "password" };
Growl *growl = new Growl(GROWL_TCP,NULL, "Appname", (const char **const)n,2);
The header file is being included at the top of the file and I am linking with the following line:
#include "..\\..\\..\\libs\\Growl\\growl++.hpp"
#pragma comment(lib, "..\\..\\..\\libs\\Growl\\libgrowl-static++.lib")
The header source can be found here:
https://github.com/psinnott/gntp-send/blob/master/headers/growl%2B%2B.hpp
I retrieved the pre-built binaries from the following page:
https://github.com/psinnott/gntp-send/wiki/Windows
Some extra info: I do have my Project Propeties character set to use Multi-Byte Character Set, im under the assumption this shouldn't affect anything. This is also a Win32 Console application.
Where am I going wrong?
Update:
Found this via google:
http://groups.google.com/group/growl-for-windows/browse_thread/thread/6c48a62454d062f1
Followed the instructions:
Added the libgrowlstatic.lib (alongside libgrowlstatic++.lib)
Added the pre-processor definitions, GROWL_STATIC and GROWL_CPP_STATIC
Got lots of error including:
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
fatal error LNK1169: one or more multiply defined symbols found
So I added the following line to Project properties, Linker, Command Line:
/NODEFAULTLIB:MSVCRTD /NODEFAULTLIB:LIBCMT
Now im getting alot more errors including some of the following:
libgrowl-static.lib(tcp.obj) : error LNK2019: unresolved external symbol _atoi referenced in function _growl_tcp_parse_hostname
libgrowl-static.lib(tcp.obj) : error LNK2019: unresolved external symbol _strchr referenced in function _growl_tcp_parse_hostname
libgrowl-static.lib(growl-static.obj) : error LNK2019: unresolved external symbol _fseek referenced in function _growl_tcp_register
libgrowl-static.lib(growl-static.obj) : error LNK2019: unresolved external symbol _fopen referenced in function _growl_tcp_register
libgrowl-static.lib(growl-static.obj) : error LNK2019: unresolved external symbol _strcpy referenced in function _growl_udp_notify
Been at this for several hours and can't seem to figure it out. 10+ views and no replies?
I swear im not being lazy. I looked into one of the answers provided about libraries but didn't have much luck. Nothing explained why this is acting the way it is. Please help!
#pragma comment(lib, "..\\..\\..\\libs\\Growl\\libgrowl-static++.lib")
There is a clear mismatch between the #pragma and the way your code is getting compiled. The name of the library strongly suggests this is a static link library, the "static" in the name makes that clear. The error messages however talk about __declspec(dllimport), a directive that's used when you compile code that #includes a header that assumes the code lives in a DLL instead of a static link library.
The other errors you are getting bear this out as well. The Project + Properties, C/C++, Code Generation, Runtime Library setting matters. You are using the /MD setting, a setting that's appropriate when you work with DLLs. The library no doubt was compiled with /MT, a setting appropriate when you create a monolithic EXE that doesn't use DLLs. You are trying to link two chunks of code that were built with conflicting settings, the linker falls over when trying to deal with this. It explicitly says so in an error message.
You'll need to either dig up the DLL version of the .lib or use /MT consistently in the rest of your code. There's usually a #define that tells the .h file which version of the .lib you intend to link.
This is working for me. It assumes you want to use the static libraries and not the dll.
Properties -> Configuration -> Properties -> VC++ Directories
Add directory of unzipped sdk to include and library directories
Properties -> Configuration -> Properties -> C/C++ -> Preprocessor
Add GROWL_STATIC and GROWL_CPP_STATIC to preprocessor definitions
Properties -> Configuration -> Properties -> C/C++ -> Code generation
Change runtime library to multi threaded ( /MT or /MTd )
Properties -> Configuration -> Properties -> Linker -> Input
Add ws2_32.lib , libgrowl-static.lib and libgrowl-static++.lib to additional dependencies

VC++ Project: unresolved external symbol HidD_GetHidGuid

I'm trying to build a project (for ARM) to facilitate the communication over an HID device. Here are the details of what I have:
PC with Windows 7
Visual Studio 2011 Developer Preview
WDK
A microsoft library function FindKnownHidDevices() makes a call to HidD_GetHidGuid() in my project. However, Linker doesn't like this and complains:
*error LNK2019: unresolved external symbol HidD_GetHidGuid referenced in function "unsigned char __cdecl FindKnownHidDevices*
I already have all of following workarounds in my project with no success so far:
Include hid.lib & SetupAPI.lib in Linker -> Input -> Additional Dependencings under configuration manager of VS 2011
Include hidsdi.h under "VC++ Directories -> Include Directories" in Configuration Manager of VS 2011
Include hidsdi.h in the .h version of .c file which makes a call to the function HidD_GetHidGuid() using extern "C"
What might I be missing?
If the code compiles OK, then the compiler is finding the correct header files. As the linker is failing, this suggests that it cannot find the specified .lib files.
Have you downloaded and installed the WoA SDK? The required lib files may not actually be in the linker folder for ARM targets (they're not in the default installation for Studio 11 Developer Preview).

Resources