libpng function calls are all unresolved external symbols - c++

I am trying to link my project against the libpng version 1.6.23 dll library, but my linker only sees all function calls that I make to it as unresolved external symbols. I am using Visual Studio Express 2013. Here is a snippet of the linker's output.
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_set_sig_bytes referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read#PNGUtils##SAPEAXPEBDAEAI1AEAH#Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_sig_cmp referenced in function "private: static bool __cdecl PNGUtils::Validate(struct _iobuf *)" (?Validate#PNGUtils##CA_NPEAU_iobuf###Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_create_read_struct referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read#PNGUtils##SAPEAXPEBDAEAI1AEAH#Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_set_longjmp_fn referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read#PNGUtils##SAPEAXPEBDAEAI1AEAH#Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_create_info_struct referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read#PNGUtils##SAPEAXPEBDAEAI1AEAH#Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_read_info referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read#PNGUtils##SAPEAXPEBDAEAI1AEAH#Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_set_expand_gray_1_2_4_to_8 referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read#PNGUtils##SAPEAXPEBDAEAI1AEAH#Z)
I am linking successfully with other libraries such as lua and glew, and I am to my knowledge doing nothing different when trying to link to libpng.
Strangely, when I put the linker into verbose mode. It states...
1> Finished searching libraries
1>
1> Unused libraries:
1> libs\png\libpng16.lib
The linker seems to claim that I am not using the libpng library even though I am clearly calling its functions such as in my code segment here in PNGUtils.cpp Read method.
png_structp pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!pngPtr)
{
LOG(LOG_CHANNEL_ERROR, "PNGUtils: Couldn't initialize png read struct");
fclose(fp);
return NULL;
}
png_infop infoPtr = png_create_info_struct(pngPtr);
if (!infoPtr)
{
LOG(LOG_CHANNEL_ERROR, "PNGUtils: Couldn't initialize png info struct");
png_destroy_read_struct(&pngPtr, (png_infopp)0, (png_infopp)0);
fclose(fp);
return NULL;
}
I feel lost on why the linker seems to be ignoring the function calls to libpng. I would be happy to hear any thoughts or answers and am of course more than willing to provide any more information on request.

Be sure that your project and your libpng.dll were built with
the same settings, as explained in the projects/vstudio/README.txt that comes with libpng:
WARNING
======= Libpng 1.6.x does not use the default run-time library when
building static library builds of libpng; instead of the shared DLL
runtime it uses a static runtime. If you need to change this make
sure to change the setting on all the relevant projects:
libpng
zlib
all the test programs
The runtime library settings for each build are as follows:
Release Debug
DLL /MD /MDd
Library /MT /MTd
NOTICE that libpng 1.5.x erroneously used /MD for Debug DLL builds; if
you used the debug builds in your app and you changed your app to use
/MD you will need to change it back to /MDd for libpng 1.6.0 and
later.
The Visual Studio 2010 defaults for a Win32 DLL or Static Library
project are as follows:
Release Debug
DLL /MD /MDd
Static Library /MD /MDd
Also, be sure to build libpng, zlib, and your project all for the same
platform (e.g., 32-bit or 64-bit).

cI know the question is a bit old, but maybe there are people having same difficulties.
In my case 2 steps to solve "unresolved link" (with Visual Studio 16.4.6 2019) issue were:
to compile my project as x86 (as the libraries I was using were built under this architecture) and use 32 bits version of libpng .dll
add zlib (including zlib.h in the code and linking with the corresponding .dll and .lib)
After doing this, it compiled sucessfully.

Related

Unresolved external symbol globalThreadCount when trying to compile a project including openexr

