Vey*_* Wu 2 c cuda system-calls
我尝试在 CUDA C 中打开文件
fd = open("stats.txt", O_CREAT)
Run Code Online (Sandbox Code Playgroud)
open() 应该在主机端运行,编译通过但存在链接错误。
In function `open':
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:45: undefined reference to `__open_too_many_args'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,在谷歌上搜索并没有提供任何接近的信息。有谁有任何提示如何解决这个问题?多谢!
是的,我实际上用的是 0644,抱歉打错了。我将程序简化如下,但仍然出现链接错误。
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <cuda.h>
#include <sys/types.h>
#include <fcntl.h>
int main(int argc, char ** argv) {
int fd;
if((fd = open("stats.txt",O_CREAT|O_RDWR, 0644)) == -1) { printf("Can't open stats.txt.\n"); }
else printf("stats.txt opened.\n");
return 0;
}
nvcc -c -arch sm_20 --keep --compiler-options -fno-strict-aliasing -I/usr/local/cuda/include/ -I../NVIDIA_GPU_Computing_SDK/C/common/inc/ -I../../libcuda -L../NVIDIA_GPU_Computing_SDK/C/lib -lcutil -DUNIX -O3 try.cu -o try
try.cu(13): warning: variable "fd" was set but never used
try.cu(13): warning: variable "fd" was set but never used
g++ -g -c try.cu.cpp -o try.cu_o
g++ -Wall -O3 try.cu_o -o try -L../libcuda -lcuda -L/home/NVIDIA_GPU_Computing_SDK/C/lib -static -static-libgcc -L/usr/lib64 -lcutil_x86_64 -lm -lc
try.cu_o: In function `open':
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:45: undefined reference to `__open_too_many_args'
Run Code Online (Sandbox Code Playgroud)
由于某些依赖性,我必须使用较旧的 nvcc
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2010 NVIDIA Corporation
Built on Wed_Nov__3_16:16:57_PDT_2010
Cuda compilation tools, release 3.2, V0.2.1221
Run Code Online (Sandbox Code Playgroud)
g++ 是 4.6.3。谢谢。
这些open()功能有 2 种变体。
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
Run Code Online (Sandbox Code Playgroud)
如果指定O_CREAT标志,则还必须指定mode参数(文件权限位)。
所以你的代码应该是例如
fd = open("stats.txt", O_CREAT, 0644)
Run Code Online (Sandbox Code Playgroud)
链接器错误只是一种使最近 glibc 标头完成的编译/链接失败的方法,通过使用 gcc 特定的技巧来捕获传递给 的__open_too_many_args情况,但无法提供 3. 模式参数。O_CREATopen()