انجمنهای فارسی اوبونتو
کمک و پشتیبانی => برنامهسازی => نویسنده: ramintehranchi در 13 شهریور 1391، 02:05 بظ
-
سلام.من میخام یه نرم افزاری که تو C نوشته شده رو اجرا کنم ولی نمی تونم. اگه از دوستان لطف کنن میلشونو بگن من اون نرم افزارو واسشون میفرستم. من هدفم انه که ازش فقط خروجی بگیرم. ممنون
-
اگه توی نرم افزارت از کتابخونه خاصی استفاده نشده میتونی اینجوری کامپایلش کنی.
gcc YourProgram.c -o YourProgramExecutable
البته قبلش باید بری توی همون دایرکتوری که سورس هست.
بعد هم اینجوری اجراش کن.
./YourProgramExecutable
-
من یه تازه کارم.اصلا نمیدونم اینایی که شما گفتید کجا وارد کنم.از نرم افزار Blockcode واسه اجرا کردنش استفاده کردم ولی پیغام داد که فایل G++ رو نداره
-
codeblocks یه IDE هستش که برای c++ ه. برای اینکه c++ بنویسید نیاز دارید g++ رو روی لینوکس نصب کنید. ولی برنامه شما c هست نیازی ندارید که چیزی نصب کنید. کامپایلر gcc روی لینوکس نصب هست.
بزارید دستورات رو یکی یکی بهتون بگم. فرض میکنیم که اسم فایل سورس شما source.c باشه و فایل اجرایی ای که میخواهید بسازید output اسمش باشه و فایل source.c روی desktop باشه.
شما کلیدهای ctrl+alt+t رو بزنید تا یه صفحه ترمینال باز بشه.بعد بنویسید
cd Desktop
حالا شما توی desktop هستید. حالا بنویسید
gcc source.c -o output
اگه پیغام خطایی نده فایل شما کامپایل شده. حالا برای اجراش بنویسید
./output
و اینطوری فایل رو اجرا میکنه.
دقت کنید که توی همه مراحل بزرگی و کوچکی حروف اشتباه نشه. ترمینال لینوکس به بزرگی و کوچکی حروف حساسه.
-
خیلی ممنون از راهنمااییتون.وقتی میزنم کامپایل شه این پعغامو میده:
undefined refrence to
-
اینی که شما نوشتید ناقصه.
بقیش کو؟
-
undefined refrence to چی؟
-
ramin@ubuntu:~/Desktop/cats_v3.1.2/analysis$ gcc cats.c -o output
/tmp/ccyQCpXQ.o: In function `main':
cats.c:(.text+0xe53): undefined reference to `read_cats_series'
cats.c:(.text+0xf13): undefined reference to `read_rlrdata'
cats.c:(.text+0x114f): undefined reference to `decode_model_string'
cats.c:(.text+0x12ac): undefined reference to `print_model'
cats.c:(.text+0x1333): undefined reference to `create_A_and_d'
cats.c:(.text+0x1394): undefined reference to `create_A_and_d'
cats.c:(.text+0x1584): undefined reference to `create_spectrum'
cats.c:(.text+0x17be): undefined reference to `mle_wrapper'
cats.c:(.text+0x190f): undefined reference to `psd_wrapper'
cats.c:(.text+0x1a39): undefined reference to `emp_wrapper'
cats.c:(.text+0x1b63): undefined reference to `wls_wrapper'
cats.c:(.text+0x1c85): undefined reference to `sqrt'
cats.c:(.text+0x1db8): undefined reference to `print_model'
collect2: ld returned 1 exit status
-
میشه کدت رو هم بذاری ببینیم؟
-
توی کدت از header دیگه ای هم استفاده کردی؟
این تغییر رو واسه کامپایل کردن بده.
gcc cats.c -o output -lm
یه خورده از error ها کمتر میشه ولی فکر کنم بازم همش از بین نره.
-
#include "timeseries.h"
#include <getopt.h>
main(int argc, char **argv) {
int i, c, j, k, l, n, bf;
int p_alloc, n_periods;
int columns, error, n_harm;
int got_outfile, got_psdfile, got_kernelfile;
int n_models;
int filetype, no_elem;
int n_used_series;
int sm, n_psd;
int got_sf;
int estimate_trend;
char period_type;
char *outfile = NULL;
char *psdfile = NULL;
char *kernel_file = NULL;
char *model_string[100];
char word[512];
double a[3], p, scale_factor;
double *period, *P, *f;
time_series ts;
noise_model *nm;
options op;
data_kernel dk;
time_t start_time, end_time;
clock_t time1, time2;
struct tm *loctime;
struct utsname uts;
struct passwd *pw;
/*****************************/
/* Initialize some variables */
/*****************************/
got_sf = 0;
filetype = 1;
n_models = 0;
error = 0;
got_outfile = 0;
got_psdfile = 0;
got_kernelfile = 0;
estimate_trend = 1;
columns = -1;
p_alloc = 100;
n_periods = 0;
period = (double *) calloc((size_t)p_alloc, sizeof(double));
op.est_method = 1;
op.cov_method = 1;
op.verbose = 0;
op.speed = 0;
op.input_method = 5;
op.tol = (double *) calloc((size_t)4, sizeof(double));
op.tol[0] = 400.0;
op.tol[1] = 0.000001;
op.tol[2] = 0.000020;
/* op.tol[3] = 0.000001; */
op.tol[3] = 0.0001;
op.delta = 1.5;
op.fpout = NULL;
op.fpsd = NULL;
op.fpkernel = NULL;
scale_factor = 1.0;
/*******************/
/* Get the options */
/*******************/
while (1) {
int option_index = 0;
static struct option long_options[] = {
{"model", 1, 0, 'M'},
{"method", 1, 0, 'B'},
{"columns", 1, 0, 'C'},
{"scale", 1, 0, 'S'},
{"sinusoid", 1, 0, 'A'},
{"verbose", 0, 0, 'v'},
{"Verbose", 0, 0, 'V'},
{"speed", 1, 0, 'Z'},
{"help", 0, 0, 'H'},
{"quick", 1, 0, 'Q'},
{"delta", 1, 0, 'D'},
{"tolerance", 1, 0, 'T'},
{"output", 1, 0, 'O'},
{"filetype", 1, 0, 'F'},
{"kernel", 1, 0, 'K'},
{"psdfile", 1, 0, 'P'},
{"notrend", 0, 0, 'E'},
{"cov_form", 1, 0, 'X'}
};
c = getopt_long( argc, argv, "m:M:b:B:c:C:s:S:a:A:vVz:Z:hHq:Q:d:D:t:T:o:O:k:K:f:F:p:P:eEx:X:", long_options, &option_index);
if (c == -1) break;
switch (c) {
case 0:
break;
case 'm':
case 'M':
model_string[n_models++] = optarg;
break;
case 'b':
case 'B':
switch (optarg[0]) {
case 'm':
case 'M':
op.est_method = 1;
break;
case 's':
case 'S':
op.est_method = 2;
break;
case 'e':
case 'E':
op.est_method = 3;
break;
case 'w':
case 'W':
op.est_method = 4;
break;
default:
fprintf(stderr, " Unknown estimation method : choose from mle, spectral, empirical, wls.\n");
error++;
break;
}
break;
case 'c':
case 'C':
n = sscanf(optarg, "%d", &columns);
if (n != 1) error++;
break;
case 's':
case 'S':
n = sscanf(optarg, "%lf", &scale_factor);
if (n != 1) error++;
got_sf = 1;
break;
case 'a':
case 'A':
n = sscanf(optarg, "%lf%c%d", &p, &period_type,&n_harm);
if (n == 2) n_harm = 0;
switch (period_type) {
case 'd':
for (j = 0; j <= n_harm; j++) {
period[n_periods++] = p / (double) (j+1) / 365.24219;
if (n_periods == p_alloc) {
p_alloc += 16;
period = (double *) realloc( (void *)period, p_alloc * sizeof(double) );
}
}
break;
case 'y':
for (j = 0; j <= n_harm; j++) {
period[n_periods++] = p / (double) (j+1);
if (n_periods == p_alloc) {
p_alloc += 16;
period = (double *) realloc( (void *)period, p_alloc * sizeof(double) );
}
}
break;
case 'h':
for (j = 0; j <= n_harm; j++) {
period[n_periods++] = p / (double) (j+1) / 24.0 / 365.24219;
if (n_periods == p_alloc) {
p_alloc += 16;
period = (double *) realloc( (void *)period, p_alloc * sizeof(double) );
}
}
break;
case 'm':
for (j = 0; j <= n_harm; j++) {
period[n_periods++] = p / (double) (j+1) / 24.0 / 60.0 / 365.24219;
if (n_periods == p_alloc) {
p_alloc += 16;
period = (double *) realloc( (void *)period, p_alloc * sizeof(double) );
}
}
break;
case 's':
for (j = 0; j <= n_harm; j++) {
period[n_periods++] = p / (double) (j+1) / 24.0 / 3600.0 / 365.24219;
if (n_periods == p_alloc) {
p_alloc += 16;
period = (double *) realloc( (void *)period, p_alloc * sizeof(double) );
}
}
break;
default:
error++;
fprintf(stderr, "Error defining a sinusoid period\n");
}
break;
case 'v':
op.verbose = 1;
break;
case 'V':
op.verbose = 2;
break;
case 'x':
case 'X':
n = sscanf(optarg, "%d", &op.cov_method);
if (n != 1) error++;
if (op.cov_method != 1 || op.cov_method != 2) error++;
break;
case 'z':
case 'Z':
n = sscanf(optarg, "%d", &op.speed);
if (n != 1) error++;
if (op.speed < 0 || op.speed > 3) error++;
break;
case 'h':
case 'H':
error++;
break;
case 'd':
case 'D':
n = sscanf(optarg, "%lf", &op.delta);
if (n != 1) error++;
if (op.delta <= 1.0) error++;
break;
case 't':
case 'T':
n = sscanf (optarg, "%lf/%lf/%lf", &op.tol[1], &op.tol[2], &op.tol[3]);
if (n != 3) {
error++;
fprintf(stderr, "Must specify 3 parameters -T tol1/tol2/tol3\n");
}
break;
case 'o':
case 'O':
outfile = optarg;
got_outfile = 1;
break;
case 'k':
case 'K':
kernel_file = optarg;
got_kernelfile = 1;
break;
case 'f':
case 'F':
if (strncmp(optarg,"cats",4) == 0) {
filetype = 1;
} else if (strncmp(optarg,"psmsl",4) == 0) {
filetype = 2;
} else {
fprintf(stderr, " filetype %s must be cats or psmsl.\n", optarg);
error++;
}
break;
case 'p':
case 'P':
psdfile = optarg;
got_psdfile = 1;
break;
case 'e':
case 'E':
estimate_trend = 0;
break;
}
}
if (got_outfile) {
if ((op.fpout = fopen(outfile,"a+")) == NULL) {
fprintf(stderr, "%s : Cannot open file %s\n", argv[0], outfile);
exit(EXIT_FAILURE);
}
} else op.fpout = stdout;
if (got_psdfile) {
if ((op.fpsd = fopen(psdfile,"w")) == NULL) {
fprintf(stderr, "%s : Cannot open file %s\n", argv[0], psdfile);
exit(EXIT_FAILURE);
}
}
if (op.verbose) {
fprintf(op.fpout, " Cats Version : %s\n", version);
fprintf(op.fpout, " Cats command :");
for (i = 0; i < argc; i++) fprintf(op.fpout, " %s", argv[i]);
fprintf(op.fpout, "\n");
}
if (error) {
fprintf(stderr, " Cats Version : %s\n", version);
fprintf(stderr, " Cats command :");
for (i = 0; i < argc; i++) fprintf(stderr, " %s", argv[i]);
fprintf(stderr, "\n Please look in Manual for command syntax.\n");
exit(EXIT_FAILURE);
}
/************************************************************************/
/* Now output some information about file, machine and operating system */
/* Useful for comparisons */
/* Also who ran the program */
/************************************************************************/
uname(&uts);
fprintf(op.fpout, " Data from file : %s\n", argv[optind]);
fprintf(op.fpout, " %s : running on %s\n", argv[0], uts.nodename);
fprintf(op.fpout, " %s release %s (version %s) on %s\n", uts.sysname, uts.release, uts.version, uts.machine);
if ((pw = getpwuid (getuid ())) != NULL) {
fprintf(op.fpout, " userid : %s\n\n", pw->pw_name);
} else {
fprintf(op.fpout, " userid : unknown\n\n");
}
no_elem = argc-optind;
if (no_elem > 0) {
if (no_elem > 1) fprintf(stderr, " There are %d non-option elements : using the first as the input file\n", no_elem);
if (filetype == 1) {
if (!got_sf) scale_factor = 1000.0;
ts = read_cats_series(argv[optind],op,scale_factor,columns);
} else if (filetype == 2) {
if (!got_sf) scale_factor = 1.0;
ts = read_rlrdata(argv[optind],op,scale_factor);
} else {
fprintf(stderr, "Unrecognized input file type\n");
error++;
/* exit(EXIT_FAILURE); */
}
} else {
fprintf(stderr, " An input file hasnt been specified\n");
error++;
/* exit(EXIT_FAILURE); */
}
if (error) {
fprintf(stderr, " Cats Version : %s\n", version);
fprintf(stderr, " Cats command :");
for (i = 0; i < argc; i++) fprintf(stderr, " %s", argv[i]);
fprintf(stderr, "\n Please look in Manual for command syntax.\n");
exit(EXIT_FAILURE);
}
/*****************************************/
/* count the number of series being used */
/*****************************************/
fprintf(op.fpout, " Number of series to process : %d\n", ts.n_series);
/****************************************/
/* Now presumably we are ready to go... */
/****************************************/
start_time = time(NULL);
time1 = clock();
loctime = localtime(&start_time);
fprintf(op.fpout, " Start Time : %s\n", asctime(loctime));
/*******************************************/
/* The main loop, loops through the series */
/*******************************************/
for (c = 0; c < ts.n_series; c++) {
/********************************************/
/* Now process the stochastic models to use */
/********************************************/
nm = (noise_model *) calloc((size_t) (n_models), sizeof(noise_model));
for (j = 0; j < n_models; j++) {
nm[j] = decode_model_string(model_string[j],c);
nm[j].c_id = ts.c_id[c];
print_model(nm[j], op, 1.0);
}
ts.current_series = c;
/******************************************************************/
/* At some point add in the ability to read data kernel from file */
/******************************************************************/
if (got_kernelfile) {
/* dk = create_A_and_d_from_file(ts, c, kernel_file); */
dk = create_A_and_d(ts, period, n_periods, c, estimate_trend);
} else {
dk = create_A_and_d(ts, period, n_periods, c, estimate_trend);
}
if (got_psdfile || op.est_method == 2) {
P = (double *) calloc((size_t) dk.n_data, sizeof(double));
f = (double *) calloc((size_t) dk.n_data, sizeof(double));
n_psd = create_spectrum(P, f, ts, dk, op);
P = (double *) realloc( (void *)P, n_psd * sizeof(double));
f = (double *) realloc( (void *)f, n_psd * sizeof(double));
if (got_psdfile) {
for (j = 0; j < n_psd; j++) fprintf(op.fpsd,"%g %g\n", f[j], P[j] );
fprintf(op.fpsd, "0 0\n");
}
}
/*********************************************************************/
/* Now check the model options against the estimation method options */
/*********************************************************************/
switch(op.est_method) {
case 1:
mle_wrapper(nm,n_models,ts,dk,op);
break;
case 2:
psd_wrapper(nm,n_models,ts,dk,op,P,f,n_psd);
break;
case 3:
emp_wrapper(nm,n_models,ts,dk,op);
break;
case 4:
wls_wrapper(nm,n_models,ts,dk,op);
break;
}
if (got_psdfile || op.est_method == 2) {
free(P);
free(f);
}
/***********************/
/* Output results here */
/***********************/
fprintf(op.fpout, "+%s MLE : %12.6f\n", comp_names[ts.c_id[c]], dk.MLE[0]);
for (j = 0; j < dk.n_par; j++) {
fprintf(op.fpout, "+%s ", comp_names[ts.c_id[c]]);
fprintf(op.fpout, " %s ", par_names[dk.name_id[j]]);
fprintf(op.fpout, " %11.4f +- %11.4f\n", dk.params[j], sqrt(dk.covar[j + j * dk.n_par]));
}
for (j = 0; j < n_models; j++) print_model(nm[j],op,1.0);
for (j = 0; j < n_models; j++) {
if (nm[j].n_pvec > 0) {
free(nm[j].names);
free(nm[j].pvec_flag);
free(nm[j].pvec);
free(nm[j].pvec_sigma);
}
free(nm[j].sigma);
free(nm[j].dsigma);
free(nm[j].sigma_flag);
}
free(nm);
free(dk.A);
free(dk.d);
free(dk.dd);
free(dk.name_id);
free(dk.alt_id);
free(dk.params);
free(dk.covar);
free(dk.MLE);
}
free(ts.index);
free(ts.off_code);
free(ts.c_id);
free(ts.t);
free(ts.data);
free(ts.formal_error);
free(ts.offsets);
free(period);
free(op.tol);
end_time = time(NULL);
time2 = clock();
loctime = localtime(&end_time);
fprintf(op.fpout, " End Time : %s\n", asctime(loctime));
fprintf(op.fpout, " Total Time : %lg\n", difftime(end_time, start_time) );
if (op.fpout != stdout) fclose(op.fpout);
if (got_psdfile) fclose(op.fpsd);
}
-
وقتی -lm رو اضافه کردم یکیش کمتر شد
-
کاش کدت رو توی تگ code میزاشتی. بی زحمت متنت رو ویرایش کن. اون علامت # رو که بالای متن پاسخ هست بزن و کدت رو توی اون paste کن.
اون دو تا هدر هم توی همین دایرکتوری هستن؟
-
ویرایشش کردم. بله. همشون تو یه دایرکتوری هستند
-
این رو اضافه کنن ببین چی میشه:
$sudo apt-get install libdolfin1.0-dev
-
نتیجش این میشه:
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
-
البته وقتی دستورو بدون $ می نویسم نتیجش این میشه:
[sudo] password for ramin
که هیچی نمیشه تایپ کرد
-
گزینه دوم درسته.
اون چیزی که تایپ میکنی رو نشونت نمیده. وقتی اونو نوشت پسوردت رو بنویس و اینتر بزن.
-
اینم نتیجش:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libdolfin1.0-dev
E: Couldn't find any package by regex 'libdolfin1.0-dev'
-
لازمه قبلش بزنی
$ sudo apt-get update