[英]crt1.o: In function `_start': (.text+0x20): undefined reference to `main'
I have a small piece of code, which gives this error when trying to make
, here is the CMakelists.txt being used: 我有一小段代码,尝试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$
The main.cu file is below: 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;
}
While building, the linkers are set. 构建时,将设置链接器。 I am unable to figure out what is wrong here. 我无法弄清楚这里出了什么问题。
I found the issue here, firstly as pointed I needed to use cuda_add_executable, instead of add_executable. 我在这里找到了问题,首先,我需要使用cuda_add_executable而不是add_executable。 Doing that and building, I get errors like: 这样做并构建时,出现如下错误:
overriding itk::ImageBase<VImageDimension>::Pointer
itk::ImageBase<VImageDimension>::CreateAnother() const [with unsigned int VImageDimension = 3u, itk::ImageBase<VImageDimension>::Pointer = itk::SmartPointer<itk::ImageBase<3u> >]
These are because the CUDA compiler has trouble with the C++ features used by ITK. 这是因为CUDA编译器在ITK使用的C ++功能上遇到了麻烦。 Using the ITK features in a .cxx file and calling CUDA functions in .cu file helped. 在.cxx文件中使用ITK功能并在.cu文件中调用CUDA功能很有帮助。
Credits: http://public.kitware.com/pipermail/insight-developers/2012-October/022116.html 鸣谢: http : //public.kitware.com/pipermail/insight-developers/2012-October/022116.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.