c - 在 Windows 上使用“空格”访问文件路径中的数据

标签 c windows

我在 Windows 上遇到了一个奇怪的问题 我正在使用一个名为 STDCL 的库,它在 Linux 上运行良好,但在 Windows 上,如果输出 .exe 文件路径有“空格”,则会出现错误

例子:

c:\my file\my file.exe //won't work
c:\my_file\my file.exe //will work
c:\my file\my file.exe //won't work
// and it is accessing data from dll(any where) containing STDCL library
c:\my_file\my file.exe //will work
// and it is accessing data from dll(any where) containing STDCL library

我得到了编译库的源代码 或者是否有更简单的方法强制接受我的 .dll 中的 .exe 路径

编辑:示例代码

/* hello_stdcl.c */


#include <stdio.h>
#include <stdcl.h>

int main()
{
    stdcl_init(); // this is only necessary for Windows

   cl_uint n = 64;

#if(1)

    /* use default contexts, if no GPU use CPU */
   CLCONTEXT* cp = (stdgpu)? stdgpu : stdcpu;

   unsigned int devnum = 0;

   void* clh = clopen(cp,"matvecmult.cl",CLLD_NOW);
   cl_kernel krn = clsym(cp,clh,"matvecmult_kern",0);

   /* allocate OpenCL device-sharable memory */
   cl_float* aa = (float*)clmalloc(cp,n*n*sizeof(cl_float),0);
   cl_float* b = (float*)clmalloc(cp,n*sizeof(cl_float),0);
   cl_float* c = (float*)clmalloc(cp,n*sizeof(cl_float),0);

   clndrange_t ndr = clndrange_init1d( 0, n, 64);

   /* initialize vectors a[] and b[], zero c[] */
   int i,j; 
   for(i=0;i<n;i++) for(j=0;j<n;j++) aa[i*n+j] = 1.1f*i*j;
   for(i=0;i<n;i++) b[i] = 2.2f*i;
   for(i=0;i<n;i++) c[i] = 0.0f;

   /* define the computational domain and workgroup size */
   //clndrange_t ndr = clndrange_init1d( 0, n, 64);

   /* non-blocking sync vectors a and b to device memory (copy to GPU)*/
   clmsync(cp,devnum,aa,CL_MEM_DEVICE|CL_EVENT_NOWAIT);
   clmsync(cp,devnum,b,CL_MEM_DEVICE|CL_EVENT_NOWAIT);

   /* set the kernel arguments */
   clarg_set(cp,krn,0,n);
   clarg_set_global(cp,krn,1,aa);
   clarg_set_global(cp,krn,2,b);
   clarg_set_global(cp,krn,3,c);

   /* non-blocking fork of the OpenCL kernel to execute on the GPU */
   clfork(cp,devnum,krn,&ndr,CL_EVENT_NOWAIT);

   /* non-blocking sync vector c to host memory (copy back to host) */
   clmsync(cp,0,c,CL_MEM_HOST|CL_EVENT_NOWAIT);

   /* force execution of operations in command queue (non-blocking call) */
   clflush(cp,devnum,0);

   /* block on completion of operations in command queue */
   clwait(cp,devnum,CL_ALL_EVENT);

   for(i=0;i<n;i++) printf("%d %f %f\n",i,b[i],c[i]);

   clfree(aa);
   clfree(b);
   clfree(c);

   clclose(cp,clh);

#endif

    system("pause");

}

编辑 2:

当我编译上面的代码时...获取结果 .exe 文件并将其放在没有空格的路径(短路径)中它可以工作

如果我把它放在带空格的路径中......它只会崩溃,当我调试时它就像内存问题(所以它会因长路径而崩溃)

当我联系图书馆的创建者时,他告诉我: “windows getcwd() 调用返回带空格的不可用路径”

正如我之前所说,这个库在 Linux 上运行良好,在 Windows 上可能有什么解决方案

系统:win7 64位

最佳答案

对二进制名称/路径使用引号作为“myfile.exe”

关于c - 在 Windows 上使用“空格”访问文件路径中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16246187/

相关文章:

c - 程序崩溃并显示 0xC0000005

windows - 如何有效地检索目录中的文件数?

java - Windows 无法删除具有大路径的文件

C预处理器: what is the motivation behind not macro-expanding arguments of#error directive?

c - 在C中将单个字符串分成两个不同的字符串

c - 了解如何编写缓存友好的代码

c - 取消引用 void * 就像 (int) -- 标准做法?

linux - 删除不存在的文件

.net - 从注册表中检索 Windows 密码提示

windows - Windows 上的 Postgresql WAL