我正在使用此代码示例程序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。
感谢您的帮助
问题解决了。哇,非常感谢你!一切都很好。 – user1028641