crt1.o:在函数“_start”中:(.text+0x20):对“main”的未定义引用
crt1.o: In function `_start': (.text+0x20): undefined reference to `main'
我有一小段代码,在尝试 make
时出现此错误,这是正在使用的 CMakelists.txt:
cmake_minimum_required(VERSION 2.8) #Specify the minimum CM$
project(gaussian) $
find_package(CUDA REQUIRED) #find the CUDA $
find_package(ITK REQUIRED)
include( ${ITK_USE_FILE} )
#message("Debug: ITK ${ITK_DIR}")
include_directories(${CUDA_INCLUDE_DIRS}) #Specify the CUDA include direc$
add_executable(gaussian source/main.cu) #create an executabl$
#specify any additional libraries here (CUFFT and CUBLAS can be useful)
target_link_libraries(gaussian ${CUDA_cufft_LIBRARY} ${CUDA_cublas_LIBRARY} ${I$
main.cu 文件如下:
#include <fstream>
#include <cuda.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <ctime>
#include <cuda_runtime_api.h>
#include <cufft.h>
#include "itkImage.h"
using namespace std;
static void HandleError( cudaError_t err, const char *file, int line )
{
if (err != cudaSuccess)
cout<<cudaGetErrorString(err)<<" in "<< file <<" at line "<< line<<endl;
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
int main(int argc, char* argv[])
{
typedef itk::Image< unsigned short, 3 > ImageType;
ImageType::Pointer image = ImageType::New();
cout << "ITK Hello World !" << endl;
int nDevices;
cout<<"DEVICE SPECIFICATIONS: "<<endl<<endl;
HANDLE_ERROR(cudaGetDeviceCount(&nDevices));
return 0;
}
构建时,链接器已设置。我无法弄清楚这里出了什么问题。
我在这里发现了问题,首先我需要使用 cuda_add_executable,而不是 add_executable。这样做并构建,我收到如下错误:
overriding itk::ImageBase<VImageDimension>::Pointer
itk::ImageBase<VImageDimension>::CreateAnother() const [with unsigned int VImageDimension = 3u, itk::ImageBase<VImageDimension>::Pointer = itk::SmartPointer<itk::ImageBase<3u> >]
这是因为 CUDA 编译器无法处理 ITK 使用的 C++ 功能。在 .cxx 文件中使用 ITK 功能并在 .cu 文件中调用 CUDA 函数有帮助。
学分:http://public.kitware.com/pipermail/insight-developers/2012-October/022116.html
我有一小段代码,在尝试 make
时出现此错误,这是正在使用的 CMakelists.txt:
cmake_minimum_required(VERSION 2.8) #Specify the minimum CM$
project(gaussian) $
find_package(CUDA REQUIRED) #find the CUDA $
find_package(ITK REQUIRED)
include( ${ITK_USE_FILE} )
#message("Debug: ITK ${ITK_DIR}")
include_directories(${CUDA_INCLUDE_DIRS}) #Specify the CUDA include direc$
add_executable(gaussian source/main.cu) #create an executabl$
#specify any additional libraries here (CUFFT and CUBLAS can be useful)
target_link_libraries(gaussian ${CUDA_cufft_LIBRARY} ${CUDA_cublas_LIBRARY} ${I$
main.cu 文件如下:
#include <fstream>
#include <cuda.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <ctime>
#include <cuda_runtime_api.h>
#include <cufft.h>
#include "itkImage.h"
using namespace std;
static void HandleError( cudaError_t err, const char *file, int line )
{
if (err != cudaSuccess)
cout<<cudaGetErrorString(err)<<" in "<< file <<" at line "<< line<<endl;
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
int main(int argc, char* argv[])
{
typedef itk::Image< unsigned short, 3 > ImageType;
ImageType::Pointer image = ImageType::New();
cout << "ITK Hello World !" << endl;
int nDevices;
cout<<"DEVICE SPECIFICATIONS: "<<endl<<endl;
HANDLE_ERROR(cudaGetDeviceCount(&nDevices));
return 0;
}
构建时,链接器已设置。我无法弄清楚这里出了什么问题。
我在这里发现了问题,首先我需要使用 cuda_add_executable,而不是 add_executable。这样做并构建,我收到如下错误:
overriding itk::ImageBase<VImageDimension>::Pointer
itk::ImageBase<VImageDimension>::CreateAnother() const [with unsigned int VImageDimension = 3u, itk::ImageBase<VImageDimension>::Pointer = itk::SmartPointer<itk::ImageBase<3u> >]
这是因为 CUDA 编译器无法处理 ITK 使用的 C++ 功能。在 .cxx 文件中使用 ITK 功能并在 .cu 文件中调用 CUDA 函数有帮助。
学分:http://public.kitware.com/pipermail/insight-developers/2012-October/022116.html