2012-05-30 19 views
1

我正在學習在Linux(Ubuntu 12.04 64位)上構建Qt + CUDA應用程序。對於初學者,我試圖構建一個應用程序來檢查計算機上啓用CUDA的設備的數量。使用CUDA運行時庫的Qt應用程序在雙擊時無法運行

我能夠從Qt Creator中啓動應用程序,但不能通過雙擊應用程序。我可以通過在終端中發佈./device_query來運行它(應用程序的名稱是device_query)。

我有一個簡單的用戶界面(創建Qt的GUI應用程序時由Qt Creator中創建的默認)

這裏有其他文件

mainwindow.h

#ifndef MAINWINDOW_H 
#define MAINWINDOW_H 

#include <QMainWindow> 
#include <cuda_runtime.h> 

namespace Ui { 
class MainWindow; 
} 

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

public: 
    explicit MainWindow(QWidget *parent = 0); 
    ~MainWindow(); 

private: 
    Ui::MainWindow *ui; 


}; 

#endif // MAINWINDOW_H 

mainwindow.cpp

#include "mainwindow.h" 
#include "ui_mainwindow.h" 

MainWindow::MainWindow(QWidget *parent) : 
    QMainWindow(parent), 
    ui(new Ui::MainWindow) 
{ 
    ui->setupUi(this); 

    int count; 
    cudaGetDeviceCount(&count); //when this line is added, unable to double click and launch 

} 

MainWindow::~MainWindow() 
{ 
    delete ui; 
} 

的main.cpp

#include <QtGui/QApplication> 
#include "mainwindow.h" 
#include <QtDebug> 

int main(int argc, char *argv[]) 
{ 
    QApplication a(argc, argv); 
    MainWindow w; 
    w.show(); 
    return a.exec(); 
} 

.pro文件

​​

爲什麼,我不能夠運行通過雙擊它的應用程序?

+0

如果您刪除了所有與CUDA相關的代碼,那麼應用程序在任何情況下都可以正常運行? – Bart

+0

@Bart是的。如果我使用__cudaGetDeviceCount(&count)__行進行編譯,我可以通過雙擊來啓動該應用程序。 – Mathai

+0

對cudaGetDeviceCount的調用返回什麼(如果有)錯誤?可能有一個特權問題? – Bart

回答

1

此問題可能是因爲雙擊應用程序時未爲應用程序設置$ LD_LIBRARY_PATH。在Nsight Eclipse Edition中,我們有一個shell腳本,用於初始化環境,然後啓動IDE - 這樣您就可以從桌面菜單啓動Nsight。