Xcode failed to load libvulkan.1.dylib - xcode

I am setting up dev env for Vulkan on OS X,via MoltenVK wrapper. I use Xcode IDE.
I downloaded VulkanSDK from lunarG website.
Configured the includes.
Added (copied) libvulkan.1.1.121.dylib ,libvulkan.1.dylib into the project
,then added those into Build Phases -> Link Binary With Libraries of the target.
The sample code is:
#include <vulkan/vulkan.h>
#include <GLFW/glfw3.h>
#include <stdlib.h>
#include <stdio.h>
VkInstance instance;
void createInstance() {
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Hello Triangle";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 1, 0);
appInfo.pEngineName = "No Engine";
appInfo.engineVersion = VK_MAKE_VERSION(1, 1, 0);
appInfo.apiVersion = VK_API_VERSION_1_1;
VkInstanceCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
uint32_t glfwExtensionCount = 0;
const char** glfwExtensions;
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
createInfo.enabledExtensionCount = glfwExtensionCount;
createInfo.ppEnabledExtensionNames = glfwExtensions;
createInfo.enabledLayerCount = 0;
if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS)
{
printf("failed to create instance!");
}
}
int main(int argc, const char * argv[]) {
createInstance();
return 0;
}
I receive no linker errors.
When I launch the app, I keep getting:
dyld: Library not loaded: #rpath/libvulkan.1.dylib Referenced from:
/Users/xxxxx/Library/Developer/Xcode/DerivedData/VulkanApp-aybsxkpxiqbshfebkfpcwaoiuige/Build/Products/Debug/VulkanApp
Reason: image not found
Then Xcode presents me with the following disassembly:
My hardware setup is:
MacBook Pro. macOS 10.14.6
Two GPUs:
Radeon Pro 555
Intel HD Graphics 630

I got the same issue and the solution for me was to clear the content of Subpath in Xcode -> Targets -> Build Phases -> Copy files.

Related

LNK2019 on function that does exist in an included *.cpp file

For Visual Studio 2019 on Windows 10 in a new project I'm getting an unexpected LNK2019 error.
I have a test function calling a function in another project where I've included the necessary *.cpp file into the test project so I can access the internals of a DLL for testing.
test.cpp:
#include "dllsubmodule.h"
void TestCountPagesInSomething()
{
// ... setup ...
int nPages;
nPages = CountPagesInSomething(iCurrentPos, hashFoundPages, hashPageCounts, sFoundData);
}
int main(int argc, char **argv)
{
TestCountPagesInSomething();
}
dllsubmodule.h
#pragma once
int CountPagesInSomething(
int iCurrentPos,
std::map<int, ERPPageInfo>& hashFoundPages,
std::map<std::string, int>& hashPageCounts,
const wxString& sFoundData
);
dllsubmodule.cpp
#include "stdafx.h"
#include "dllsubmodule.h"
int CountPagesInSomething(
int iCurrentPos,
std::map<int, ERPPageInfo>& hashFoundPages,
std::map<std::string, int>& hashPageCounts,
const wxString& sFoundData
)
{
// implementation code here...
}
For whatever reason the linker error seems to be complaining that CountPagesInSomething() doesn't exist. I suspect I'm having trouble with name mangling variations but I've no idea how to diagnose the problem.
Note: CountPagesInSomething() is internal to the DLL and not a DLL export.
Right now this is just a console project. I'm trying to get a basic printf() test working before I figure out what kind of unit test framework to use.

Regarding CFLocaleCopyCurrent API incorrect return value

