D3D11 Compiling shaders file not found - directx-11

I am trying to use
wchar_t wFilename[MAX_PATH];
mbstowcs(wFilename, szFileNAme, MAX_PATH);
D3DCompileFromFile(wFilename, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, szEntryPoint, szShaderModel, dwShaderFlags, 0, ppBlobOut, &pErrorBlob);
to compile my shaders for DirectX 11 and I keep getting a file not found error on the shader file. It is in the same directory as the file that is making the above call.
What could I be missing?
Edit: I've tried adding the shader file to my project which required another shader file which I added as well. Doing this causes an error: 'main':entrypoint not found for file "FXC"

Is that your entire code? As is, you aren't checking the return value of mbstowcs. It could be invalid due to an error and the destination array could be ill-formed. Hence, the "file not found" error.
If you are compiling the shader in-code then you need to tell Visual Studio to not compile the shader as part of the build process. You can do this by excluding it via right-clicking on the file in the solution explorer then Properties > General > Exclude from build: Yes
You are getting the error because the main entry point of your function is not named main and that's the default that FXC looks for. You can change it in the same properties pane as before: Properties > HLSL Compiler > General > Entrypoint name.
But, since you are compiling in-code with custom entry points, you should disable build-step compiling, so changing the entrypoint name will have no effect.

First you have to make sure that visual studio is copying the file into the build directory (that the executable is being executed from).
The DXSample.h header uses this code to find the executables directory path at runtime
inline void GetAssetsPath(_Out_writes_(pathSize) WCHAR* path, UINT pathSize)
{
if (path == nullptr)
{
throw std::exception();
}
DWORD size = GetModuleFileName(nullptr, path, pathSize);
if (size == 0 || size == pathSize)
{
// Method failed or path was truncated.
throw std::exception();
}
WCHAR* lastSlash = wcsrchr(path, L'\\');
if (lastSlash)
{
*(lastSlash + 1) = L'\0';
}
}
Here are some fragments of it being use
std::wstring m_assetsPath;
WCHAR assetsPath[512];
GetAssetsPath(assetsPath, _countof(assetsPath));
m_assetsPath = assetsPath;
std::wstring DeviceResources::GetAssetFullPath(LPCWSTR assetName)
{
return m_assetsPath + assetName;
}
deviceResources.GetAssetFullPath(L"compute_shader.cso").c_str(),
'main':entrypoint not found for file "FXC"
You probably have not specified what kind of shader it is in visual studio properly.

Related

Can't link to .so file on Mac with CMake

I'm working on a PHP 7 extension using Swig and am trying to link to libphp7.so. From my CMakeLists.txt file:
find_library(php7_lib php7 PATHS "/usr/local/Cellar/php/7.3.0/lib/httpd/modules" NO_DEFAULT_PATH)
target_link_libraries(navdb_php7_client_api ${php7_lib} dl)
But I get an error:
[100%] Linking CXX shared module .../lib/libnavdb_php7_client_api.so
...
ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file '/usr/local/Cellar/php/7.3.0/lib/httpd/modules/libphp7.so' for architecture x86_64
The file I'm trying to link to:
$ file /usr/local/Cellar/php/7.3.0/lib/httpd/modules/libphp7.so
/usr/local/Cellar/php/7.3.0/lib/httpd/modules/libphp7.so: Mach-O 64-bit bundle x86_64
Any ideas on how to resolve this?
Although Apple recommends bundles be given the extension .bundle many developers give them the .so extension for the sake of cross-platform familiarity. On Linux, no distinction is made between a shared module (a bundle on MacOS) and a shared library (a dylib on MacOS.)
Understanding that, as ld states, you cannot link to an MH_BUNDLE on MacOS. It either needs to be a dylib to link it, or you need to load the .so using the dyld APIs.
This link gives an example of how to dynamically load a bundle on MacOS:
#include <stdio.h>
#import <mach-o/dyld.h>
int main( )
{
int the_answer;
int rc; // Success or failure result value
NSObjectFileImage img; // Represents the bundle's object file
NSModule handle; // Handle to the loaded bundle
NSSymbol sym; // Represents a symbol in the bundle
int (*get_answer) (void); // Function pointer for get_answer
/* Get an object file for the bundle. */
rc = NSCreateObjectFileImageFromFile("libanswer.bundle", &img);
if (rc != NSObjectFileImageSuccess) {
fprintf(stderr, "Could not load libanswer.bundle.\n");
exit(-1);
}
/* Get a handle for the bundle. */
handle = NSLinkModule(img, "libanswer.bundle", FALSE);
/* Look up the get_answer function. */
sym = NSLookupSymbolInModule(handle, "_get_answer");
if (sym == NULL)
{
fprintf(stderr, "Could not find symbol: _get_answer.\n");
exit(-2);
}
/* Get the address of the function. */
get_answer = NSAddressOfSymbol(sym);
/* Invoke the function and display the answer. */
the_answer = get_answer( );
printf("The answer is... %d\n", the_answer);
fprintf(stderr, "%d??!!\n", the_answer);
return 0;
}
I found out how/what to do from this link:
Clang and undefined symbols when building a library
The libphp7.so doesn't need to be linked to at compile time, run-time works fine. This can be enabled by setting a CXX_FLAG (see the link for details).

SDL2_gfx install and USE - Mac OS X

