簡體   English   中英

C ++命令行參數Eclipse CDT?

[英]C++ command line arguments Eclipse CDT?

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

無論如何,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。

謝謝你的幫助

你也可以在eclipse中傳遞參數。 構建項目后,嘗試創建運行配置,然后可以傳遞參數。 這是屏幕截圖:

在此輸入圖像描述

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM