Unresolved external symbol _IID_IDXGIFactory - c++

I create Console Application in VC++ 2010, and add the following code to it:
#include <d3d10.h>
#include <d3dx10.h>
#include <DxErr.h>
#pragma comment(lib, "d3d10.lib")
#pragma comment(lib, "d3dx10.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "dxerr.lib")
int _tmain(int argc, _TCHAR* argv[])
{
IDXGIFactory* pDXGIFactory;
CreateDXGIFactory(IID_IDXGIFactory, ( void** )&pDXGIFactory);
return 0;
}
Building this project, I have linker error: error LNK2001: unresolved external symbol _IID_IDXGIFactory
Now I create Console Application with MFC support, and add the same code. The build is successful. What is wrong in the first case? Why MFC project is built successfully, and non-MFC project fails?

You need to reference another library, which holds this identifier:
#pragma comment(lib, "windowscodecs.lib")
MSDN says its DXGI.lib but effectively at least Windows SDK 7.0 has it in a different library.

I had the same issue and In my case referencing
#pragma comment(lib, "dxgi.lib") solved the issue.

Related

Set custom EntryPoint for a simple application

I have this simple hello world c++ application:
#include <windows.h>
#include <iostream>
using namespace std;
void test()
{
cout << "Hello world" << endl;
}
I want to use test as my custom entry point. So far I tried to set Linker -> Advanced -> Entrypoint to test But I got lots of lnk2001 errors. Is it possible to somehow remove any main() wmain() WinMain() and use my function with just Visual studio settings?
Using a custom entry point in a Windows app bypasses the entire CRT startup and global C++ initializations. Because of that, it requires not using the CRT, and turning off compiler features that depend on the CRT such as /GS buffer checks and other /RTC run-time error checks.
The following is an example of a minimal app with the custom entry point test.
#include <sdkDdkVer.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
// compile with /GS- lest
// LNK2001: unresolved external symbol #__security_check_cookie#4
//#pragma strict_gs_check(off)
// turn off /RTC*
#pragma runtime_checks("", off)
#pragma comment(linker, "/nodefaultlib /subsystem:windows /ENTRY:test")
int __stdcall test(void)
{
OutputDebugStringA("custom /entry:test\n");
ExitProcess(0);
}
More insight can be found in Raymond Chen's WinMain is just the conventional name for the Win32 process entry point.

linking error/conflict for SendMessageA method

