Makefile“run”产生错误,但是手动exec没有

问题描述 投票:-2回答:1

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

enter image description here

这是makefile:

# 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;
}

如果有人可以提供帮助,我们将不胜感激。很抱歉提出这么简单的问题,只是因为它很简单并不意味着它是一个无效的问题。例如,不要低估复杂性。

c++ makefile gnu-make
1个回答
1
投票
return result;

您的代码返回结果(4)作为程序的退出代码。非零退出代码通常被解释为“程序执行期间的错误”;通知您的程序退出4并中止,打印退出代码为错误。

© www.soinside.com 2019 - 2024. All rights reserved.