2011-12-05 125 views
11

我正在使用此代碼示例程序http://sicktoolbox.sourceforge.net/>http://sourceforge.net/projects/sicktoolbox/files/。它基本上是一個距離掃描儀驅動程序我試圖運行的程序在sicktoolbox-1.0.1/C++/examples/lms/lms_plot_values中,以防你想看到我正在談論的代碼。C++命令行參數Eclipse CDT?

無論如何,lms_plot_values項目文件夾包含gnuplot_i.cc,gnuplot_i.hpp,main.cc,Makefile,Makefile.am,Makefile.in。因此,我將前三個文件放在Eclipse Indigo CDT中,編譯(沒有編譯器錯誤,所有東西已經在Eclipse中正確鏈接,並且所有需要的庫都已添加),但是此示例程序是爲寫入命令行參數而編寫的。代碼得到的就是這裏。

/*! 
* \file main.cc 
* \brief Illustrates how to acquire a measurements from the Sick 
*  LMS 2xx using the configured measuring mode. 
* 
* Note: This example should work for all Sick LMS 2xx models. 
* 
* Code by Jason C. Derenick and Thomas H. Miller. 
* Contact derenick(at)lehigh(dot)edu 
* 
* The Sick LIDAR Matlab/C++ Toolbox 
* Copyright (c) 2008, Jason C. Derenick and Thomas H. Miller 
* All rights reserved. 
* 
* This software is released under a BSD Open-Source License. 
* See http://sicktoolbox.sourceforge.net 
*/ 

/* Implementation dependencies */ 
#include <stdlib.h> 
#include <string> 
#include <vector> 
#include <signal.h> 
#include <iostream> 
#include <sicklms-1.0/SickLMS.hh> 
#include "gnuplot_i.hpp" 

using namespace std; 
using namespace SickToolbox; 

bool running = true; 
void sigintHandler(int signal); 

int main(int argc, char * argv[]) { 

    string device_str; // Device path of the Sick LMS 2xx 
    SickLMS::sick_lms_baud_t desired_baud = SickLMS::SICK_BAUD_38400; 

    /* Check for a device path. If it's not present, print a usage statement. */ 
    if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) { 
    cout << "Usage: lms_plot_values PATH [BAUD RATE]" << endl 
    << "Ex: lms_plot_values /dev/ttyUSB0 9600" << endl; 
    return -1; 
    } 

,因爲它說,它拋出一個錯誤,並殺死節目,稱這要我輸入「lms_plot_values的/ dev/ttyUSB0 9600」在命令行中運行的程序,但我不能這樣做,我想在日食中做所有事情,所以我不想那樣做。我試圖加入:

argv[1] = "/dev/ttyUSB0"; 
argv[2] = "9600"; 

但是,這並沒有工作,因爲argc檢查。你知道它是否說要傳入「lms_plot_values/dev/ttyUSB0 9600」,爲什麼它會期待或從哪裏獲得argc值?或者我怎樣才能讓它認爲這些參數通過了?我對C++的工作方式不是很熟悉,我只使用了Java。

感謝您的幫助

回答

18

您也可以在eclipse中傳遞參數。一旦你建立你的項目,嘗試創建一個運行配置,你可以傳遞參數。下面是截圖:

enter image description here

enter image description here

+0

問題解決了。哇,非常感謝你!一切都很好。 – user1028641