繁体   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