vulkan vkresult linker error msvc - c++

I'm trying to compile the first sample program included in vulkan, so I pasted it into a new win32 project in the vs17 rc. It is called 01-init_instance in the Samples dir. I am compiling x86.
#include <iostream>
#include <cstdlib>
#include <util_init.hpp>
#define APP_SHORT_NAME "vulkansamples_instance"
int main(int argc, char *argv[]) {
struct sample_info info = {};
init_global_layer_properties(info);
/* VULKAN_KEY_START */
// initialize the VkApplicationInfo structure
VkApplicationInfo app_info = {};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
app_info.pNext = NULL;
app_info.pApplicationName = APP_SHORT_NAME;
app_info.applicationVersion = 1;
app_info.pEngineName = APP_SHORT_NAME;
app_info.engineVersion = 1;
app_info.apiVersion = VK_API_VERSION_1_0;
// initialize the VkInstanceCreateInfo structure
VkInstanceCreateInfo inst_info = {};
inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
inst_info.pNext = NULL;
inst_info.flags = 0;
inst_info.pApplicationInfo = &app_info;
inst_info.enabledExtensionCount = 0;
inst_info.ppEnabledExtensionNames = NULL;
inst_info.enabledLayerCount = 0;
inst_info.ppEnabledLayerNames = NULL;
VkInstance inst;
VkResult res;
res = vkCreateInstance(&inst_info, NULL, &inst);
if (res == VK_ERROR_INCOMPATIBLE_DRIVER) {
std::cout << "cannot find a compatible Vulkan ICD\n";
exit(-1);
}
else if (res) {
std::cout << "unknown error\n";
exit(-1);
}
vkDestroyInstance(inst, NULL);
/* VULKAN_KEY_END */
return 0;
}
I have done the project properties like:
I had this wrong and was getting linker errors for vkCreateInstance not being resolved (before adding the .lib in dependencies) now I am getting a single, different, linker error for not finding vkResult. This confuses me because I don't know how it could resolve vkcreate but not vkresult. I used all the charset settings (multi-byte, not unicode as normal) but that didn't change anything.
The error is:
Error LNK2019 unresolved external symbol "enum VkResult __cdecl init_global_layer_properties(struct sample_info &)" (?init_global_layer_properties##YA?AW4VkResult##AAUsample_info###Z) referenced in function _main vktest C:\Users\user\Documents\Visual Studio 2017\Projects\vktest\vktest\Source.obj 1

The samples that come with the Vulkan SDK compile the utils folder into a static library, and link with that library. This is where the init_global_layer_properties function exists. If you don't link your sample with that library also, you will get unresolved symbols.

Related

Windows Sharing file over network NetShareAdd Error 53

I tried to compile this example from microsoft docs for sharing a folder over network however the executable gives an error.
Full Code :
#include "stdafx.h"
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <stdio.h>
#include <lm.h>
#pragma comment(lib, "Netapi32.lib")
void wmain(int argc, TCHAR *argv[])
{
NET_API_STATUS res;
SHARE_INFO_2 p;
DWORD parm_err = 0;
if (argc<2)
printf("Usage: NetShareAdd server\n");
else
{
//
// Fill in the SHARE_INFO_2 structure.
//
p.shi2_netname = TEXT("TESTSHARE");
p.shi2_type = STYPE_DISKTREE; // disk drive
p.shi2_remark = TEXT("TESTSHARE to test NetShareAdd");
p.shi2_permissions = 0;
p.shi2_max_uses = 4;
p.shi2_current_uses = 0;
p.shi2_path = TEXT("F:\\abc");
p.shi2_passwd = NULL; // no password
//
// Call the NetShareAdd function,
// specifying level 2.
//
res = NetShareAdd(argv[1], 2, (LPBYTE)&p, &parm_err);
//
// If the call succeeds, inform the user.
//
if (res == 0)
printf("Share created.\n");
// Otherwise, print an error,
// and identify the parameter in error.
//
else
printf("Error: %u\tparmerr=%u\n", res, parm_err);
}
return;
}
Exe command :
ConsoleApplication1.exe myShare
Error Shown :
Error: 53 parmerr=0
However the follwing from cmd works fine :
net share abc=F:\abc
I am unable to figure out what actually the error is and how to resolve that. can anybody help?
I am on windows 11 and code is compiled on VS 2015 Community.
With admin privileges, servername ConsoleApplication1.exe localhost and ConsoleApplication1.exe 127.0.0.1 worked fine.

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.

Unresolved Externals in Irrlicht

I am currently coding in Visual Studio 2010, using C++ and the Irrlicht game engine. I have tried asking this question on their forum, however I haven't had any response.
I am using the tutorials on the Irrlicht website:
http://irrlicht.sourceforge.net/docu/example002.html
The error I am getting is: "unresolved external symbol _imp_createDevice referenced in function _main"
I have added linked the Irrlicht library and include files already, but I am still getting this error.
// Tutorial2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) OpenGL 1.5\n (b) Direct3D 9.0c\n (c) Direct3D 8.1\n"\
" (d) Burning's Software Renderer\n (e) Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a':driverType = video::EDT_OPENGL; break;
case 'b':driverType = video::EDT_DIRECT3D9; break;
case 'c':driverType = video::EDT_DIRECT3D8; break;
case 'd':driverType = video::EDT_BURNINGSVIDEO; break;
case 'e':driverType = video::EDT_SOFTWARE; break;
case 'f':driverType = video::EDT_NULL; break;
default: return 1;
}
// create device and exit if creation failed
IrrlichtDevice *device =
createDevice(driverType, core::dimension2d<u32>(640, 480));
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
device->getFileSystem()->addFileArchive("../../media/map-20kdm2.pk3");
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* node = 0;
if (mesh)
node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
// node = smgr->addmeshSceneNode(mesh->getMesh(0));
if (node)
node->setPosition(core::vector3df(-1300,-144,-1249));
smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
int lastFPS = -1;
while(device->run())
{
if(device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255, 200, 200, 200));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - Quake 3 Map example[";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
else
device->yield();
}
device->drop();
return 0;
}
I've managed to build the sample, no problem.
The only way to get your error is to mix the 32 and 64bit lib files.
Rename the 64bit library Irrlicht_x64.lib and try building again.

