简体   繁体   English

C ++命令行参数Eclipse CDT?

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

I am using an example program from this code http://sicktoolbox.sourceforge.net/ > http://sourceforge.net/projects/sicktoolbox/files/ . 我正在使用此代码中的示例程序http://sicktoolbox.sourceforge.net/ > http://sourceforge.net/projects/sicktoolbox/files/ It's basically a distance scanner driver. 它基本上是一个距离扫描仪驱动程序。 The program I'm trying to run is in sicktoolbox-1.0.1/c++/examples/lms/lms_plot_values in case you wanted to see the code I'm talking about. 我想要运行的程序是在sicktoolbox-1.0.1 / c ++ / examples / lms / lms_plot_values中,以防你想看到我正在谈论的代码。

Anyways, the lms_plot_values project folder contains gnuplot_i.cc, gnuplot_i.hpp, main.cc, Makefile, Makefile.am, Makefile.in. 无论如何,lms_plot_values项目文件夹包含gnuplot_i.cc,gnuplot_i.hpp,main.cc,Makefile,Makefile.am,Makefile.in。 So I put the first three files in my Eclipse Indigo CDT, compile (no compiler errors, everything's correctly linked in Eclipse already and all needed libraries are added), but this sample program is written to take in command line arguments. 所以我把前三个文件放在我的Eclipse Indigo CDT中,编译(没有编译器错误,所有内容都已经在Eclipse中正确链接,并且添加了所有需要的库),但是这个示例程序被编写为接受命令行参数。 Here is as far as the code gets. 这是代码得到的。

/*!
 * \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;
  }

As it says, it throws an error and kills the program, saying it wants me to type "lms_plot_values /dev/ttyUSB0 9600" from the command line to run the program, but I can't do that, and I'm wanting to do everything in eclipse so I don't want to do that. 正如它所说,它抛出一个错误并杀死程序,说它要我从命令行输入“lms_plot_values / dev / ttyUSB0 9600”来运行程序,但我不能这样做,我想要在日食中做所有事情,所以我不想那样做。 I tried adding: 我尝试添加:

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

But that didn't work because of the argc checks. 但由于argc检查,这不起作用。 Do you know if it says to pass in "lms_plot_values /dev/ttyUSB0 9600", why it would be expecting or where it would be getting the argc values from? 你知道它是否说要传入“lms_plot_values / dev / ttyUSB0 9600”,为什么它会期待或从哪里得到argc值? Or how I can make it think these parameters were passed in? 或者我如何让它认为这些参数被传递? I'm not very familiar with how C++ works like this, I've only used Java. 我不太熟悉C ++是如何工作的,我只使用了Java。

Thanks for any help 谢谢你的帮助

You can pass arguments in eclipse too. 你也可以在eclipse中传递参数。 Once you build your project, try creating a run configuration and there you can pass the arguments. 构建项目后,尝试创建运行配置,然后可以传递参数。 Here is the screen shot: 这是屏幕截图:

在此输入图像描述

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM