Ошибка линковки: Linker command failed with exit code 1 - C (СИ)
Формулировка задачи:
main.cpp
lss_19_07.c
lss_19_07.h
#include <stdio.h> #include <stdlib.h> #include <time.h> #include "lss_19_07.h" int d, e; int strncmp(const char *s1, const char *s2, size_t n); int search(char *argv[], const char *param, int argc); int main(int argc, char *argv[]) { d = e = 0; const char *in, *out, *in_, *out_; in = "/Users/doublench/Desktop/zxczxc/zxczxc/lss_19_07_in.txt"; out = "/Users/doublench/Desktop/zxczxc/zxczxc/lss_19_07_out.txt"; if (argc > 1) { if (argv[1][0] == '-' && argc > 5) { perror("Too much parametеrs..."); exit(2); } if (argv[1][0] != '-' && argc > 7) { in_ = argv[1]; out_ = argv[2]; perror("Too much parametеrs..."); exit(2); } } if (argc > 1) { int i; if (argv[1][0] == '-') i = 1; else i = 3; for (; i < argc; ++i) { if (strncmp(argv[i], "-d", 2) == 0 || strncmp(argv[i], "-e", 2) == 0 || strncmp(argv[i], "-p", 2) == 0 || strncmp(argv[i], "-t", 2) == 0 || strncmp(argv[i], "-h", 2) == 0 || strncmp(argv[i], "-?", 2) == 0) { } else { perror("Unknown parameter/s..."); exit(3); } } } if (argc > 2) { int count, i; count = i = 0; char params[4][2] = {{'d', '0'}, {'e', '0'}, {'p', '0'}, {'t', '0'}}; if (argv[1][0] == '-') i = 1; else i = 3; for (; i < argc; ++i) { int j; for (j = 0; j < 4; ++j) { if (argv[i][1] == 'h' || argv[i][1] == '?') count = 1; if (argv[i][1] == params[j][0] && params[j][1] != '0') count = 1; if (argv[i][1] == params[j][0] && params[j][1] == '0') params[j][1] = '1'; } } if (count) { perror("Incorrect set of parameters..."); exit(4); } } if (strncmp(argv[1], "-h", 2) == 0 || strncmp(argv[1], "-?", 2) == 0) { printf("Usage: lss [input_file_name] [output_file_name] [options]\n"); printf("Where options include:\n"); printf(" -d print debug messages [default OFF]\n"); printf(" -e print errors [default OFF]\n"); printf(" -p print matrix [default OFF]\n"); printf(" -t print execution time [default OFF]\n"); printf(" -h,-? print help\n"); exit(0); } if (search(argv, "-e", argc) == 0) e = 1; FILE *fin; if (argv[1][0] == '-') fin = fopen(in, "r"); else fin = fopen(in_, "r"); if (fin == NULL) { if (e == 1) perror("File open error..."); exit(5); } int n; if (fscanf(fin, "%d", &n) != 1) { if (e == 1) perror("Read error..."); exit(6); } if (n <= 0) { if (e == 1) perror("Value of n is less or equal 0..."); exit(7); } double *A, *B, *X; if ((A = (double *) malloc(n * n * sizeof(double))) == NULL) { if (e == 1) perror("Memory allocation error..."); exit(8); } if ((B = (double *) malloc(n * sizeof(double))) == NULL) { if (e == 1) perror("Memory allocation error..."); exit(8); } if ((X = (double *) malloc(n * sizeof(double))) == NULL) { if (e == 1) perror("Memory allocation error..."); exit(8); } int i; for (i = 0; i < n * n; ++i) if (fscanf(fin, "%lf", &A[i]) != 1) { if (e == 1) perror("Read error..."); exit(6); } if (search(argv, "-p", argc) == 0) { printf("Matrix A:\n"); int k; for (k = 1; k <= n * n; ++k) { printf("%lf ", A[k - 1]); if (k % n == 0) printf("\n"); } printf("\n"); } for (i = 0; i < n; ++i) if (fscanf(fin, "%lf", &B[i]) != 1) { if (e == 1) perror("Read error..."); exit(6); } if (fclose(fin)) { if (e == 1) perror("Close error..."); exit(9); } if (search(argv, "-d", argc) == 0) d = 1; clock_t time; if ((time = clock()) == -1) { if (e == 1) perror("Time is unavailable on this system..."); exit(10); } if (lss_19_07(n, A, B, X) == -1) { FILE *fout; if (argv[1][0] == '-') fout = fopen(out, "wb"); else fout = fopen(out_, "wb"); if (fout == NULL) { if (e == 1) perror("File open error..."); exit(5); } if (fprintf(fout, "") < 0) { if (e == 1) perror("Write error..."); exit(11); } // TODO: -1 ? return -1; } time = clock() - time; if (search(argv, "-t", argc) == 0) printf("Time: %f\n", (double) time); FILE *fout; if (argv[1][0] == '-') fout = fopen(out, "wb"); else fout = fopen(out_, "wb"); if (fout == NULL) { if (e == 1) perror("File open error..."); exit(5); } if (fprintf(fout, "%d\n", n) < 0) { if (e == 1) perror("Write error..."); exit(11); } for (i = 0; i < n; ++i) if (fprintf(fout, "%1.9lf\n", X[i]) < 0) { if (e == 1) perror("Write error..."); exit(11); } if (fclose(fout)) { if (e == 1) perror("Close error..."); exit(9); } free(A); free(B); free(X); return 0; } int strncmp(const char *s1, const char *s2, size_t n) { for (; n > 0; s1++, s2++, --n) if (*s1 != *s2) return ((*(unsigned char *) s1 < *(unsigned char *) s2) ? -1 : +1); else if (*s1 == '\0') return 0; return 0; } int search(char *argv[], const char *param, int argc) { int i; for (i = 1; i < argc; ++i) if (strncmp(argv[i], param, 2) == 0) return 0; return -1; }
#include <stdio.h> #include <stdlib.h> #include <time.h> #include "lss_19_07.h" extern int d, e; int lss_19_07(int n, double *A, double *B, double *X) { int i, j, k; double summ; clock_t time; if ((time = clock()) == -1) { if (e == 1) perror("Time is unavailable on this system..."); exit(10); } if (d == 1) { printf("Solving l[i][1]...(i = 1, ..., %d)\n", n); clock_t time1 = clock() - time; printf("Solving done...\n"); printf("Current time: %f\n\n", (double)time1); } if (A[0] == 0) return -1; if (d == 1) printf("Solving u[1][k]...(k = 2, ..., %d)\n", n); for (k = 1; k < n; ++k) A[k] = A[k] / A[0]; if (d == 1) { clock_t time2 = clock() - time; printf("Solving done...\n"); printf("Current time: %f\n\n", (double)time2); } for (i = 1; i < n; ++i) { if (d == 1) printf("Solving l[i][k]...(1<k<=i, i,k = 2, ..., %d)\n", n); for (k = 1; k <= i; ++k) { summ = 0.0; for (j = 0; j <= k - 1; ++j) summ += A[i * n + j] * A[j * n + k]; A[i * n + k] = A[i * n + k] - summ; if (i == k && A[i * n + k] == 0) return -1; } if (d == 1) { clock_t time3 = clock() - time; printf("Solving done...\n"); printf("Current time: %f\n\n", (double)time3); } if (d == 1) printf("Solving u[i][k]...(k>i>1, i,k = 2, ..., %d)\n", n); for (k = i + 1; k < n; ++k) { summ = 0.0; for (j = 0; j <= i - 1; ++j) summ += A[i * n + j] * A[j * n + k]; A[i * n + k] = (A[i * n + k] - summ) / A[i * n + i]; } if (d == 1) { clock_t time4 = clock() - time; printf("Solving done...\n"); printf("Current time: %f\n\n", (double)time4); } } // TODO: проверка несовместимости системы if (d == 1) printf("Solving Ly=B...\n"); X[0] = B[0] / A[0]; for (i = 1; i < n; ++i) { summ = 0.0; for (j = 0; j < i; ++j) summ += A[i * n + j] * X[j]; X[i] = (B[i] - summ) / A[i * n + i]; } if (d == 1) { clock_t time5 = clock() - time; printf("Solving done...\n"); printf("Current time: %f\n\n", (double)time5); } if (d == 1) printf("Solving Ux=y...\n"); for (i = n - 2; i >= 0; --i) { summ = 0.0; for (j = n - 1; j >= i + 1; --j) summ += X[j] * A[i * n + j]; X[i] = X[i] - summ; } if (d == 1) { clock_t time6 = clock() - time; printf("Solving done...\n"); printf("Current time: %f\n\n", (double)time6); } return 0; }
#ifndef INC_07_LSS_19_07_H #define INC_07_LSS_19_07_H int lss_19_07(int n, double *A, double *B, double *X); #endif // INC_07_LSS_19_07_H
"lss_19_07(int, double*, double*, double*)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Решение задачи: «Ошибка линковки: Linker command failed with exit code 1»
textual
Листинг программы
... #ifdef __cplusplus extern "C" { #endif int lss_19_07(int n, double *A, double *B, double *X); #ifdef __cplusplus } #endif ...
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д