Linker errors in Visual C++ LNK2005, LNK2019 - not sure why - c++

I'm trying to build code from the nVidia 9.5 SDK but I get the following linker errors:
>1>NV_D3DCommonDX9U.lib(NV_StringFuncs.obj) : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl std::getline<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_istream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (??$getline#DU?$char_traits#D#std##V?$allocator#D#2##std##YAAAV?$basic_istream#DU?$char_traits#D#std###0#AAV10#AAV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##0##Z) already defined in msvcprtd.lib(MSVCP90D.dll)
1>FogTombScene.obj : error LNK2019: unresolved external symbol "public: struct IDirect3DTexture9 * * __thiscall TextureFactory::CreateTextureFromFile(struct IDirect3DDevice9 *,wchar_t const *,bool)" (?CreateTextureFromFile#TextureFactory##QAEPAPAUIDirect3DTexture9##PAUIDirect3DDevice9##PB_W_N#Z) referenced in function "public: virtual long __thiscall FogTombScene::RestoreDeviceObjects(void)" (?RestoreDeviceObjects#FogTombScene##UAEJXZ)
1>FogTombScene.obj : error LNK2019: unresolved external symbol "public: long __thiscall LoadXFile::LoadFile(wchar_t const *,bool)" (?LoadFile#LoadXFile##QAEJPB_W_N#Z) referenced in function "public: virtual long __thiscall FogTombScene::RestoreDeviceObjects(void)" (?RestoreDeviceObjects#FogTombScene##UAEJXZ)
1>FogTombScene.obj : error LNK2019: unresolved external symbol "public: long __thiscall LoadXFile::Initialize(struct IDirect3DDevice9 *,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > (__cdecl*)(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,bool),class TextureFactory * *)" (?Initialize#LoadXFile##QAEJPAUIDirect3DDevice9##P6A?AV?$basic_string#_WU?$char_traits#_W#std##V?$allocator#_W#2##std##ABV34#_N#ZPAPAVTextureFactory###Z) referenced in function "public: virtual long __thiscall FogTombScene::RestoreDeviceObjects(void)" (?RestoreDeviceObjects#FogTombScene##UAEJXZ)
1>NV_D3DCommonDX9U.lib(NV_StringFuncs.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::locale::facet::_Register(void)" (__imp_?_Register#facet#locale#std##QAEXXZ) referenced in function "class std::ctype<char> const & __cdecl std::use_facet<class std::ctype<char> >(class std::locale const &)" (??$use_facet#V?$ctype#D#std###std##YAABV?$ctype#D#0#ABVlocale#0##Z)
1>NV_D3DCommonDX9U.lib(NV_StringFuncs.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl std::ctype<char>::_Getcat(class std::locale::facet const * *)" (__imp_?_Getcat#?$ctype#D#std##SAIPAPBVfacet#locale#2##Z) referenced in function "class std::ctype<char> const & __cdecl std::use_facet<class std::ctype<char> >(class std::locale const &)" (??$use_facet#V?$ctype#D#std###std##YAABV?$ctype#D#0#ABVlocale#0##Z)
1>NV_D3DCommonDX9U.lib(NV_StringFuncs.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl std::ctype<unsigned short>::_Getcat(class std::locale::facet const * *)" (__imp_?_Getcat#?$ctype#G#std##SAIPAPBVfacet#locale#2##Z) referenced in function "class std::ctype<unsigned short> const & __cdecl std::use_facet<class std::ctype<unsigned short> >(class std::locale const &)" (??$use_facet#V?$ctype#G#std###std##YAABV?$ctype#G#0#ABVlocale#0##Z)
I have no idea why I'm gettin gthese terrors because I'm 99% sure I've setup my directories correctly.
For example one of the functions it can't find is TextureFactory::CreateTextureFromFile yet I have the directory in which that function is declared and defined already added to the include/source directory in the Visual C++ settings.
Top of the file looks like this:
#include "nvafx.h"
//#include "NV_D3DCommon\NV_D3DCommonDX9.h" // include library sub-headers
// and add .lib to linker inputs
//#include "NV_D3DMesh\NV_D3DMesh.h"
//#include "shared\NV_Common.h"
//#include "shared\NV_Error.h"
#include "FogTombScene.h"
#include "ThicknessRenderProperties.h"
#include "ThicknessRenderProperties8BPC.h"
#include "../camera.h"
// When the following two lines are added I get more LNK2005 (understandable)
// but I also still get the same LNK2019 errors as above
#include "texturefactory.h"
#include "texturefactory.cpp"
More to the point if I say #include "TextureFactory.h" and #include "texturefactory.cpp" at the top of the file in which I'm getting these errors then there can be no room for ambiguity, the functions are defined and basically copy+pasted into the same source file generating the linker error, yet I still get the linker error.
Am I overlooking something?

That happend because:
1 The source of .lib is missing like said tomzx or Daniel,
or
2 The .lib it was compiled in another version of Visual C
Try to create your file like a .c (NOT a .cpp) in notepad, then you add to your project the file .c (project...add to project...file)
Sorry I'm Mexican, I don't speak english.
Saludos.

You have added the files in the include/source folder, but what about the libraries? Looks more like a library problem to me (missing .lib).
Maybe you also need to list your dependencies in Linker - Input.
LNK2005 generally means that additionnal libraries aren't correctly linked.

You probably forgot to link to one of the SDKs lib files. You can set this in your project properties under Linker->Input->Additional Dependencies or use a #pragma comment.

Related

Unresolved External Symbol errors while using Catch2

I am trying to do Catch2 Unit Testing in Visual Studio. I have created a small test project to practice. When I try to compile this test project, I get a linker error. I am now trying to diagnose this linker error, but the Catch2.hpp header file contains thousands of lines of code. My hope is that someone who is more familiar with Catch2 or unit testing in general can diagnose what the issue is.
I will describe the process by which I created this project. I created a new project in a new solution. I have 4 files, all in the same directory, listed below.
The class I want to test:
//a.h
#pragma once
class A {
friend int A_Tester_Func1(A a);
public:
A(int num) : my_num_(num) {
}
private:
int my_num_;
};
The test:
//atester.cpp
#pragma once
#include "catch.hpp"
#include "a.h"
int A_Tester_Func1(A a) {
return a.my_num_;
}
TEST_CASE("a contains a positive integer", "[a]") {
//...
A a(3);
REQUIRE(A_Tester_Func1(a) == 3);
}
The main function that runs the tests:
//tester.cpp
#define CATCH_CONFIG_MAIN
#include "catch.hpp" // this should create the main function
The Catch2 Testing Framework:
// catch.hpp
/*
* Catch v2.13.2
* Generated: 2020-10-07 11:32:53.302017
*/
//~17-18k lines of code that from Catch2
#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
When I try to compile this code in Visual Studio using the Local Windows Debugger button, I get a bunch of Unresolved External Symbol linker errors. I believe I read somewhere that Catch2 is "partially compiled." That may have something to do with it, but I don't know. Following this guide (StackOverflow: Best practices for Unit testing with Catch2 in Visual Studio) has worked for me, but I'm trying to understand why the small example above is not successfully linking.
I have included the linker errors below for completeness, although I feel that they will probably not be necessary for the question.
1>atester.obj : error LNK2019: unresolved external symbol "public: __thiscall Catch::StringRef::StringRef(char const *)" (??0StringRef#Catch##QAE#PBD#Z) referenced in function "public: class Catch::BinaryExpr<int const &,int const &> const __thiscall Catch::ExprLhs<int const &>::operator==<int>(int const &)" (??$?8H#?$ExprLhs#ABH#Catch##QAE?BV?$BinaryExpr#ABHABH#1#ABH#Z)
1>atester.obj : error LNK2019: unresolved external symbol "struct Catch::ITestInvoker * __cdecl Catch::makeTestInvoker(void (__cdecl*)(void))" (?makeTestInvoker#Catch##YAPAUITestInvoker#1#P6AXXZ#Z) referenced in function "void __cdecl `anonymous namespace'::`dynamic initializer for 'autoRegistrar1''(void)" (??__EautoRegistrar1#?A0xf9ca9c7d##YAXXZ)
1>atester.obj : error LNK2019: unresolved external symbol "public: __thiscall Catch::NameAndTags::NameAndTags(class Catch::StringRef const &,class Catch::StringRef const &)" (??0NameAndTags#Catch##QAE#ABVStringRef#1#0#Z) referenced in function "void __cdecl `anonymous namespace'::`dynamic initializer for 'autoRegistrar1''(void)" (??__EautoRegistrar1#?A0xf9ca9c7d##YAXXZ)
1>atester.obj : error LNK2019: unresolved external symbol "public: __thiscall Catch::AutoReg::AutoReg(struct Catch::ITestInvoker *,struct Catch::SourceLineInfo const &,class Catch::StringRef const &,struct Catch::NameAndTags const &)" (??0AutoReg#Catch##QAE#PAUITestInvoker#1#ABUSourceLineInfo#1#ABVStringRef#1#ABUNameAndTags#1##Z) referenced in function "void __cdecl `anonymous namespace'::`dynamic initializer for 'autoRegistrar1''(void)" (??__EautoRegistrar1#?A0xf9ca9c7d##YAXXZ)
1>atester.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall Catch::AutoReg::~AutoReg(void)" (??1AutoReg#Catch##UAE#XZ) referenced in function "void __cdecl `anonymous namespace'::`dynamic atexit destructor for 'autoRegistrar1''(void)" (??__FautoRegistrar1#?A0xf9ca9c7d##YAXXZ)
1>atester.obj : error LNK2019: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl Catch::StringMaker<int,void>::convert(int)" (?convert#?$StringMaker#HX#Catch##SA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl Catch::Detail::stringify<int>(int const &)" (??$stringify#H#Detail#Catch##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABH#Z)
1>atester.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall Catch::ITransientExpression::~ITransientExpression(void)" (??1ITransientExpression#Catch##UAE#XZ) referenced in function "public: virtual __thiscall Catch::BinaryExpr<int const &,int const &>::~BinaryExpr<int const &,int const &>(void)" (??1?$BinaryExpr#ABHABH#Catch##UAE#XZ)
1>atester.obj : error LNK2019: unresolved external symbol "void __cdecl Catch::formatReconstructedExpression(class std::basic_ostream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class Catch::StringRef,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?formatReconstructedExpression#Catch##YAXAAV?$basic_ostream#DU?$char_traits#D#std###std##ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##3#VStringRef#1#1#Z) referenced in function "private: virtual void __thiscall Catch::BinaryExpr<int const &,int const &>::streamReconstructedExpression(class std::basic_ostream<char,struct std::char_traits<char> > &)const " (?streamReconstructedExpression#?$BinaryExpr#ABHABH#Catch##EBEXAAV?$basic_ostream#DU?$char_traits#D#std###std###Z)
1>atester.obj : error LNK2019: unresolved external symbol "public: __thiscall Catch::AssertionHandler::AssertionHandler(class Catch::StringRef const &,struct Catch::SourceLineInfo const &,class Catch::StringRef,enum Catch::ResultDisposition::Flags)" (??0AssertionHandler#Catch##QAE#ABVStringRef#1#ABUSourceLineInfo#1#V21#W4Flags#ResultDisposition#1##Z) referenced in function "void __cdecl ____C_A_T_C_H____T_E_S_T____0(void)" (?____C_A_T_C_H____T_E_S_T____0##YAXXZ)
1>atester.obj : error LNK2019: unresolved external symbol "public: void __thiscall Catch::AssertionHandler::handleExpr(struct Catch::ITransientExpression const &)" (?handleExpr#AssertionHandler#Catch##QAEXABUITransientExpression#2##Z) referenced in function "void __cdecl ____C_A_T_C_H____T_E_S_T____0(void)" (?____C_A_T_C_H____T_E_S_T____0##YAXXZ)
1>atester.obj : error LNK2019: unresolved external symbol "public: void __thiscall Catch::AssertionHandler::handleUnexpectedInflightException(void)" (?handleUnexpectedInflightException#AssertionHandler#Catch##QAEXXZ) referenced in function __catch$?____C_A_T_C_H____T_E_S_T____0##YAXXZ$0
1>atester.obj : error LNK2019: unresolved external symbol "public: void __thiscall Catch::AssertionHandler::complete(void)" (?complete#AssertionHandler#Catch##QAEXXZ) referenced in function __catch$?____C_A_T_C_H____T_E_S_T____0##YAXXZ$0
1>MSVCRTD.lib(exe_main.obj) : error LNK2019: unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
What is causing these errors? How do I fix these errors while keeping catch.hpp in the same project as my source files?
In a .cpp file, add this to make the project a Catch2 test runner:
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
Read more at Supplying main() yourself
I ran into the same problem.
You need to keep #define CATCH_CONFIG_MAIN in the first line of the file, especially before other #include.
atester.cpp must not have the #pragma once directive. It's for header files, and while it may not be your source of trouble, it simply doesn't belong. Since you're not providing enough detail (namely: where's the minimized project file?), I have to be conservative here.
It seems that tester.cpp is not part of the project that you're building. Just because it's a file that exists on disk doesn't mean it's automatically picked up. You have to manually add it to the MSVC project. That's all there's to it. I use Catch2 with MSVS all the time and that's all it takes to make it work.

Trouble installing the Stanford C++ Libraries (graph, BasicGraph classes) [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I am having trouble installing the Stanford C++ Libraries, in particular, the Graph related libraries that I need to use for a project. I am using the Visual Studio IDE, Eclipse IDE, so instructions tailored to either would be appreciated.
I have done the following already:
-> Downloaded and unzipped the library at https://stanford.edu/~stepp/cppdoc/
-> selected the 'collections' folder in StanfordCPPLib as #include directory for Eclipse/Visual Studio
-> things seem to work until this point, and #include works. But During compile time, a ton of other 'unresolved inclusions' occur.
Please can someone who has actually installed the library/willing to do so, help me to do the same. I have spent quite a bit of time trying to solve this myself, and this is a major bottleneck.
Specs: Windows 10 Home
MY CODE:
#include "pch.h"
#include <iostream>
#include <collections/basicgraph.h>
using namespace std;
int main() {
BasicGraph g;
g.addVertex("1");
g.addVertex("2");
g.addEdge("1", "2");
cout<< g.getVertex("1")->name <<endl;
//boost::optional<int>;
return 0;
}
RESULT:
1>------ Build started: Project: IsolationBranchingImplementation, Configuration: Debug Win32 ------
1>main.cpp
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl stanfordcpplib::staticInitializeLibrary(void)" (?staticInitializeLibrary#stanfordcpplib##YAXXZ) referenced in function "public: __thiscall stanfordcpplib::StanfordCppLibraryInitializer::StanfordCppLibraryInitializer(void)" (??0StanfordCppLibraryInitializer#stanfordcpplib##QAE#XZ)
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?error##YAXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "private: void __thiscall Vector<struct Map<class EdgeGen<void *,void *> *,bool>::iterator::NodeMarker>::checkIndex(int,int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)const " (?checkIndex#?$Vector#UNodeMarker#iterator#?$Map#PAV?$EdgeGen#PAXPAX##_N####ABEXHHHV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
1>main.obj : error LNK2019: unresolved external symbol "double __cdecl stringToReal(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?stringToReal##YANABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "public: virtual void __thiscall BasicGraphGen<void *,void *>::scanArcData(class TokenScanner &,class EdgeGen<void *,void *> *,class EdgeGen<void *,void *> *)" (?scanArcData#?$BasicGraphGen#PAXPAX##UAEXAAVTokenScanner##PAV?$EdgeGen#PAXPAX##1#Z)
1>main.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall TokenScanner::getStringValue(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?getStringValue#TokenScanner##QBE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABV23##Z) referenced in function "private: class VertexGen<void *,void *> * __thiscall Graph<class VertexGen<void *,void *>,class EdgeGen<void *,void *> >::scanNode(class TokenScanner &)" (?scanNode#?$Graph#V?$VertexGen#PAXPAX##V?$EdgeGen#PAXPAX####AAEPAV?$VertexGen#PAXPAX##AAVTokenScanner###Z)
1>main.obj : error LNK2019: unresolved external symbol "public: enum TokenScanner::TokenType __thiscall TokenScanner::getTokenType(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?getTokenType#TokenScanner##QBE?AW4TokenType#1#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "private: class VertexGen<void *,void *> * __thiscall Graph<class VertexGen<void *,void *>,class EdgeGen<void *,void *> >::scanNode(class TokenScanner &)" (?scanNode#?$Graph#V?$VertexGen#PAXPAX##V?$EdgeGen#PAXPAX####AAEPAV?$VertexGen#PAXPAX##AAVTokenScanner###Z)
1>main.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall TokenScanner::nextToken(void)" (?nextToken#TokenScanner##QAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) referenced in function "public: virtual void __thiscall BasicGraphGen<void *,void *>::scanArcData(class TokenScanner &,class EdgeGen<void *,void *> *,class EdgeGen<void *,void *> *)" (?scanArcData#?$BasicGraphGen#PAXPAX##UAEXAAVTokenScanner##PAV?$EdgeGen#PAXPAX##1#Z)
1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall TokenScanner::saveToken(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?saveToken#TokenScanner##QAEXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "public: virtual void __thiscall BasicGraphGen<void *,void *>::scanArcData(class TokenScanner &,class EdgeGen<void *,void *> *,class EdgeGen<void *,void *> *)" (?scanArcData#?$BasicGraphGen#PAXPAX##UAEXAAVTokenScanner##PAV?$EdgeGen#PAXPAX##1#Z)
1>C:\Users\Aditya Tyagi\source\repos\IsolationBranchingImplementation\Debug\IsolationBranchingImplementation.exe : fatal error LNK1120: 7 unresolved externals
1>Done building project "IsolationBranchingImplementation.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Based on the error, it seems to be missing the library/implementations that it needs to link with to produce the executable. The library in the link that you provided, it's distributed as raw source. What you would have to do is to either incorporate that whole library into your project so that you can include and build it together with your own codes. Or you can build it as a separate project that would create a static library, then you can include its headers like you're currently doing and then link your program with the library that it produced.
Something like this:
MyProject\
main.cpp
stanfordlib\
collections\
graph.h
graph.cpp
....
then in your code include the library like this,
#include "stanfordlib/collections/graph.h"
This will allow your project to compile the lib and link it with your code.

Including OpenVDB in DLL; Linking errors with Visual Studio 2015

I am trying to compile, in Visual Studio 2015, a DLL that I am making which acts as a C-compatible wrapper around some functionality from OpenVDB, making it usable in an existing C project. When I build, however, I get the following Linker Errors:
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class std::basic_streambuf<char,struct std::char_traits<char> > > __thiscall openvdb::v4_0_1::io::MappedFile::createBuffer(void)const " (__imp_?createBuffer#MappedFile#io#v4_0_1#openvdb##QBE?AV?$shared_ptr#V?$basic_streambuf#DU?$char_traits#D#std###std###std##XZ) referenced in function "private: void __thiscall openvdb::v4_0_1::tree::LeafBuffer<float,3>::doLoad(void)const " (?doLoad#?$LeafBuffer#M$02#tree#v4_0_1#openvdb##ABEXXZ)
Error LNK2019 unresolved external symbol "__declspec(dllimport) class std::shared_ptr<class openvdb::v4_0_1::io::StreamMetadata> __cdecl openvdb::v4_0_1::io::getStreamMetadataPtr(class std::ios_base &)" (__imp_?getStreamMetadataPtr#io#v4_0_1#openvdb##YA?AV?$shared_ptr#VStreamMetadata#io#v4_0_1#openvdb###std##AAVios_base#5##Z) referenced in function "void __cdecl openvdb::v4_0_1::io::readCompressedValues<float,class openvdb::v4_0_1::util::NodeMask<3> >(class std::basic_istream<char,struct std::char_traits<char> > &,float *,unsigned int,class openvdb::v4_0_1::util::NodeMask<3> const &,bool)" (??$readCompressedValues#MV?$NodeMask#$02#util#v4_0_1#openvdb###io#v4_0_1#openvdb##YAXAAV?$basic_istream#DU?$char_traits#D#std###std##PAMIABV?$NodeMask#$02#util#12#_N#Z)
Error LNK2019 unresolved external symbol "__declspec(dllimport) void __cdecl openvdb::v4_0_1::io::setStreamMetadataPtr(class std::ios_base &,class std::shared_ptr<class openvdb::v4_0_1::io::StreamMetadata> &,bool)" (__imp_?setStreamMetadataPtr#io#v4_0_1#openvdb##YAXAAVios_base#std##AAV?$shared_ptr#VStreamMetadata#io#v4_0_1#openvdb###5#_N#Z) referenced in function "private: void __thiscall openvdb::v4_0_1::tree::LeafBuffer<float,3>::doLoad(void)const " (?doLoad#?$LeafBuffer#M$02#tree#v4_0_1#openvdb##ABEXXZ)
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: static class std::shared_ptr<class openvdb::v4_0_1::math::Transform> __cdecl openvdb::v4_0_1::math::Transform::createLinearTransform(class openvdb::v4_0_1::math::Mat4<double> const &)" (__imp_?createLinearTransform#Transform#math#v4_0_1#openvdb##SA?AV?$shared_ptr#VTransform#math#v4_0_1#openvdb###std##ABV?$Mat4#N#234##Z) referenced in function "public: static class std::shared_ptr<class openvdb::v4_0_1::math::Transform> __cdecl OpenVDB_c::LinearTransform(double,double,double,double,double,double,double,double,double,double,double,double,double,double,double,double)" (?LinearTransform#OpenVDB_c##SA?AV?$shared_ptr#VTransform#math#v4_0_1#openvdb###std##NNNNNNNNNNNNNNNN#Z)
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: void __thiscall openvdb::v4_0_1::GridBase::setTransform(class std::shared_ptr<class openvdb::v4_0_1::math::Transform>)" (__imp_?setTransform#GridBase#v4_0_1#openvdb##QAEXV?$shared_ptr#VTransform#math#v4_0_1#openvdb###std###Z) referenced in function __catch$?setGridTransform#OpenVDB_c##QAE_NHV?$shared_ptr#VTransform#math#v4_0_1#openvdb###std###Z$0
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class openvdb::v4_0_1::GridBase> __thiscall openvdb::v4_0_1::io::File::readGrid(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?readGrid#File#io#v4_0_1#openvdb##QAE?AV?$shared_ptr#VGridBase#v4_0_1#openvdb###std##ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##6##Z) referenced in function "public: int __thiscall OpenVDB_c::readGrid(int,char *)" (?readGrid#OpenVDB_c##QAEHHPAD#Z)
Error LNK2001 unresolved external symbol "public: virtual class std::shared_ptr<class openvdb::v4_0_1::io::Archive> __thiscall openvdb::v4_0_1::io::File::copy(void)const " (?copy#File#io#v4_0_1#openvdb##UBE?AV?$shared_ptr#VArchive#io#v4_0_1#openvdb###std##XZ)
Error LNK2001 unresolved external symbol "public: virtual void __thiscall openvdb::v4_0_1::io::File::write(class std::vector<class std::shared_ptr<class openvdb::v4_0_1::GridBase const >,class std::allocator<class std::shared_ptr<class openvdb::v4_0_1::GridBase const > > > const &,class openvdb::v4_0_1::MetaMap const &)const " (?write#File#io#v4_0_1#openvdb##UBEXABV?$vector#V?$shared_ptr#$$CBVGridBase#v4_0_1#openvdb###std##V?$allocator#V?$shared_ptr#$$CBVGridBase#v4_0_1#openvdb###std###2##std##ABVMetaMap#34##Z)
Error LNK2001 unresolved external symbol "__declspec(dllimport) private: static union half::uif const * const half::_toFloat" (__imp_?_toFloat#half##0QBTuif#1#B) C:\Users\t00001657\documents\visual studio 2015\Projects\OVDBC\OVDBC\ovdbc.obj 1
OpenVDB and all of its dependencies are in the include folder, whose directory is added to additional include directories, and this is my current list of Additional Dependencies under the Linker options:
blosc.lib
cppunit.lib
glew32.lib
glfw3.lib
Half.lib
Iex-2_2.lib
IexMath-2_2.lib
IlmImf-2_2.lib
IlmImfUtil-2_2.lib
IlmThread-2_2.lib
Imath2_2.lib
openvdb.lib
tbb.lib
tbb_debug.lib
tbb_preview.lib
tbb_preview_debug.lib
tbbmalloc.lib
tbbmalloc_debug.lib
tbbproxy.lib
zlibstaticd.lib
I can't seem to find any information on compiling with OpenVDB in Visual Studio that covers this kind of error, and am pretty stumped as to what I could be forgetting.
It turned out to be a combination of a couple problems:
My OpenVDB binaries were compiled with OPENVDB_3_ABI_COMPATIBLE defined, and so were using the boost version of shared_ptr instead of the std version, but I hadn't defined OPENVDB_3_ABI_COMPATIBLE when trying to build my project, so it was trying to build using the std version; hence, undefined externals.
I hadn't defined OPENEXR_DLL and HALF_EXPORTS, which is evidently required when building with those libraries, unbeknownst to me.
I was compiling with the /MT option instead of the /MDd option used by half.lib
In the end, all I needed to do was define OPENEXR_DLL, HALF_EXPORTS, and OPENVDB_3_ABI_COMPATIBLE, and switch the build option to /MDd.
Try to use Vcpkg.
It supports visual studio 2015,2017
https://github.com/Microsoft/vcpkg
It's easy to use like yum in Linux.

How to compile a c++ program that uses both windows.h and google glog (glog/logging.h)?

I have two libraries A and B. Library B is my own library and I need "windows.h" in it. Also for some functions I need to use a third-party library A. A uses google logging library and here is the problem :
The first error was this :
Severity Code Description Project File Line Error C1189 #error: ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h
I defined GLOG_NO_ABBREVIATED_SEVERITIES before "A.h", but after that strange linking errors appeared. I have tested all solutions suggested here but none of them works.
Is there any other ways to use glog in a project that uses "windows.h"?
EDIT :
The linker errors are :
error LNK2019: unresolved external symbol "__declspec(dllimport) public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(char)" (__imp_?fill#?$basic_ios#DU?$char_traits#D#std###std##QAEDD#Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char>,char>(class std::basic_ostream<char,struct std::char_traits<char> > &,struct std::_Fillobj<char> const &)" (??$?6DU?$char_traits#D#std##D#std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#ABU?$_Fillobj#D#0##Z)
error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(class std::ios_base & (__cdecl*)(class std::ios_base &))" (__imp_??6?$basic_ostream#DU?$char_traits#D#std###std##QAEAAV01#P6AAAVios_base#1#AAV21##Z#Z) referenced in function _getHtsLables
error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(double)" (__imp_??6?$basic_ostream#DU?$char_traits#D#std###std##QAEAAV01#N#Z) referenced in function "public: virtual void __thiscall AD3::FactorDense::Print(class std::basic_ostream<char,struct std::char_traits<char> > &)" (?Print#FactorDense#AD3##UAEXAAV?$basic_ostream#DU?$char_traits#D#std###std###Z)
fatal error LNK1120: 3 unresolved externals
Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include <windows.h>
#include <glog/logging.h>
Add GLOG_NO_ABBREVIATED_SEVERITIES in preprocessor definitions in Visual Studio, i.e. Project > Properties > C/C++ > Preprocessor.
I have recompiled A after adding GLOG_NO_ABBREVIATED_SEVERITIES, but nothing changed. But the problem solved by reordering the inclusion of "A.h" and "windows.h". When I include "A.h" before "windows.h" no error appears!!! I can not understand what was the real cause of linker errors! – payman

QT 5.6 static unresolved external symbol

I'm developing a small Application using a QWidget and statically linking Qt 5.6. I'm using VS12 at moment.
#include <QMainWindow>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
w.show();
return a.exec();
}
It compiles fine but I'm getting linker errors.
1>libGLESv2d.lib(global_state.obj) : error LNK2019: unresolved external symbol "unsigned long __cdecl CreateTLSIndex(void)" (?CreateTLSIndex##YAKXZ) referenced in function "struct A0x6526a104::Current * __cdecl `anonymous namespace'::GetCurrentData(void)" (?GetCurrentData#?A0x6526a104##YAPAUCurrent#1#XZ)
1>libGLESv2d.lib(global_state.obj) : error LNK2019: unresolved external symbol "bool __cdecl DestroyTLSIndex(unsigned long)" (?DestroyTLSIndex##YA_NK#Z) referenced in function _DllMain_ANGLE#12
1>libGLESv2d.lib(global_state.obj) : error LNK2019: unresolved external symbol "bool __cdecl SetTLSValue(unsigned long,void *)" (?SetTLSValue##YA_NKPAX#Z) referenced in function "struct A0x6526a104::Current * __cdecl `anonymous namespace'::AllocateCurrent(void)" (?AllocateCurrent#?A0x6526a104##YAPAUCurrent#1#XZ)
1>libGLESv2d.lib(global_state.obj) : error LNK2019: unresolved external symbol "void * __cdecl GetTLSValue(unsigned long)" (?GetTLSValue##YAPAXK#Z) referenced in function "void __cdecl `anonymous namespace'::DeallocateCurrent(void)" (?DeallocateCurrent#?A0x6526a104##YAXXZ)
1>libGLESv2d.lib(Program.obj) : error LNK2019: unresolved external symbol "bool __cdecl sh::InterpolationTypesMatch(enum sh::InterpolationType,enum sh::InterpolationType)" (?InterpolationTypesMatch#sh##YA_NW4InterpolationType#1#0#Z) referenced in function "private: static bool __cdecl gl::Program::linkValidateVaryings(class gl::InfoLog &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct sh::Varying const &,struct sh::Varying const &)" (?linkValidateVaryings#Program#gl##CA_NAAVInfoLog#2#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABUVarying#sh##2#Z)
1>libGLESv2d.lib(Program.obj) : error LNK2019: unresolved external symbol "public: struct sh::ShaderVariable & __thiscall sh::ShaderVariable::operator=(struct sh::ShaderVariable const &)" (??4ShaderVariable#sh##QAEAAU01#ABU01##Z) referenced in function "private: bool __thiscall gl::Program::linkAttributes(class gl::InfoLog &,class gl::AttributeBindings const &,class gl::Shader const *)" (?linkAttributes#Program#gl##AAE_NAAVInfoLog#2#ABVAttributeBindings#2#PBVShader#2##Z)
1>libGLESv2d.lib(Program.obj) : error LNK2019: unresolved external symbol "public: __thiscall sh::Attribute::Attribute(void)" (??0Attribute#sh##QAE#XZ) referenced in function "public: __thiscall gl::Program::Program(class rx::ProgramImpl *,class gl::ResourceManager *,unsigned int)" (??0Program#gl##QAE#PAVProgramImpl#rx##PAVResourceManager#1#I#Z)
1>libGLESv2d.lib(Program.obj) : error LNK2019: unresolved external symbol "public: __thiscall sh::Attribute::~Attribute(void)" (??1Attribute#sh##QAE#XZ) referenced in function "public: __thiscall gl::Program::Program(class rx::ProgramImpl *,class gl::ResourceManager *,unsigned int)" (??0Program#gl##QAE#PAVProgramImpl#rx##PAVResourceManager#1#I#Z)
1>libGLESv2d.lib(ProgramImpl.obj) : error LNK2001: unresolved external symbol "public: __thiscall sh::Attribute::~Attribute(void)" (??1Attribute#sh##QAE#XZ)
1>libGLESv2d.lib(Program.obj) : error LNK2019: unresolved external symbol "public: struct sh::Attribute & __thiscall sh::Attribute::operator=(struct sh::Attribute const &)" (??4Attribute#sh##QAEAAU01#ABU01##Z) referenced in function "void __cdecl std::_Fill<struct sh::Attribute *,struct sh::Attribute>(struct sh::Attribute *,struct sh::Attribute *,struct sh::Attribute const &)" (??$_Fill#PAUAttribute#sh##U12##std##YAXPAUAttribute#sh##0ABU12##Z)
I have included the following libs:
winmm.lib
imm32.lib
Ws2_32.lib
opengl32.lib
Qt5Guid.lib
Qt5Widgetsd.lib
qtpcred.lib
qtharfbuzzngd.lib
Qt5PlatformSupportd.lib
qwindowsd.lib
libEGLd.lib
libGLESv2d.lib
qtfreetyped.lib
Qt5Cored.lib
And the funny thing is that if use QtCreator it compiles,links and runs just fine.
What I saw is that QtCreator adds the following compile flags:
-DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENGL_ES_2 -DQT_OPENGL_ES_2_ANGLE -DQT_OPENGL_ES_2_ANGLE_STATIC -DGL_APICALL= -DEGLAPI=
I tried them in my project but it does not change anything.
What am I missing? What do I need to make the program link?
I found it. This is the list of libs you need to make it work:
winmm.lib
imm32.lib
Ws2_32.lib
Qt5Guid.lib
Qt5Widgetsd.lib
qtpcred.lib
qtharfbuzzngd.lib
Qt5PlatformSupportd.lib
qwindowsd.lib
libEGLd.lib
libGLESv2d.lib
qtfreetyped.lib
Qt5Cored.lib
+ preprocessord.lib
+ translatord.lib
+ d3d9.lib
+ dxguid.lib
opengl32.lib is not needed.
I still have no idea why QtCreator knows what libs are needed and why VS2013 does not.
Thanks for your help.
As far as I can tell the linker is complaining about this line of code. Looking at what that file is including seems to suggest dependence on libANGLE.
After a lot of Googling I found that CreateTLS() seems to be defined in libANGLE common, which can be found here.
I'm not sure in which particular Lib or DLL those definitions end up but looking into the build scripts would definitely reveal it (sorry, I don't have time to do that atm). But the symbols in the original question are definitely in one of the Libs provided by libANGLE.
this page suggests that all you need to do is add libEGLd.lib and libGLESv2.lib to your linker line, which is already the case, but you should check that you also have the DLLs too. Note point 3, quoted from the linked page, below:
Copy libEGL.dll and libGLESv2.dll from the build output directory (see Building ANGLE) into your application folder.
If you add the DLLs to your solution you can automate copying them to the destination directory..