本文介绍了&]连结&QUOT; bubblesort函数中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试使用bubblesort方法对数组进行排序。我得到以下链接错误,这是不明确的。我不能使用gdb / valgrind。 I'm trying to sort an array using the bubblesort method. I get the below "link error", which isn't clear. I can't use gdb/valgrind.~/workspace/pset3/find/ $ make helpers clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow helpers.c -lcrypt -lcs50 -lm -o helpers /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2 /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function _start': (.text+0x20): undefined reference tomain' clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [helpers] Error 1 (对不起长度) 非常感谢, 我的尝试: (sorry for the length)Thanks a lot,What I have tried:/** * helpers.c * * Computer Science 50 * Problem Set 3 * * Helper functions for Problem Set 3. */ #include <cs50.h>#include "helpers.h"/** * Returns true if value is in array of n values, else false.*/bool search(int value, int values[], int n){ bool result = false; if (n > 0) { for (int a = 0; a < n; a++) { if (values[a] == value) { result =true; break; } } } return result;}/** * Sorts array of n values - selection sort method 1 *//* Test if array is sorted*/bool sortedtest(int array[]){ int l = sizeof(*array)/sizeof(int); for (int c = 0; c < l-1; c++) { if (array[c] > array[c+1]) { return false; } } return true;}/* bubblesort function*/void sort(int values[], int n){ bool sorted = false; while ( sorted == false) { /*do bubble sort*/ for (int a = 1; a < n-1; a++) { int b; if (values[a] > values[a+1]) { b = values[a+1]; values[a+1] = values[a]; values[a] = b; } } /*use sorted test*/ if (sortedtest(values)) { sorted = true; } } } 推荐答案 (对不起长度) 非常感谢, 我的尝试: (sorry for the length)Thanks a lot,What I have tried:/** * helpers.c * * Computer Science 50 * Problem Set 3 * * Helper functions for Problem Set 3. */ #include <cs50.h>#include "helpers.h"/** * Returns true if value is in array of n values, else false.*/bool search(int value, int values[], int n){ bool result = false; if (n > 0) { for (int a = 0; a < n; a++) { if (values[a] == value) { result =true; break; } } } return result;}/** * Sorts array of n values - selection sort method 1 *//* Test if array is sorted*/bool sortedtest(int array[]){ int l = sizeof(*array)/sizeof(int); for (int c = 0; c < l-1; c++) { if (array[c] > array[c+1]) { return false; } } return true;}/* bubblesort function*/void sort(int values[], int n){ bool sorted = false; while ( sorted == false) { /*do bubble sort*/ for (int a = 1; a < n-1; a++) { int b; if (values[a] > values[a+1]) { b = values[a+1]; values[a+1] = values[a]; values[a] = b; } } /*use sorted test*/ if (sortedtest(values)) { sorted = true; } } } 这篇关于&]连结&QUOT; bubblesort函数中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 14:11