简体   繁体   English

crt1.o:在函数_start中:(.text + 0x20):对main的未定义引用

[英]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.

相关问题 crt1.o函数_start中对&#39;main&#39;错误的未定义引用 - Undefined reference to 'main' error in crt1.o function _start g ++链接问题:在函数`_start'中:(。text + 0x20):对'main'的未定义引用 - g++ link problems: In function `_start': (.text+0x20): undefined reference to `main' 函数`_start&#39;:(。text + 0x20):未定义引用`main&#39;colle2:ld返回1退出状态 - In function `_start': (.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status 从 crt1.o 对 main 的未定义引用 - Undefined reference to main from crt1.o (.text + 0x20):尝试编译.cpp文件时对“ main”的未定义引用 - (.text+0x20): undefined reference to `main' When trying to Compile .cpp file ld:入口点(开始)未定义。 通常在crt1.o中用于架构x86_64 - ld: entry point (start) undefined. Usually in crt1.o for architecture x86_64 g ++在函数__start中链接到crt1.o时遇到致命错误 - g++ encounters a fatal error linking to crt1.o in function __start crt1.o linux x64上没有这样的文件c ++编译错误 - crt1.o no such file c++ compilation error on linux x64 编译错误:未定义符号:“_main”,引用自:从 crt1.10.5.o 开始 - Compile error: Undefined symbols: "_main", referenced from: start in crt1.10.5.o 奇怪的链接器错误涉及`crti.o`和`crt1.o` - Weird linker errors involving `crti.o` and `crt1.o`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM