【发布时间】:2014-04-25 12:45:32
【问题描述】:
我在使用 C Cuda 和 lodepng 库编译 cuda 项目时遇到了一些问题。
我的 makefile 看起来像这样。
gpu: super-resolution.cu
gcc -g -O -c lodepng.c
nvcc -c super-resolution.cu
nvcc -o super-resolution-cuda super-resolution.o
rm -rf super-resolution.o
rm -rf lodepng.o
谁能告诉我我做错了什么,因为它在抱怨
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
super-resolution.o: In function `main':
parallel-algorithm/super-resolution.cu:238: undefined reference to `lodepng_decode32_file(unsigned char**, unsigned int*, unsigned int*, char const*)'
parallel-algorithm/super-resolution.cu:259: undefined reference to `lodepng_encode32_file(char const*, unsigned char const*, unsigned int, unsigned int)'
parallel-algorithm/super-resolution.cu:269: undefined reference to `lodepng_encode32_file(char const*, unsigned char const*, unsigned int, unsigned int)'
parallel-algorithm/super-resolution.cu:282: undefined reference to `lodepng_encode32_file(char const*, unsigned char const*, unsigned int, unsigned int)'
parallel-algorithm/super-resolution.cu:292: undefined reference to `lodepng_encode32_file(char const*, unsigned char const*, unsigned int, unsigned int)'
parallel-algorithm/super-resolution.cu:301: undefined reference to `lodepng_encode32_file(char const*, unsigned char const*, unsigned int, unsigned int)'
...
我只需要一种方法来编译我的 .cu 文件并在编译过程中使用 nvcc 添加一个 C .o 文件。
编辑:尝试过的建议。没有成功。
gcc -g -O -c lodepng.c
nvcc -c super-resolution.cu
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
super-resolution.cu:1:2: warning: #import is a deprecated GCC extension [-Wdeprecated]
#import "cuda.h"
^
super-resolution.cu(106): warning: expression has no effect
super-resolution.cu(116): warning: expression has no effect
super-resolution.cu(141): warning: variable "y" was declared but never referenced
super-resolution.cu:1:2: warning: #import is a deprecated GCC extension [-Wdeprecated]
#import "cuda.h"
^
super-resolution.cu(106): warning: expression has no effect
super-resolution.cu(116): warning: expression has no effect
super-resolution.cu(141): warning: variable "y" was declared but never referenced
ptxas /tmp/tmpxft_00000851_00000000-5_super-resolution.ptx, line 197; warning : Double is not supported. Demoting to float
nvcc -o super-resolution-cuda super-resolution.o lodepng.o
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
super-resolution.o: In function `main':
tmpxft_00000851_00000000-3_super-resolution.cudafe1.cpp:(.text+0x5d): undefined reference to `lodepng_decode32_file(unsigned char**, unsigned int*, unsigned int*, char const*)'
它仍然找不到对目标文件的引用。 编辑:这是我们的 .cu 文件。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cstdio>
extern "C" unsigned lodepng_encode32_file(const char* ,const unsigned char* , unsigned , unsigned h);
extern "C" unsigned lodepng_decode32_file(unsigned char** , unsigned* , unsigned* ,const char* );
【问题讨论】:
-
您正在与
nvcc链接,但不包括您使用 gcc (lodepng.o) 构建的对象。尝试使用nvcc -o super-resolution-cuda super-resolution.o lodepng.o代替现有的nvcc -o super-resolution-cuda super-resolution.o链接步骤。 -
所以
lodepng_encode32_file参考得到了整理,但lodepng_decode32_file参考没有?可能需要查看确切的代码,然后才能理解为什么以及是否正确地进行 C/C++ 链接(例如 extern C 等)。您确定lodepng_encode32_file和lodepng_decode32_file都以相同的方式导出和使用吗? -
认真的吗?您要在 cmets 中发布这些更新吗? lodepng中的对应函数怎么样?他们的原型匹配吗?我不确定这个问题可以用小sn-ps来回答。在演示问题的问题中创建一个完整、简短、可编译的案例。是的,您需要大量编辑文件,这需要您付出努力。但是,将 2 个文件编辑到显示问题的关键部分应该不难。