DirectX 9 "unresolved external symbol" problem

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?

Boost::Test -- generation of Main()?

I'm a bit confused on setting up the boost test library. Here is my code:
#include "stdafx.h"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE pevUnitTest
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE( TesterTest )
{
BOOST_CHECK(true);
}
My compiler generates the wonderfully useful error message:
1>MSVCRTD.lib(wcrtexe.obj) : error LNK2019: unresolved external symbol _wmain referenced in function ___tmainCRTStartup
1>C:\Users\Billy\Documents\Visual Studio 10\Projects\pevFind\Debug\pevUnitTest.exe : fatal error LNK1120: 1 unresolved externals
It seems that the Boost::Test library is not generating a main() function -- I was under the impression it does this whenever BOOST_TEST_MODULE is defined. But ... the linker error continues.
Any ideas?
Billy3
EDIT: Here's my code to work around the bug described in the correct answer below:
#include "stdafx.h"
#define BOOST_TEST_MODULE pevUnitTests
#ifndef _UNICODE
#define BOOST_TEST_MAIN
#endif
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#ifdef _UNICODE
int _tmain(int argc, wchar_t * argv[])
{
char ** utf8Lines;
int returnValue;
//Allocate enough pointers to hold the # of command items (+1 for a null line on the end)
utf8Lines = new char* [argc + 1];
//Put the null line on the end (Ansi stuff...)
utf8Lines[argc] = new char[1];
utf8Lines[argc][0] = NULL;
//Convert commands into UTF8 for non wide character supporting boost library
for(unsigned int idx = 0; idx < argc; idx++)
{
int convertedLength;
convertedLength = WideCharToMultiByte(CP_UTF8, NULL, argv[idx], -1, NULL, NULL, NULL, NULL);
if (convertedLength == 0)
return GetLastError();
utf8Lines[idx] = new char[convertedLength]; // WideCharToMultiByte handles null term issues
WideCharToMultiByte(CP_UTF8, NULL, argv[idx], -1, utf8Lines[idx], convertedLength, NULL, NULL);
}
//From boost::test's main()
returnValue = ::boost::unit_test::unit_test_main( &init_unit_test, argc, utf8Lines );
//End from boost::test's main()
//Clean up our mess
for(unsigned int idx = 0; idx < argc + 1; idx++)
delete [] utf8Lines[idx];
delete [] utf8Lines;
return returnValue;
}
#endif
BOOST_AUTO_TEST_CASE( TesterTest )
{
BOOST_CHECK(false);
}
Hope that's helpful to someone.
Billy3
I think the problem is that you're using the VC10 beta.
It has a fun little bug where, when Unicode is enabled, it requires the entry point to be wmain, not main. (Older versions allowed you to use both wmain and main in those cases).
Of course this will be fixed in the next beta, but until then, well, it's a problem. :)
You can either downgrade to VC9, disable Unicode, or try manually setting the entry point to main in project properties.
Another thing that might work is if you define your own wmain stub, which calls main. I'm pretty sure this is technically undefined behavior, but as a workaround for a compiler bug in an unreleased compiler it might do the trick.