At my workplace, we are in a situation where following standalone code below,
#include <CoreFoundation/CoreFoundation.h>
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <boost/cast.hpp>
// Reference release
struct reference_close
{
void operator()(const void *ref) const
{
CFRelease(static_cast<CFTypeRef>(ref));
}
}; // end of reference_close structure
typedef std::unique_ptr<const void, reference_close> reference_uptr;
std::string get_user_locale()
{
reference_uptr ref_ptr(CFLocaleCopyCurrent());
CFLocaleRef locale_ref(static_cast<CFLocaleRef>(ref_ptr.get()));
if (locale_ref == nullptr)
{
return std::string();
}
const size_t default_size(128);
std::vector<char> buff(default_size);
CFStringRef str_ref(CFLocaleGetIdentifier(locale_ref));
// CFStringRef str_ref((CFStringRef)CFLocaleGetValue(locale_ref,kCFLocaleLanguageCode));
if (str_ref != nullptr)
{
CFIndex len(CFStringGetLength(str_ref) + 1);
if (len > boost::numeric_cast<CFIndex>(default_size))
{
buff.resize(len);
}
buff[0] = 0;
if (!CFStringGetCString(str_ref, &buff[0], len, kCFStringEncodingISOLatin1))
{
return std::string();
}
}
return std::string(&buff[0]);
} // end of get_user_locale()
int main()
{
std::cout << "get_user_locale() : "<<get_user_locale() << std::endl;
return 0;
}
gives us a different output on OS X 10.12 and 10.13 beta.
This is what we do in a nutshell.
On 10.12 machine
1) Set the preference language as ru and region as RU
2) Restart the machine
3) Get the output of "defaults read -g AppleLocale" to make sure that output is
{
ru_RU
}
4) Compile the code, run the exe. We get the output as { ru_RU }.
We then repeat the steps 1) to 3) on OS X 10.13 (beta) machine and then run the same exe (created on 10.12, you might ask why, its because of some our internal build system restrictions ) on 10.13 machine and the output we get is "en_RU" which is not correct.
Are we missing something here ? Or is this a known problem in OS X 10.13 (beta) ? If so, how do we fix this ?
UPDATE
We also wrote a following Objective-C code to use NSLocale interface and that too gave us same results i.e ru_RU on 10.12 and en_RU on 10.13 (beta)
#import <Foundation/Foundation.h>
int main()
{
#autoreleasepool
{
NSLog(#"localeIdentifier: %#", [[NSLocale currentLocale] localeIdentifier]);
}
}
The reason we were getting an incorrect value is because our app was not localized into the locale we expected e.g ru.
We corrected this by adding an empty ru.lproj directory into our app's Contents/Resources directory and the API started giving us the correct answer.

LoadLibrary("bthprops.dll") fails, file not found

The Microsoft documentation for Bluetooth APIs such as BluetoothGetDeviceInfo provide instructions for calling these functions using either static or dynamic imports.
The static import, linking with bthprops.lib, works fine.
#include <windows.h>
#include <BluetoothAPIs.h>
#include <iostream>
int main(int argc, char** argv)
{
BLUETOOTH_DEVICE_INFO binfo = {};
binfo.dwSize = sizeof binfo;
binfo.Address.ullLong = 0xBAADDEADF00Dull;
auto result = ::BluetoothGetDeviceInfo(nullptr, &binfo);
std::wcout << L"BluetoothGetDeviceInfo returned " << result
<< L"\nand the name is \"" << binfo.szName << "\"\n";
return 0;
}
But this isn't ideal in ultra-portable code, because the documentation says they are not supported prior to Windows XP SP2. So one should use dynamic linking and recover from missing functions. However, dynamic loading bthprops.dll as instructed by the MSDN docs fails:
decltype(::BluetoothGetDeviceInfo)* pfnBluetoothGetDeviceInfo;
bool LoadBthprops( void )
{
auto dll = ::LoadLibraryW(L"bthprops.dll");
if (!dll) return false;
pfnBluetoothGetDeviceInfo = reinterpret_cast<decltype(pfnBluetoothGetDeviceInfo)>(::GetProcAddress(dll, "BluetoothGetDeviceInfo"));
return pfnBluetoothGetDeviceInfo != nullptr;
}
How should one dynamically link to these functions?
Apparently this fact is pretty well known to Google but not to MSDN. If you want to dynamically load these functions, use LoadLibrary("bthprops.cpl") which is the correct DLL name, contrary to the nice table in the function documentation.
This works:
decltype(::BluetoothGetDeviceInfo)* pfnBluetoothGetDeviceInfo;
bool LoadBthprops( void )
{
auto dll = ::LoadLibraryW(L"bthprops.cpl");
if (!dll) return false;
pfnBluetoothGetDeviceInfo = reinterpret_cast<decltype(pfnBluetoothGetDeviceInfo)>(::GetProcAddress(dll, "BluetoothGetDeviceInfo"));
return pfnBluetoothGetDeviceInfo != nullptr;
}

Use of undeclared identifier 'kAudioUnitSubType_SpeechSynthesis...

I've been following the examples on Audio Units from Learning Core Audio book by Adamson and Avila. I'm getting the above error for some reason. I #include <CoreAudio/CoreAudio.h> even just to make sure I am importing the possible libraries for Audio, and made sure to configure the "Link Binary with Libraries" under the "Build Phases" part of target. I even changed the Base SDK to OSX 10.7 (as opposed to the default 10.8) to see what happens, but no cigar. And according to the documentation, the Speech Synthesis API is not fully deprecated in anyway -- some functions are, however. My MacBook is running 10.7.5. XCode is Version 4.6 (4H127.
Below I put a comment on where I got the error in CAPS. Any ideas?
//
// main.c
// CAsamplerSynthesisGraph
//
// Created by Edderic Ugaddan on 6/25/13.
// Copyright (c) 2013 Edderic Ugaddan. All rights reserved.
//
//#include <CoreFoundation/CoreFoundation.h>
#include <AudioUnit/AudioUnit.h>
#include <AudioToolbox/AudioToolbox.h>
#include <CoreAudio/CoreAudio.h>
// #define PART_II
#pragma mark user-data struct
// Insert Listing 7.19 here
typedef struct MyAUGraphPlayer {
AUGraph graph;
AudioUnit samplerAU;
} MyAUGraphPlayer;
#pragma mark utility functions
// Insert Listing 4.2 here
static void CheckError(OSStatus error, const char *operation) {
if (error == noErr) return;
char errorString[20];
// See if it appears to be a 4-char-code.
*(UInt32 *)*(errorString + 1) = CFSwapInt32HostToBig(error);
if (isprint(errorString[1]) && isprint(errorString[2]) &&
isprint(errorString[3]) && isprint(errorString[4])) {
errorString[0] = errorString[5] = '\'';
errorString[6] = '\0';
}
else {
// No, format it as an integer.
sprintf(errorString, "%d", (int) error);
fprintf(stderr, "Error: %s (%s)\n", operation, errorString);
exit(1);
}
}
void CreateMyAUGraph(MyAUGraphPlayer *player) {
// Insert Listing 7.21 here
// Create a new graph
CheckError(NewAUGraph(&player->graph),
"NewAUGraph failed");
// Generates a description that matches our output device (speakers)
AudioComponentDescription outputcd = {0};
outputcd.componentType = kAudioUnitType_Output;
outputcd.componentSubType = kAudioUnitSubType_DefaultOutput;
outputcd.componentManufacturer = kAudioUnitManufacturer_Apple;
// Adds a node with above description to the graph
AUNode outputNode;
CheckError(AUGraphAddNode(player->graph,
&outputcd,
&outputNode),
"AUGraphAddNode[kAudioUnitSubType_DefaultOutput] failed");
// Generates a description that will match a generator AU
// of type: sampler synthesizer
AudioComponentDescription samplercd = {0};
samplercd.componentType = kAudioUnitType_Generator;
samplercd.componentSubType = kAudioUnitSubType_SpeechSynthesis; // I GET ERROR HERE
samplercd.componentManufacturer = kAudioUnitManufacturer_Apple;
// Adds a node with above description to the graph
AUNode samplerNode;
CheckError(AUGraphAddNode(player->graph,
&samplercd,
&samplerNode),
"AUGraphAddNode[kAudioUnitSubType_samplerSynthesis] failed");
// Opening the graph opens all contained audio units, but
// does not allocate any resources yet
CheckError(AUGraphOpen(player->graph),
"AUGraphOpen failed");
// Gets the reference to the AudioUnit object for the
// sampler graph node
CheckError(AUGraphNodeInfo(player->graph,
samplerNode,
NULL,
&player->samplerAU),
"AUGraphNodeInfo failed");
#ifdef PART_II
// Insert Listing 7.24 - 7.26 here
#else
// Insert Listing 7.22 here
// Connect the output source of the sampler synthesis AU
// to the input source of the output node
CheckError(AUGraphConnectNodeInput(player->graph,
samplerNode,
0,
outputNode,
0),
"AUGraphConnectNodeInput failed");
#endif
}
// Replace with listing 7.23
void PrepareSamplerAU(MyAUGraphPlayer *player) {
// Sampler
}
#pragma mark main function
// Replace with listing 7.20
int main(int argc, const char * argv[])
{
MyAUGraphPlayer player = {0};
// Build a basic sampler->speakers graph
CreateMyAUGraph(&player);
// Configure the sampler synthesizer
PrepareSamplerAU(&player);
// Start playing
CheckError(AUGraphStart(player.graph),
"AUGraphStart failed");
// Sleep a while so the sampler can play out
usleep ((int)(10 * 1000. * 1000.));
// Cleanup
AUGraphStop(player.graph);
AUGraphUninitialize(player.graph);
AUGraphClose(player.graph);
return 0;
}
kAudioUnitSubType_SpeechSynthesis is declared in SpeechSynthesis.framework, which lives within the ApplicationServices.framework umbrella framework, so you should #import < ApplicationServices.framework>.

How to use pthread library in DevC++?

I downloaded pthread package from pthread. What should I do now to use it in DevC++?
Download pthreads devpak Download
Install it in Dev C++
Create new Project in Dev C++
After that go to Project menu -> Project Option -> In that select "Parameter Tab"
Select "add Library or object" option
Select "libpthreadGC2.a" file from installation directory of Dev c++
It will be in LIB directory.
Press ok
Now test following sample code ready for running..
Sample Code :
#include <iostream>
#include <pthread.h>
using namespace std;
void * fun_thread1(void *data)
{
for(int i=0;i<100;i++)
{
cout<<endl<<"In Thread 1"<<endl;
}
}
void * fun_thread2(void *data)
{
for(int i=0;i<100;i++)
{
cout<<endl<<"In Thread 2"<<endl;
}
}
int main(int argc, char *argv[])
{
int status;
// creating thread objects
pthread_t thrd_1;
pthread_t thrd_2;
// create thread
pthread_create(&thrd_1,NULL,fun_thread1,(void *)0);
pthread_create(&thrd_2,NULL,fun_thread2,(void *)0);
pthread_join(thrd_1, (void **)&status);
pthread_join(thrd_2, (void **)&status);
system("PAUSE");
return EXIT_SUCCESS;
}

Resources