C++ DirectX Create Device Unresolved Externals Symbol - c++

I made a dll for DirectX tools and got stuck with a compilation error (As the title says : Unresolved External Symbol Direct3DCreate9 called from initDevice) when creating the device.
I narrowed down the code to a single line and a single function and the error persists.
#include "stdafx.h"
#include "DirectXTools.h"
#include <stdexcept>
#include <d3d9.h>
using namespace std;
namespace DirectX
{
LPDIRECT3D9 directX;
void initDevice(HWND myWindow) {
directX = Direct3DCreate9(D3D_SDK_VERSION);
}
}
I am a beginner C++ programmer so I assume the problem is very easy to solve.

The solution that some external libraries's .libs require being added through the linker in the project properties.

Related

Creating a C++ .Net Core wrapper for native library results in error LNK2028

I'm trying to create a managed (.net core) C++/CLI wrapper for a native library (Srt) but when referencing methods in the native lib I'm getting 2 build errors. I've referenced the headers srt.h from the native library, tried calling a method named srt_cleanup but get this on build:
error LNK2028: unresolved token (0A00000B) "extern "C" int __cdecl srt_cleanup(void)" (?srt_cleanup##$$J0YAHXZ) referenced in function "public: void __clrcall HeliosMediaStreamCliSrt::SrtReceiver::Stop(void)" (?Stop#SrtReceiver#HeliosMediaStreamCliSrt##$$FQE$AAMXXZ)
error LNK2019: unresolved external symbol "extern "C" int __cdecl srt_cleanup(void)" (?srt_cleanup##$$J0YAHXZ) referenced in function "public: void __clrcall HeliosMediaStreamCliSrt::SrtReceiver::Stop(void)" (?Stop#SrtReceiver#HeliosMediaStreamCliSrt##$$FQE$AAMXXZ)
Sample:
// pch.h
#ifndef PCH_H
#define PCH_H
#include <srt.h>
#include <stdio.h>
#include <tchar.h>
#include <memory>
#include <map>
#include <stdlib.h>
#endif //PCH_H
// SrtReceiver.h
#pragma once
using namespace System;
namespace TestSrt {
public ref class SrtReceiver {
public:
void SrtReceiver::Stop();
private:
};
}
// SrtReceiver.cpp
#include "pch.h"
#include "SrtReceiver.h"
namespace TestSrt {
void SrtReceiver::Stop() {
srt_cleanup();
}
}
Project Configuration:
General -> Configuration Type: Dynamic Library (.dll)
Advanced -> Common Language Runtime Support: .NET Core Runtime Support (/clr:netcore)
Advanced -> .NET Core Target Framework: .NET 5.0
C/C++ -> General -> Common Language Runtime Support: NetCore
I'm pretty rusty with C++ so I'm unfamiliar with the build system and its resulting in confusing errors. I've never tried doing anything with .net core in c++ before as C# is more my speed. This looks like something to do with build properties and the compiler is looking for the wrong internal method names. How would I go about fixing this?
I simply forgot to include the paths to the .lib files in Linker -> Input -> Additional Dependencies: /path/to/srt.lib
Simple, but spent hours of google searching to no avail. Hopefully this helps out other a C++ beginners as I didn't come across it.

PIN with python includes tool. Ambiguous symbol

I'm having the same problem than this post.
Basically I am trying to compile a PIN tool that uses Python.h.
There are some types that are called the same for Windows.h and PIN.h and either of them declared a namespace for them so I'm getting error C2872: 'UINT32' : ambiguous symbol
The problem is that my PIN tool imports PIN.h and Python.h (which imports at the same time Windows.h) and both of them have same name types so the compiler doesn't know what type is each one and i'm getting the ambiguous symbols error
I cant use the solution:
namespace WINDOWS
{
#include <Windows.h>
}
or
namespace PIN
{
#include <PIN.h>
}
Because there are too many reference to them that need to be renamed and that would be a mess (PIN and Windows.h libraries uses UINT32 or CONTEXT a lot of times).
Is there any elegant way to fix this?

Connecting VS Express 2013 to MySQL with Connector C++ 1.1.3 - error LNK2019: unresolved external symbol

Scroll down for (part of) the solution that I found:
I'm on a Windows 8.1, 64 bit laptop
It is my first time trying to connect C++ to MySQL using the mentioned connector.
The error is as follow:
Error 1 error LNK2019: unresolved external symbol "class sql::mysql::MySQL_Driver * __cdecl sql::mysql::get_driver_instance(void)" (?get_driver_instance#mysql#sql##YAPAVMySQL_Driver#12#XZ) referenced in function _main C:\Users\user\documents\visual studio 2013\Projects\Profile\Profile\Profile.obj Profile
This is my main code:
// Profile.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <string>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#define dbHOST "tcp://127.0.0.1:3306"
#define dbUSER "root"
#define dbPASS "root"
#define dbDB "db_test"
using namespace std;
using namespace sql;
int main()
{
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
driver = sql::mysql::get_driver_instance();
con = driver->connect(dbHOST, dbUSER, dbPASS);
delete con;
system("pause");
return 0;
}
I have followed the instructions from this mysql site for the static installation.
I have also Google quite a lot with the error.
Some suggested it could be the connector files different for 64bit and 32bits - I've tried downloading both (they are installed in Program Files and Program Files (x86) accorindgly. but the error persists.
One thing to note, when I link it with the 32bit connector files, it will have a huge load more of errors.
Makes me wonder after all the search, is it that VS Express 2013 is not compatible to connect with MySQL thus far?
I heard ppl saying using the Qt would be easier, but I still want to try this out.
Please let me know if my question is vague or if you need more information.
Thanks in advance!
SOLUTION I FOUND
I don't want to add it as an answer because it does not remedy the question I asked.
Anyway, I found a link which gives fairly simple instructions which has got it to work. Would still appreciate if anyone is willing to look into my original issue.
:)

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.

OpenGL Linking error? Unresolved external glCreateShader()

I'm working on an OpenGL program to test out shaders and trying to compile them. However, the call to glCreateShader() (and other shader calls like glDeleteShader) give the following error:
(this error is from glCreateShader())
Error 3 error LNK2001: unresolved external symbol _pglCreateShader
I'm using Visual Studio 2012 and on windows 7. Got one of the latest nvidia cards including the latest drivers so can't be my OpenGL version.
I'm using the glTools header files for all the helper functions for the OpenGL Superbible 4th edition. Not sure if there is an error in using these files?
I'll post my includes in case this could be of any help as well.
#pragma once
#include <Windows.h>
// Basic C++ includes
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;
// OpenGL specific and GUI includes
#include "shared/gltools.h"
#include "shared/math3d.h"
#include <SOIL.h>
And linker options:
soil.lib;opengl32.lib;gltools.lib;
Oké, the problem has been solved thanks to the answers:
I edited my glTools.h to include 'gl/glew.h' instead of "glee.h", added a ;glew32.lib option to my linker and added glewInit() before entering the main loop. I've also added the GLEW libs,dlls and includes into the appropriate folder and all the functions work like they should! :)
Grab a copy of GLEW to handle extension loading.
Doing it by hand is...annoying.
On Windows, you use WGL, and when using WGL you can't just link against the GL functions directly. All the functions you get are these; you're supposed to dynamically grab the pointer to the GL entry point you want with wglGetProcAddress (as in here) before you can use them.
Basically, OpenGL on Windows is a PITA if you do the GL entrypoint function pointer loading manually. It's much easier to use a utility library to grab the pointers for you, such as GLEW.