c++ - crt1.o : In function `_start' : (.text+0x20): undefined reference to `main'

标签 c++ compiler-errors cmake cuda itk

我有一小段代码,尝试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

关于c++ - crt1.o : In function `_start' : (.text+0x20): undefined reference to `main' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44763796/

相关文章:

c++ boost导致崩溃

c++ - cc1plus : error: unrecognized command line option "-std=c++11" with g++

c++ - 错误 : expected primary-expression before '<=' token

windows - 无法在 Visual Studio 2017 : "Access is denied." 下使用或不使用调试器运行 CMake 可执行文件

c++ - CMake 和 MsVS-NuGet

c++ - 负时间点

c++ - 类名没有命名类型 C++

c++ - 访问超出范围的变量而不传递它们?

c# - 大括号触发编译器警告错误C#

linux - 将 OpenCV 构建为静态库