I've been trying for about 6 hours... to make use of the SDL2_gfx library in my project on Xcode 8.0.
I'll tell you right now, I'm a complete newbie to all of this, terminal commands, including libraries and stuff.
I've managed to use SDL2 fine, for there is a .framework, but the SDL2_gfx only comes as a folder with a .a, .dylib, .h and a mysterious .json.
I've installed it through homebrew whithout problems, but now, how do I make a project using it ??
In the Build Phases and Build Settings :
I've tried linking .a and .dylib via "Link Binary With Libraries",
I've added the headers paths in "Headers Search Paths" in "Search Paths",
I've tried adding the .h to my project directly,
and I have absolutely no idea of what to put in "Other Linker Flags" as it what suggested in many answers.
I keep getting the very simple error "no matching function for call ..." whenever I try using a function. But I'm doing it the same way as in some examples on the internet, and I checked in the .h, the functions do exist...
Please help T_T
EDIT :
I've managed to find functions that are apparently recognized :
Sint16 circleR = 100;
Sint16 circleX = 300;
Sint16 circleY = 300;
int result = filledCircleColor(gRenderer, circleX, circleY, circleR, 0xFF0000FF);
std::cout << "draw circle result " << result << std::endl;
int a = pixelRGBA(gRenderer, circleR, circleR, 0xFF, 0x00, 0x00, 0xFF);
std::cout << "draw pixel result " << a << std::end;
But come out with result -1, which means it didn't work.
Still can't figure it out...
I suppose I'm not using them correctly, but I can't find any different example on the internet.
i think i see your problem : you are calling with as 1st parameter a RENDERER. The function header expects a SURFACE :
http://www.ferzkopp.net/Software/SDL_gfx-2.0/Docs/html/_s_d_l__gfx_primitives_8h.html#a4f7b717b958ef39bfc8c958476dd0de1
clearly defines the function as :
SDL_GFXPRIMITIVES_SCOPE int filledCircleColor ( SDL_Surface * dst,
Sint16 x,
Sint16 y,
Sint16 rad,
Uint32 color
)

GetFileAttributes() function doesn't work with a relative path to a folder

I have a Visula C++ console application in MS VS 2013 where I'm checking the existence of folder on a hard drive. I use GetFileAttributes() function for it in the following way:
int _tmain(int argc, _TCHAR* argv[])
{
string folderPath = argv[1];
if (GetFileAttributes(folderPath.c_str()) == FILE_ATTRIBUTE_DIRECTORY)
{
// Do something here
}
else
{
// Also do something here
}
return 0;
}
But the result of GetFileAttributes() is equal to FILE_ATTRIBUTE_DIRECTORY (0x10) only if I set (in command line arguments) a fully qualified path to folder. For example: "M:\MS_VS2013_Projects\WordsCounter\Debug\TextFiles_to_Test" where "M" is a hard drive name.
But if I try to set (in command line arguments) a relative path for example: "TextFiles_to_Test" or "M:TextFiles_to_Test" or "\TextFiles_to_Test" or ".\TextFiles_to_Test" then GetFileAttributes() returns the wrong result == 4294967295. How can I achieve the correct resuli (0x10) in case of relative path to folder? I'll be very thankful for your help.
This is not specific to Windows XP. I made some tests on Windows 7. It doesn't work with relative paths, and also doesn't work with "reparse points". For instance, if you use localized versions of a folder, it won't work.
Ex: on a French Windows OS, only the 1st of the following calls will succeed.
DWORD dwAttr1 = ::GetFileAttributesW(L"C:\\Program Files");
DWORD dwAttr2 = ::GetFileAttributesW(L"Program Files"); //relative folder
DWORD dwAttr3 = ::GetFileAttributesW(L"C:\\Programmes"); //NTFS Junction point
DWORD dwAttr4 = ::GetFileAttributesW(L"Programmes");

Difference between mkdir and CreateDirectory

Is there a difference between mkdir(<name>) and CreateDirectory(<name>, NULL) under Win32.
As I can see, both are working (in the same way ??)
mkdir (and the recommended _mkdir are runtime library functions. CreateDirectory is specific to Windows. If you want portable code, call _mkdir. If you're fine making your program Windows-specific, or you need the ability to add security descriptors, then call CreateDirectory.
Most likely, the _mkdir implementation for Windows calls CreateDirectory(name, NULL). So both end up doing the same thing.
Edit: The Visual Studio 12 implementation of _mkdir() calls _wmkdir(), which then calls CreateDirectoryW:
int __cdecl _wmkdir (
const wchar_t *path
)
{
ULONG dosretval;
/* ask OS to create directory */
if (!CreateDirectoryW(path, (LPSECURITY_ATTRIBUTES)NULL))
dosretval = GetLastError();
else
dosretval = 0;
if (dosretval) {
/* error occured -- map error code and return */
_dosmaperr(dosretval);
return -1;
}
return 0;
}

UF_TRACKED file flag from stat.h

In the header stat.h on osx 10.7 I found a define in fileflag UF_TRACKED. I googled that define but didn't find anything about the flag. Can you describe to me what this flag means? I encountered it when I tried to apply attributes to the file which placed on the mounted folder. That folder is HFS+ folder on the remoted osx 10.7.3.
Maybe I can ignore it? And what can happen in that case?
The UF_TRACKED is a flag which tells HFS to send an event to a tracked file handler in user mode on any change to the file's dentry (i.e. rename or delete, and changes in metadata, but not file modification). You can see that both in the header file:
#define UF_TRACKED 0x00000040 /* file renames and deletes are tracked */
The code to handle this is in the kernel, bsd/hfs/hfs_vfsutils.c:
int
check_for_tracked_file(struct vnode *vp, time_t ctime, uint64_t op_type, void *arg)
{
int tracked_error = 0, snapshot_error = 0;
if (vp == NULL) {
return 0;
}
if (VTOC(vp)->c_bsdflags & UF_TRACKED) {
...
And is called all over the place, primarily from hfs_vnops.c

Resources