nvlink : error : Undefined reference when trying to write to text file

隐身守侯 提交于 2019-12-06 13:37:55

Your simple code

#include <iostream>
#include <fstream>
using namespace std;

int main () {
    ofstream myfile;
    myfile.open ("example.txt");
    myfile << "Writing this to a file.\n";
    myfile.close();
    return 0;
}

compiled with the -rdc=true option was giving the nvlink error you reported. This can be due to failing to use statically loaded C runtime to match the CUDA runtime. This can be fixed by

Project -> Properties -> Configuration Properties -> CUDA C/C++ -> Host -> Runtime Library 

and the choose

Multi-Threaded Debug (/MTd)

if you are in Debug mode or

Multi-Threaded (/MT)

if you are in Release mode.

I hope that this fixes your problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!