MACでの即行きセンサのプログラム

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
saito

MACでの即行きセンサのプログラム

#1

投稿記事 by saito » 6年前

側域センサust-10lxを研究で使おうと考えていますが、北陽のサンプルプログラムを実行しようとしたところ、
エラーが発生し実行できない状況です。
実際に動かしている方の意見や、解決策として考えられることを教えていただきたいです。

開発環境
MACOS Sierra 10.12.6
gcc

プログラム
/*!
\example get_distance.c Obtains distance data
\author Satofumi KAMIMURA

$Id$
*/

#include "urg_sensor.h"
#include "urg_utils.h"
#include "open_urg_sensor.h"
#include <stdlib.h>
#include <stdio.h>


static void print_data(urg_t *urg, long data[], int data_n, long time_stamp)
{
#if 1
int front_index;

(void)data_n;

// Shows only the front step
front_index = urg_step2index(urg, 0);
printf("%ld [mm], (%ld [msec])\n", data[front_index], time_stamp);

#else
(void)time_stamp;

int i;
long min_distance;
long max_distance;

// Prints the X-Y coordinates for all the measurement points
urg_distance_min_max(urg, &min_distance, &max_distance);
for (i = 0; i < data_n; ++i) {
long l = data;
double radian;
long x;
long y;

if ((l <= min_distance) || (l >= max_distance)) {
continue;
}
radian = urg_index2rad(urg, i);
x = (long)(l * cos(radian));
y = (long)(l * sin(radian));
printf("(%ld, %ld), ", x, y);
}
printf("\n");
#endif
}
pragma comment(lib, "Ws2_32.lib")


int main(int argc, char *argv[])
{
enum {
CAPTURE_TIMES = 10,
};
urg_t urg;
long *data = NULL;
long time_stamp;
int n;
int i;

if (open_urg_sensor(&urg, argc, argv) < 0) {
return 1;
}

data = (long *)malloc(urg_max_data_size(&urg) * sizeof(data[0]));
if (!data) {
perror("urg_max_index()");
return 1;
}

// Gets measurement data
#if 0
// Case where the measurement range (start/end steps) is defined
urg_set_scanning_parameter(&urg,
urg_deg2step(&urg, -90),
urg_deg2step(&urg, +90), 0);
#endif

urg_start_measurement(&urg, URG_DISTANCE, URG_SCAN_INFINITY, 0);
for (i = 0; i < CAPTURE_TIMES; ++i) {
n = urg_get_distance(&urg, data, &time_stamp);
if (n <= 0) {
printf("urg_get_distance: %s\n", urg_error(&urg));
free(data);
urg_close(&urg);
return 1;
}
print_data(&urg, data, n, time_stamp);
}

// Disconnects
free(data);
urg_close(&urg);

#if defined(URG_MSC)
getchar();
#endif
return 0;
}

結果
get_distance.c:8:10: fatal error: 'urg_sensor.h' file not found
#include "urg_sensor.h"
^~~~~~~~~~~~~~
1 error generated.
saitolab-no-iMac2015:c inohideaki$ gcc get_distance.c
Undefined symbols for architecture x86_64:
"_open_urg_sensor", referenced from:
_main in get_distance-52a2ed.o
"_urg_close", referenced from:
_main in get_distance-52a2ed.o
"_urg_error", referenced from:
_main in get_distance-52a2ed.o
"_urg_get_distance", referenced from:
_main in get_distance-52a2ed.o
"_urg_max_data_size", referenced from:
_main in get_distance-52a2ed.o
"_urg_start_measurement", referenced from:
_main in get_distance-52a2ed.o
"_urg_step2index", referenced from:
_print_data in get_distance-52a2ed.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
saitolab-no-iMac2015:c inohideaki$ gcc urg_sensor.h
saitolab-no-iMac2015:c inohideaki$ gcc get_distance.c
Undefined symbols for architecture x86_64:
"_open_urg_sensor", referenced from:
_main in get_distance-5c913b.o
"_urg_close", referenced from:
_main in get_distance-5c913b.o
"_urg_error", referenced from:
_main in get_distance-5c913b.o
"_urg_get_distance", referenced from:
_main in get_distance-5c913b.o
"_urg_max_data_size", referenced from:
_main in get_distance-5c913b.o
"_urg_start_measurement", referenced from:
_main in get_distance-5c913b.o
"_urg_step2index", referenced from:
_print_data in get_distance-5c913b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
saitolab-no-iMac2015:c inohideaki$ ls
Makefile get_distance_intensity.c open_urg_sensor.o urg_detect_os.h
angle_convert_test.c get_multiecho reboot_test.c urg_errno.h
calculate_xy get_multiecho.c sensor_parameter urg_ring_buffer.h
calculate_xy.c get_multiecho_intensity sensor_parameter.c urg_sensor.h
find_port get_multiecho_intensity.c sync_time_stamp urg_sensor.h.gch
find_port.c ld_setupapi.sh sync_time_stamp.c urg_serial.h
get_distance ld_wsock.sh timeout_test.c urg_serial_utils.h
get_distance.c open_urg_sensor.c urg_connection.h urg_tcpclient.h
get_distance_intensity open_urg_sensor.h urg_debug.h urg_utils.h
saitolab-no-iMac2015:c inohideaki$ gcc get_distance.c
get_distance.c:52:1: error: unknown type name 'pragma'
pragma comment(lib, "Ws2_32.lib")
^
get_distance.c:52:21: error: expected identifier
pragma comment(lib, "Ws2_32.lib")
^
get_distance.c:52:34: error: expected ';' after top level declarator
pragma comment(lib, "Ws2_32.lib")
^
;
3 errors generated.
saitolab-no-iMac2015:c inohideaki$ gcc get_distance.c
get_distance.c:52:1: error: unknown type name 'pragma'
pragma comment(lib, "Ws2_32.lib")
^
get_distance.c:52:21: error: expected identifier
pragma comment(lib, "Ws2_32.lib")
^
get_distance.c:52:34: error: expected ';' after top level declarator
pragma comment(lib, "Ws2_32.lib")
^
;
3 errors generated.
saitolab-no-iMac2015:c inohideaki$ gcc get_distance.c
Undefined symbols for architecture x86_64:
"_open_urg_sensor", referenced from:
_main in get_distance-e29669.o
"_urg_close", referenced from:
_main in get_distance-e29669.o
"_urg_error", referenced from:
_main in get_distance-e29669.o
"_urg_get_distance", referenced from:
_main in get_distance-e29669.o
"_urg_max_data_size", referenced from:
_main in get_distance-e29669.o
"_urg_start_measurement", referenced from:
_main in get_distance-e29669.o
"_urg_step2index", referenced from:
_print_data in get_distance-e29669.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

urg_sensor.h というファイルは同じディレクトリに入っております。

どのように改善すればよろしいでしょうか。
よろしくお願いします。

“C言語何でも質問掲示板” へ戻る