Makefile "run" 产生错误但手动执行不会

Makefile "run" yields error but manual exec does not

手动执行二进制文件时,程序执行无误。有谁知道这个 makefile 或源代码有什么问题会使命令“make 运行”产生错误:

这是生成文件:

# QuickSelect
# Author Nick Gallimore
EXE=QuickSelect

GCC=g++
CFLAGS=-Wall -std=c++17

.PHONY : all
all: $(EXE)

# QuickSelect
.PHONY : run
run : QuickSelect
    @./QuickSelect

QuickSelect : QuickSelect.cpp
    $(GCC) $^ $(CFLAGS) -o $@

# clean
.PHONY : clean
clean :
    rm -f $(EXE)

这里是源代码:

// Author Nick Gallimore
// See https://en.wikipedia.org/wiki/Quickselect

#include <vector>
#include <iostream>

int partition(int list[], int left, int right, int pivotIndex) 
{
    int pivotValue = list[pivotIndex];

    int tmp = list[pivotIndex];
    list[pivotIndex] = list[right];
    list[right] = tmp;

    int storeIndex = left;
    for (int i = left; i < right - 1; i++) 
    {
        if (list[i] < pivotValue) 
        {
            tmp = list[storeIndex];
            list[storeIndex] = list[i];
            list[i] = list[storeIndex];

            storeIndex++;
        }
    }

    tmp = list[right];
    list[right] = list[storeIndex];
    list[storeIndex] = list[right];
    return storeIndex;
}

int select(int list[], int left, int right, int k) 
{
    if (left == right)
    {
        return list[left];
    }

    int pivotIndex = right;

    pivotIndex = partition(list, left, right, pivotIndex);

    if (k == pivotIndex)
    {
        return list[k];
    }
    else if (k < pivotIndex) 
    {
        return select(list, left, pivotIndex - 1, k);
    }
    else 
    {
        return select(list, pivotIndex + 1, right, k);
    }
}

int main() 
{
    // init array with random values
    int array[] = {4, 341, 123, 5634, 23, 356, 2887, 76, 45};
    auto result = select(array, 0, sizeof(array[0] / sizeof(*array)), 1);
    std::cout << result << std::endl;
    return result;
}
return result;

您的代码 returns 结果 (4) 作为程序的退出代码。非零退出代码通常被解释为 "error during the execution of the program";通知您的程序以 4 退出并中止,将退出代码打印为错误。