DirectX 9 "unresolved external symbol" problem - c++

I have been working on learning DirectX for a couple days and have run into a problem. I have been following a books example and have solved several annoying problems that have come up, but have been unsuccessful at solving my most recent one. The compiler states that I have an unresolved external symbol whenever I try to compile. Here is the error code below.
1>game.obj : error LNK2019: unresolved external symbol "struct IDirect3DSurface9 * __cdecl
LoadSurface(char *,unsigned long)" (?LoadSurface##YAPAUIDirect3DSurface9##PADK#Z) referenced in
function "int __cdecl Game_Init(struct HWND__ *)" (?Game_Init##YAHPAUHWND__###Z)
1>C:\Users\Christopher\Documents\Visual Studio 2008\Projects\Work\Debug\Work.exe : fatal error
LNK1120: 1 unresolved externals
I am running: [compiler: Visual Studios 2008] [Operating system: Windows 7 64bit professional]
Here a sample of the code and where it seem to be taking place. (I hope I gave enough info)
LPDIRECT3DSURFACE9 kitty_image[7];
SPRITE kitty;
LPDIRECT3DSURFACE9 back;
//timing variable
long start = GetTickCount();
//initializes the game
int Game_Init(HWND hwnd)
{
char s[20];
int n;
//set random number seed
srand(time(NULL));
//load the sprite animation
for (n=0; n<6; n++)
{
sprintf(s, "cat%d.bmp",n+1);
kitty_image[n] = LoadSurface(s, D3DCOLOR_XRGB(255,0,255));
if (kitty_image[n] == NULL)
return 0;
}
back = LoadSurface("background.bmp", NULL );
//initialize the sprite's properties
kitty.x = 100;
kitty.y = 150;
kitty.width = 96;
kitty.height = 96;
kitty.curframe = 0;
kitty.lastframe = 5;
kitty.animdelay = 2;
kitty.animcount = 0;
kitty.movex = 8;
kitty.movey = 0;
//return okay
return 1;
}
I have linked both d3d9.lib and d3dx9.lib to my project and have included all neccesary header files that I know of (d3d9.h, d3dx9.h). Any help is greatly appreciated! Thanks in advance!!!

It looks like the linker is complaining that there is no such function LoadSurface. Where did you define it?

Related

How do I configure AlgLib for VS2017?

I am compiling a alglib sample program (with a few changes):
#pragma once
# include "Source\RFLearn.h" \\appropriate header for this simple .cpp program.
# include <LinAlg.h>
# include <stdint.h>
# include <chrono> // for in-game frame clock.
int RFLearn::test_function()
{
alglib::real_2d_array a, b, c;
int n = 2000;
int i, j;
double timeneeded, flops;
// Initialize arrays
a.setlength(n, n);
b.setlength(n, n);
c.setlength(n, n);
for (i = 0; i<n; i++)
for (j = 0; j<n; j++)
{
a[i][j] = alglib::randomreal() - 0.5;
b[i][j] = alglib::randomreal() - 0.5;
c[i][j] = 0.0;
}
// Set global threading settings (applied to all ALGLIB functions);
// default is to perform serial computations, unless parallel execution
// is activated. Parallel execution tries to utilize all cores; this
// behavior can be changed with alglib::setnworkers() call.
alglib::setglobalthreading(alglib::parallel);
// Perform matrix-matrix product.
flops = 2 * pow((double)n, (double)3);
auto timer_start = std::chrono::high_resolution_clock::now();
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 1,
0.0,
c, 0, 0);
auto timer_end = std::chrono::high_resolution_clock::now();
auto duration = timer_end - timer_start;
timeneeded = static_cast<double>(duration.count());
// Evaluate performance
printf("Performance is %.1f GFLOPS\n", (double)(1.0E-9*flops / timeneeded));
return 0;
}
I am confident linAlg is correctly linked (as well as all of its dependencies, particularly ap.h and ap.cpp) (Preferences->C++->AllOptions->Additional Include Directories -> aglib's source directory. Changing the link provides a different set of linker errors. AlgLib is a header only-library so I don't think I need to compile any library and add it in the linker.
When compiling this code I get the errors:
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: double * __thiscall alglib::real_2d_array::operator[](int)" (??Areal_2d_array#alglib##QAEPANH#Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall alglib::real_2d_array::~real_2d_array(void)" (??1real_2d_array#alglib##UAE#XZ)
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: __thiscall alglib::real_2d_array::real_2d_array(void)" (??0real_2d_array#alglib##QAE#XZ)
1>RFLearn.obj : error LNK2001: unresolved external symbol "struct alglib::xparams const & const alglib::parallel" (?parallel#alglib##3ABUxparams#1#B)
1>RFLearn.obj : error LNK2001: unresolved external symbol "void __cdecl alglib::rmatrixgemm(int,int,int,double,class alglib::real_2d_array const &,int,int,int,class alglib::real_2d_array const &,int,int,int,double,class alglib::real_2d_array const &,int,int,struct alglib::xparams)" (?rmatrixgemm#alglib##YAXHHHNABVreal_2d_array#1#HHH0HHHN0HHUxparams#1##Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "double __cdecl alglib::randomreal(void)" (?randomreal#alglib##YANXZ)
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: void __thiscall alglib::ae_matrix_wrapper::setlength(int,int)" (?setlength#ae_matrix_wrapper#alglib##QAEXHH#Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "void __cdecl alglib::setglobalthreading(struct alglib::xparams)" (?setglobalthreading#alglib##YAXUxparams#1##Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "struct alglib::xparams const & const alglib::xdefault" (?xdefault#alglib##3ABUxparams#1#B)
I intuit that the problem lies around here: http://www.alglib.net/translator/man/manual.cpp.html#gs_configuring
but I cannot make heads or tails of it. What's the next step?
I had a similar (not exact) problem and it went away just by adding the compiled the cpp files to my project and set "included in the project" to true.

Getting Linking errors using BLuetoothAPIs.h in vs 2017 and windows 10

Using the following code:
// Bluetooth_test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include "bthdef.h"
#include "BluetoothAPIs.h"
int main()
{
BLUETOOTH_DEVICE_SEARCH_PARAMS bptsp;
// set options for how we want to load our list of BT devices
bptsp.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS);
bptsp.fReturnAuthenticated = TRUE;
bptsp.fReturnRemembered = TRUE;
bptsp.fReturnUnknown = TRUE;
bptsp.fReturnConnected = TRUE;
bptsp.fIssueInquiry = TRUE;
bptsp.cTimeoutMultiplier = 4;
bptsp.hRadio = NULL;
BLUETOOTH_DEVICE_INFO bptdi;
bptdi.dwSize = sizeof(bptdi);
HBLUETOOTH_DEVICE_FIND hFind = BluetoothFindFirstDevice(&bptsp, &bptdi);
BluetoothFindDeviceClose(hFind);
return 0;
}
I get the following errors:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _BluetoothFindFirstDevice#8 referenced in function _main Bluetooth_test D:\VS 2017\repos\Bluetooth_test\Bluetooth_test\Bluetooth_test.obj 1
Error LNK1120 2 unresolved externals Bluetooth_test D:\VS 2017\repos\Bluetooth_test\Debug\Bluetooth_test.exe 1
Error LNK2019 unresolved external symbol _BluetoothFindDeviceClose#4 referenced in function _main Bluetooth_test D:\VS 2017\repos\Bluetooth_test\Bluetooth_test\Bluetooth_test.obj 1
I am pretty new to C++ and I have no clue why it won't compile please help me
Windows API's:
https://learn.microsoft.com/en-us/windows/win32/api/bluetoothapis/nf-bluetoothapis-bluetoothfindfirstdevice
https://learn.microsoft.com/en-us/windows/win32/api/bluetoothapis/nf-bluetoothapis-bluetoothfinddeviceclose
==== EDIT ====
Like Mike Petrichenko said in the comments, the errors won't acure when I add #pragma comment(lib, "Bthprops.lib"); underneath the includes.

Difficulty using Protobuf 3.2 in C++

I'm trying to use Protobuf in C++, but having trouble getting it to do anything meaningful. I'm using Visual Studio 2015.
I built the protobuf library. I'm using the latest version from github.
I have created a .proto file as such:
syntax = "proto3";
package Networking;
message Robot{
message KinematicLinkProto {
string name = 1;
float x_pos = 2;
float y_pos = 3;
float z_pos = 4;
float roll = 5;
float pitch = 6;
float yaw = 7;
float x_scale = 8;
float y_scale = 9;
float z_scale = 10;
}
repeated KinematicLinkProto links = 1;
}
I compile this, and try to add it to a project:
#include "Robot.pb.h"
int main(int argc, char **argv)
{
Networking::Robot robot_message;
return 0;
}
My linker links libprotobuf.lib. I am building it as /MD and libprotobuf is built as /MD.
For some reason, this simple program has the following two linker errors:
Error LNK2019 unresolved external symbol "private: static bool google::protobuf::io::CodedOutputStream::default_serialization_deterministic_" (?default_serialization_deterministic_#CodedOutputStream#io#protobuf#google##0_NA) referenced in function "public: virtual unsigned char * __cdecl Networking::Robot::SerializeWithCachedSizesToArray(unsigned char *)const " (?SerializeWithCachedSizesToArray#Robot#Networking##UEBAPEAEPEAE#Z)
Error LNK2019 unresolved external symbol "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > google::protobuf::internal::fixed_address_empty_string" (?fixed_address_empty_string#internal#protobuf#google##3V?$ExplicitlyConstructed#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###123#A) referenced in function "protected: void __cdecl google::protobuf::internal::RepeatedPtrFieldBase::Clear<class google::protobuf::RepeatedPtrField<class Networking::Robot_KinematicLinkProto>::TypeHandler>(void)" (??$Clear#VTypeHandler#?$RepeatedPtrField#VRobot_KinematicLinkProto#Networking###protobuf#google###RepeatedPtrFieldBase#internal#protobuf#google##IEAAXXZ)
I'm very confused - this is a very simple program. What could I possibly be doing wrong?
EDIT: A colleague compiled proto 3001000. This version does seem to work. I'm curious as to what about 3002000 breaks everything.
If you are using DLL, use
#define PROTOBUF_USE_DLLS

Unable to link with libx264.lib static library

I'm building custom video encoder using x264 as a static library. I've followed this guide in order to build static library. Trying to compile this:
x264_t * setup_encoder(int width, int height){
x264_param_t param;
x264_param_default_preset(&param, "veryfast", "zerolatency");
param.i_threads = 1;
param.i_width = width;
param.i_height = height;
param.i_fps_num = 26;
param.i_fps_den = 1;
// Intra refres:
param.i_keyint_max = 26;
param.b_intra_refresh = 1;
//Rate control:
param.rc.i_rc_method = X264_RC_CRF;
param.rc.f_rf_constant = 25;
param.rc.f_rf_constant = 25;
param.rc.f_rf_constant_max = 35;
//For streaming:
param.b_repeat_headers = 1;
param.b_annexb = 1;
x264_param_apply_profile(&param, "baseline");
return x264_encoder_open(&param);
}
Results in:
main.obj : error LNK2019: unresolved external symbol "int __cdecl x264_param_default_preset(struct x264_param_t *,char const *,char const *)"
main.obj : error LNK2019: unresolved external symbol "int __cdecl x264_param_apply_profile(struct x264_param_t *,char const *)"
main.obj : error LNK2019: unresolved external symbol "struct x264_t * __cdecl x264_encoder_open_136(struct x264_param_t *)"
%PROJECT_DIR%: fatal error LNK1120: 3 unresolved externals
Linker scans libx264.lib, but can't find anything inside.
Searching .\lib\libx264.lib:
With dumpbin /HEADERS I can actually find the declaration I need, but linker is unable to do it.
SECTION HEADER #38
.text name
0 physical address
0 virtual address
E60 size of raw data
930C file pointer to raw data (0000930C to 0000A16B)
D219 file pointer to relocation table
0 file pointer to line numbers
40 number of relocations
0 number of line numbers
60501020 flags
Code
COMDAT; sym= x264_param_default_preset
16 byte align
Execute Read
Enviroment is Visual Studio 2012 with Intel Compiler 14 on Windows 8 64-bit.
try including using C style bindings.
extern "C" {
#include <x264.h>
}

error LNK2019: unresolved external symbol

Ok, so I'm having a problem trying figure out the problem in my code. I have a lot of code so I'm only going to post the relevant parts that are messing up when I compile. I have the following function inside of a class and it will compile and everything will run fine until I call the function "CalculateProbabilityResults" and it runs the 7th line of code within it. I've "de-commented" this line of code in my program so you can find it easier. I'm pretty sure I have the right #include directives needed since it compiles fine when not calling the function, so that can't be the problem can it? I know some of my naming notation needs a little help, so please bear with me. Thanks in advance for the help guys.
int SQLServer::CalculateProbabilityResults(int profile, int frame, int time_period, int TimeWindowSize) {
ofstream ResultFile;
stringstream searchFileName;
stringstream outputName;
vector<vector<int>> timeFrameItemsets;
int num = getTimeFrameFile(frame*TimeWindowSize, TimeWindowSize);
cout << num << endl;
//outputName << "Results" << getTimeFrameFile((frame*TimeWindowSize), TimeWindowSize) << ".csv";
cout << outputName.str() << endl;
outputName.clear();
//ResultFile.open(outputName.str().c_str());
ResultFile.close();
result.resize(0);
return 0;
}
int getTimeFrameFile(int timeInHours, int timeFrameSize) {
int fileNum = 0;
int testWin;
if (timeInHours > 24) {
while (timeInHours >24)
timeInHours -= 24;
}
for (testWin = 0; testWin < 24/timeFrameSize; testWin++) {
if (timeInHours >= testWin*timeFrameSize && timeInHours < (testWin+1)*timeFrameSize)
fileNum = testWin+1;
}
if (fileNum == 0)
fileNum = testWin+1;
return fileNum;
}
Call Log
1>------ Rebuild All started: Project: MobileSPADE_1.3, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'MobileSPADE_1.3', configuration 'Debug|Win32'
1>Compiling...
1>main.cpp
1>MobileSPADE.cpp
1>SQLServer.cpp
1>Generating Code...
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>LINK : C:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\Debug\MobileSPADE_1.3.exe not found or not built by the last incremental link; performing full link
1>SQLServer.obj : error LNK2019: unresolved external symbol "public: int __thiscall SQLServer::getTimeFrameFile(int,int)" (?getTimeFrameFile#SQLServer##QAEHHH#Z) referenced in function "public: int __thiscall SQLServer::CalculateProbabilityResults(int,int,int,int)" (?CalculateProbabilityResults#SQLServer##QAEHHHHH#Z)
1>C:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\Debug\MobileSPADE_1.3.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\MobileSPADE_1.3\Debug\BuildLog.htm"
1>MobileSPADE_1.3 - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
The compiler thinks that getTimeFrameFile is a SQLServer method:
unresolved external symbol "public: int __thiscall SQLServer::getTimeFrameFile(int,int)"
but you have it defined as a free function:
int getTimeFrameFile(int timeInHours, int timeFrameSize) {
Change that from a free function to a class method will solve the problem:
int SQLServer::getTimeFrameFile(int timeInHours, int timeFrameSize)
Put the function getTimeFrameFile above SQLServer::CalculateProbabilityResults.