I've cloned the pbrt-v3 repository using Visual Studio 2017. I've tried to compile a project where I included the Transform.h, but I'm getting the following error from the linker:
LNK2019 unresolved external symbol "int __cdecl Imf::globalThreadCount(void)" (?globalThreadCount#Imf##YAHXZ) referenced in function "class pbrt::RGBSpectrum * __cdecl pbrt::ReadImageEXR(class std::basic_string,class std::allocator > const &,int *,int *,class pbrt::Bounds2 *,class pbrt::Bounds2 *)" (?ReadImageEXR#pbrt##YAPEAVRGBSpectrum#1#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##PEAH1PEAV?$Bounds2#H#1#2#Z)
I've compiled and installed openexr using CMake for Visual Studio. I've added
libpbrt.lib
libglog_static.lib
IlmThread-2_2.lib
Half.lib
Iex-2_2.lib
IexMath-2_2.lib
Imath-2_2.lib
as additional dependencies in the project settings. I wasn't able to figure out in which library globalThreadCount is defined. So, which library am I missing?

Why is CoCreateInstanceFromApp missing from an ARM build over an x64 build?

This question does not already have an answer
I know what an unresolved external symbol means - I'm asking specifically why when building as ARM the DirectX functions are missing for my project. When I build my DirectX project for Raspberry Pi I get the below link errors. Why is CoCreateInstFromApp missing only for the ARM build?
The Microsoft documentation on CoCreateInstanceFromApp implies it should simply be present in any Windows executable - this is in fact what I see when building x86 or x64 versions of the same project. It ought to be present, since DirectX does support ARM architecture - or have I missed something?
The project is including d3d11.lib & dxgi.lib, which I presumed it would pick up from the right directory - but get no specific errors about those libraries. The project is C++ in Visual Studio 2017 Pro v15.8.7.
Redacted link error:
DirectXTK_ARM.lib : error LNK2019: unresolved
external symbol __imp_CoCreateInstanceFromApp referenced in function
"long __cdecl CoCreateInstance ...
DirectXTK_ARM.lib : error LNK2019: unresolved
external symbol __imp_PropVariantClear ....
More info, if required:
I have altered this Desktop Duplication sample from Microsoft to do a screen-shot instead of duplication, and thus removed the window code and used DirectXTK for saving the file. This works great on my desktop and on a Minnowboard (x64 Win10 IoT). But if I try and compile for Raspberry PI (ARM) it fails with the link error:
DirectXTK_ARM.lib(WICTextureLoader.obj) : error LNK2019: unresolved
external symbol __imp_CoCreateInstanceFromApp referenced in function
"long __cdecl CoCreateInstance(struct _GUID const &,struct IUnknown
*,unsigned long,struct _GUID const &,void * *)" (?CoCreateInstance##YAJABU_GUID##PAUIUnknown##K0PAPAX#Z)
DirectXTK_ARM.lib(WICTextureLoader.obj) : error LNK2019: unresolved
external symbol __imp_PropVariantClear referenced in function "long
__cdecl `anonymous namespace'::CreateTextureFromWIC(struct ID3D11Device *,struct ID3D11DeviceContext *,struct
IWICBitmapFrameDecode *,unsigned int,enum D3D11_USAGE,unsigned
int,unsigned int,unsigned int,unsigned int,struct ID3D11Resource *
*,struct ID3D11ShaderResourceView * *)" (?CreateTextureFromWIC#?A0x2b71c33d##YAJPAUID3D11Device##PAUID3D11DeviceContext##PAUIWICBitmapFrameDecode##IW4D3D11_USAGE##IIIIPAPAUID3D11Resource##PAPAUID3D11ShaderResourceView###Z)
1
CoCreateInstance and PropVariantClear are part of ole32.lib.
UWP apps should link with the umbrella WindowsApp.lib, but you can also link to umbrella mincore.lib for IoT apps.

Mixing native C++ and C++/CLI

I have a solution which consists of a native C++ DLL and a C++/CLI wrapper. My aim is to create a wrapper in C++/CLI of the native C++ DLL.
Whenever I try to create an instance of a native C++ class within the wrapper, I am met with many linker errors (see below).
2> .NETFramework,Version=v4.0.AssemblyAttributes.cpp
2>NFileOperation.obj : error LNK2028: unresolved token (0A000208) "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "[T2M] void __clrcall `dynamic initializer for 'public: static float * tagVARIANT::* ATL::CVarTypeInfo<float *>::pmField''(void)" (__t2m#???__E?pmField#?$CVarTypeInfo#PAM#ATL##2QQtagVARIANT##PAMQ3###YMXXZ#?A0x22b777aa##YMXXZ)
2>DeskUpdateManaged.obj : error LNK2028: unresolved token (0A00021C) "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "public: bool __clrcall DeskUpdateManaged::Conversion::FileExist(class System::String ^)" (?FileExist#Conversion#DeskUpdateManaged##$$FQ$AAM_NP$AAVString#System###Z)
2>DeskUpdateManaged.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "public: bool __clrcall DeskUpdateManaged::Conversion::FileExist(class System::String ^)" (?FileExist#Conversion#DeskUpdateManaged##$$FQ$AAM_NP$AAVString#System###Z)
2>NFileOperation.obj : error LNK2001: unresolved external symbol "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z)
2>C:\Users\ABGZAMANK\Music\DeskUpdate\Dev\Source\Solution\Debug\DeskUpdateManaged.dll : fatal error LNK1120: 3 unresolved externals
Function call within the C++/CLI to the native C++ DLL:
bool NFileOperation::FileExists(CAtlString sPathName)
{
return CFileOperation::FileExists(sPathName);
}
Is there a more adequate approach to what I am trying to achieve?
Any advice relating to the issue is much appreciated.
It seems that your native C++ code is using ATL/MFC. Assuming you are compiling under VS, go to the C++/CLI project's project properties->Configuration properties->General and select "Use of MFC" and "Use of ATL" to be either static library or shared dll (depending on your project type). This flag will add the necessary include paths, linking paths and libs to your project to make use of ATL/MFC types from within your project. Also, make sure that you are linking your C++/CLI project against your native C++ project to avoid linking errors from your project (easily found in the Linker segment of the project properties in General and Input).

linking error with CMake and Visual Studio 2010

I'm trying to compile osgearth library with VS2010. The library uses CMake, so after setting all dependencies it generates a VS2010 solution file. However when running build in VS I get this linker error (and 200 similar ones)
Error 7 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_ofstream >::`vbase destructor'(void)" (_imp??_D?$basic_ofstream#DU?$char_traits#D#std###std##QAEXXZ) referenced in function "public: virtual void __thiscall osgEarth::DiskCache::setImage(class osgEarth::TileKey const &,struct osgEarth::CacheSpec const &,class osg::Image const *)" (?setImage#DiskCache#osgEarth##UAEXABVTileKey#2#ABUCacheSpec#2#PBVImage#osg###Z) C:\swproj\osgearth-src\src\osgEarth\Caching.obj osgEarth
I'm not very familiar with C++, is there anything else I have to set up?
You're missing a reference to std::ofstream. You either need an #include in one of your files or a reference to the standard library dll in your project.

Linking error while using Visual Studio 2005(VC8)

I am getting a bunch of linking errors while trying to link the release version of an executable(debug version does not have the same issue). Comparing the command line for the link does not reveal any issues.
there are broadly 2 types of errors neither of which I can get a handle on.
The first kind complains about a unresolved external symbol _declspec(dllimport)
As an example:
error LNK2019: unresolved external symbol
"_declspec(dllimport)
public: __thiscall
stlpd_std::basic_string,class stlpd_std::allocator >::basic_string,class stlpd_std::allocator >(class stlpd_std::basic_string,class stlpd_std::allocator > const &)" (_imp??0?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std##QAE#ABV01##Z) referenced in function "public: __thiscall Springfield::generic::runtime_error::runtime_error(class stlpd_std::basic_string,class stlpd_std::allocator > const &)" (??0runtime_error#generic#Springfield##QAE#ABV?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std###Z)
for a more human readable version(replacing all the strings):
error LNK2019: unresolved external symbol
"__declspec(dllimport)
public: __thiscall
string::basic_string,class stlpd_std::allocator >(class string const &)" (_imp??0?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std##QAE#ABV01##Z) referenced in function "public: __thiscall Springfield::generic::runtime_error::runtime_error(class string const &)" (??0runtime_error#generic#Springfield##QAE#ABV?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std###Z
The sceond class of errors complains about
unresolved external symbol __CrtDbgReportW
I hope I can get some kind of insight in dealing with this.
From the errors it looks like you are not including the CRT as one of your linked libraries. Here is a link to the different CRT lib's offered in Visual Studio 2005. Choose the one which is most appropriate and make sure it's in the list of lib's to link against
http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx
It looks like you're either including a file that's been built using the debug settings or you're mixing runtime libraries (DLL and static).