I have built the aws-cpp-sdk the following way:
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Debug -DBUILD_ONLY="s3;sqs;sns"
and after that I ran:
MSBuild.exe INSTALL.vcxproj
Which produced the following files in the "*C:\Program Files\aws-cpp-sdk-all*" directory:
aws-c-common.dll
aws-c-event-stream.dll
aws-checksums.dll
aws-cpp-sdk-access-management.dll
aws-cpp-sdk-access-management.lib
aws-cpp-sdk-cognito-identity.dll
aws-cpp-sdk-cognito-identity.lib
aws-cpp-sdk-core.dll
aws-cpp-sdk-core.lib
aws-cpp-sdk-iam.dll
aws-cpp-sdk-iam.lib
aws-cpp-sdk-sns.dll
aws-cpp-sdk-sns.lib
aws-cpp-sdk-sqs.dll
aws-cpp-sdk-sqs.lib
aws-c-common.lib
aws-c-event-stream.lib
aws-checksums.lib
along with the include directory. I have included all the headers and all the libraries:
#include <aws/core/Aws.h>
#include <aws/core/auth/AWSCredentials.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/utils/logging/DefaultLogSystem.h>
#include <aws/core/utils/logging/AWSLogging.h>
#include <aws/sns/model/PublishRequest.h>
#include <aws/sns/model/PublishResult.h>
#include <aws/s3/model/ListObjectsRequest.h>
#include <aws/core/utils/Outcome.h>
#include <aws/s3/model/Bucket.h>
#include <aws/sqs/SQSClient.h>
#include <aws/sqs/model/SendMessageRequest.h>
#pragma comment( lib, "aws-cpp-sdk-core.lib" )
#pragma comment( lib, "aws-c-common.lib" )
#pragma comment( lib, "aws-c-event-stream.lib" )
#pragma comment( lib, "aws-checksums.lib" )
#pragma comment( lib, "aws-cpp-sdk-core.lib" )
#pragma comment( lib, "aws-cpp-sdk-iam.lib" )
#pragma comment( lib, "aws-cpp-sdk-sqs.lib" )
#pragma comment( lib, "aws-cpp-sdk-sns.lib" )
#pragma comment( lib, "aws-cpp-sdk-cognito-identity.lib" )
#pragma comment( lib, "aws-cpp-sdk-access-management.lib" )
...
Aws::SQS::SQSClient sqs;
Aws::SQS::Model::SendMessageRequest sm_req;
sm_req.SetQueueUrl( "https://sqs.amazonaws.com/123123" );
sm_req.SetMessageBody( stringJSONFormatted.c_str() );
auto sm_out = sqs.SendMessage(sm_req);
if (sm_out.IsSuccess())
Logger::Log( "Message sent successfully to the AWS SQS" );
else
Logger::Log( "FAILED to send message send to AWS SQS" );
But whenever I build this I get:
__declspec(dllimport) public: virtual class Aws::Utils::Outcome<class Aws::SQS::Model::SendMessageResult,class Aws::Client::AWSError<enum Aws::SQS::SQSErrors> >
__cdecl Aws::SQS::SQSClient::SendMessageA(class Aws::SQS::Model::SendMessageRequest const &)const
(__imp_?SendMessageA#SQSClient#SQS#Aws##UEBA?AV?$Outcome#VSendMessageResult#Model#SQS#Aws##V?$AWSError#W4SQSErrors#SQS#Aws###Client#4##Utils#3#AEBVSendMessageRequest#Model#23##Z)
fatal error LNK1120: 1 unresolved externals
I tried everything I could find, I even re-built the library many times with different arguments, but still the same problem persists. it seems it has something do with AWS::SQSClient::SendMessageA name conflicting with some kind of Windows method (but I'm probably wrong). There was one solution which stated, if I define this before the AWS headers, it should build:
#undef GetObject
but still the same error. Any suggestions please?
The problem is that the Windows system headers define the macro SendMessage to expand to either SendMessageA or SendMessageW depending on the existence of the UNICODE macro.
It does this for a lot of functions in the Windows API, which of course means that there will be clashes with other code using symbols that turn out to be macros in Windows.
One possible solution is to #undef SendMessage after #include <windows.h>. Which might not be possible if the code you try to build comes from a third party.
You may want to take a look at this blog post for a detailed explanation.
You may try with:
#undef SendMessage
before including the AWS headers (similarly to the #undef GetObject you cited in your question).

LINKER error: comsupp.lib and comsuppwd.lib

error is:
Error 14 error LNK2005: "void __stdcall _set_com_error_handler(void (__stdcall*)(long,struct IErrorInfo *))" (?_set_com_error_handler##YGXP6GXJPAUIErrorInfo###Z#Z) already defined in comsupp.lib(comsupp.obj) comsuppwd.lib
Did anyone run into this before?
There is a bug in the Visual Studio 2010 header <msclr/marshal.h>.
There is written
#pragma comment(lib, "comsupp.lib")
but compared to <comdef.h> there must be written
#ifdef _NATIVE_WCHAR_T_DEFINED
# ifdef _DEBUG
# pragma comment(lib, "comsuppwd.lib")
# else
# pragma comment(lib, "comsuppw.lib")
# endif
#else
# ifdef _DEBUG
# pragma comment(lib, "comsuppd.lib")
# else
# pragma comment(lib, "comsupp.lib")
# endif
#endif
See also the Lib-section in https://learn.microsoft.com/de-de/cpp/cpp/set-com-error-handler?view=vs-2019
So you have 2 Options
BAD: Edit the msclr/marshal.h in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\msclr\marshal.h. But then all collegues must change their file too.
Change the ProjectSetting Linker -> Input -> Ignore Specific Default Libraries and add commsupp.lib. !!!But attention if you have set the compiler option /Zc: wchar_t- (see C/C++ -> Language -> Treat WChar_t as Built in Type) AND compiling for Release then it must not be ignored!!! So each project configuration may/must be changed differently.
Error is resolved now. The cause of error was a header file: #include <msclr\marshal_cppstd.h> and conversion from System::String^ to std::string(I found a similar issue here):
//commented out following 3 lines and problem solved:
//looks like following type conversion has problems:
#include <msclr\marshal_cppstd.h>
msclr::interop::marshal_context marshal_context_1;
string_TempDir_XMLfiles=marshal_context_1.marshal_as<std::string>(String_Ptr_Destin_Dir_XMLfiles);

C++ Dll linking Curl

I am trying to create a dll which uses the curl library for a very simple function. Everything works just fine, the only problem is, that the curl linking does not seem to work properly.
I use the same linking, preprocessordefines and include directories like in my executable project where it works just fine so i am pretty sure it´s not about my linking or binary files of the libary.
Are there any special properties to link a libary to a dll?
My minimal sample code:
C++ Mainfile:
#include "main.h"
#include <Windows.h>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Info.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Exception.hpp>
namespace CurlDll
{
void CallHost::Try()
{
curlpp::Easy request;
request.setOpt(new curlpp::options::UserAgent("Mozilla/4.0"));
request.setOpt(new curlpp::options::AutoReferer(true));
request.setOpt(new curlpp::options::FollowLocation(true));
request.setOpt(new curlpp::options::Url("http://xml.utrace.de"));
request.perform();
MessageBox(0,"lololowwwwwwwwwwwl", "wqgqwwwwwgq", MB_OK |MB_ICONINFORMATION);
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason)
{return 1;}
Header file:
#ifdef MAIN_EXPORTS
#define MAIN_API __declspec(dllexport)
#else
#define MAIN_API __declspec(dllimport)
#endif
#include <iostream>
namespace CurlDll
{
class CallHost
{
public:
static MAIN_API void Try();
};
}
i get following linking errors #drescherjm
(47 , i will just post a few, i think that shouls be enough)
ERROR 2 error LNK2001: unresolved external Symbol
"__imp__WSAStartup#8".
ERROR 11 error LNK2001: unresolved external Symbol
"__imp__WSAGetLastError#0".
ERROR 33 error LNK2001: unresolved external Symbol
"__imp__setsockopt#20".
The linker errors are telling you that the linker cannot find definitions for these functions: WSAStartup, WSAGetLastError, setsockopt. These functions are defined in the import library Ws2_32.lib. You need to supply that import library to the linker.
This information is given in the documentation for the functions. For instance, the documentation for WSAStartup. At the bottom of the documentation topic is a table listing requirements. Note the required library, Ws2_32.lib.
The symbols WSAStartup, WSAGetLastError and setsocketopt are part of the Windows API, in Ws2_32.lib (e.g. see http://msdn.microsoft.com/en-gb/library/windows/desktop/ms742213(v=vs.85).aspx )
You should include ws2_32.lib as an additional library when you link your DLL. If you're using Visual Studio, it's likely that the search path should already find it; just add it as an additional library.
So actually, I suspect you're not using the exact same linker options compared to your .exe
If you're building a .exe or a .dll, the linker needs to ensure it can resolve ALL known symbols at link time.

OpenCV (CvHaarClassifierCascade*) cvLoad doesn't load, unable to load xml file

I'm trying face detection using OpenCv 2.3. My trying to load "haarcascade_frontalface_alt_tree.xml" on my project, I'm constantly unable to load the xml file.
CvHaarClassifierCascade * pCascade = 0; // the face detector
const char* file ="C:\OpenCV2.3\opencv\data\haarcascades\haarcascade_frontalface_alt_tree.xml" ;
pCascade = (CvHaarClassifierCascade*) cvLoad(file , NULL, NULL, NULL);
if (!pCascade) {
exit(-1); // unable to load xml
}
I believe that I'm experiencing the same problem as this problem.
I have tried to load an image before the cvLoad command, but it didn't help.
I'm using OpenCV 2.3, made my configuration just like in this tutorial.
I'm using those libraries (I presume my configurations are correct, the file exist and can be open using Notepad++).
#include <stdio.h>
#include "opencv2\opencv.hpp"
#include "cv.h"
#include "highgui.h"
//#include "cvaux.h"
using namespace cv;
#pragma comment(lib, "opencv_core230d.lib")
#pragma comment(lib, "opencv_highgui230d.lib")
//#pragma comment(lib, "opencv_contrib230d.lib")
//#pragma comment(lib, "opencv_calib3d230d.lib")
//#pragma comment(lib, "opencv_features2d230d.lib")
//#pragma comment(lib, "opencv_flann230d.lib")
//#pragma comment(lib, "opencv_gpu230d.lib")
#pragma comment(lib, "opencv_haartraining_engined.lib")
#pragma comment(lib, "opencv_imgproc230d.lib")
//#pragma comment(lib, "opencv_legacy230d.lib")
//#pragma comment(lib, "opencv_ml230d.lib")
//#pragma comment(lib, "opencv_objdetect230d.lib")
//#pragma comment(lib, "opencv_video230d.lib")
To narrow down the issue, before calling cvLoad you should check to see if the file exists. Here's one way:
struct stat buf;
int statResult = stat(file,&buf);
if (statResult || buf.st_ino < 0) {
cout << "File not found: " << file << endl;
exit(-2);
}
You'll need to #include <sys/stat.h>
On my system (OS X 10.6.8/OpenCV 2.3), when I attempt to load haarcascade_frontalface_alt_tree.xml or haarcascade_frontalface_alt.xml I get an exception:
OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /Users/steve/Development/opencv2/opencv/modules/core/src/persistence.cpp, line 4857
I think you are using an outdated OpenCV 1 tutorial that doesn't work with the current version of haarcascade_frontalface_alt_tree.xml. Try this OpenCV 2 tutorial instead. This code from that tutorial works for me:
CascadeClassifier face_cascade;
if (!face_cascade.load( file) ) {
cout << "Couldn't load face_cascade" << endl;
exit(-1);
}
cout << "Loaded face_cascade" << endl;
It happens also to me but finally I think I found the problem.
OpenCV has two different libraries *d.lib and *.lib the d means debug.
The problem is you need to setup the proper libraries to your environment (vs in my case) in the proper mode.
d.lib when you are in debug and .lib when you are in release.
Also in my project I need to run it in Release mode to make it work :)
This setup in my vs2009 could be found under Properties, Linker, Input, Additional dependencies.
Best regards
Check that the string with the "haarcascade_frontalface_alt.xml" file name is correct.
I had this problem and the directory separater was not being recognised. I changed the '\' character to '/' and the tutorial worked.
For your info, I was using MacOS 10.8.3 running Parallels with Windows 7, Visual Studio 2012 and opencv 2.44 - I was using the version 2 of the tutorial