【问题标题】:"./main: not found" (C++, RP 3/B, Geany IDE)\"./main: not found\" (C++, RP 3/B, Geany IDE)
【发布时间】:2022-11-28 09:31:37
【问题描述】:

我正在尝试编写一个简单的程序来调用在一对 Header 和 CPP 文件中编写的函数。

我在 Raspberry Pi 3 Model B 和 Geany IDE v1.37.1 上执行此操作。

编译命令:

g++ -Wall -c "%f" -c test.cpp

构建命令:

g++ -Wall -o "%e" "%f" -o test test.cpp

main.cpp:

#include "test.h"

int main()
{
    test_function();
    
    return 0;
}

test.h:

#ifndef _test_h_
#define _test_h_

#include <iostream>

void test_function();

#endif

test.cpp:

#include "test.h"

void test_function()
{
    std::cout << "hello world";
}

上面的代码可以很好地编译和构建,但是尝试运行它会产生以下错误:

./main: not found

(program exited with code: 127)

也许我把编译和构建命令搞砸了?

感谢您阅读我的帖子,感谢任何指导!

【问题讨论】:

    标签: c++ geany


    【解决方案1】:

    注意编译命令:

    -o test

    这意味着输出二进制文件将是test,因此您可以通过./test调用它。

    【讨论】:

    • “通过 ./test 调用它”是什么意思?你的意思是将我的“主要”功能重命名为“测试”?
    • @Runsva 不,函数名很好。 “试图运行”——你如何尝试运行它?通常,您会以./test 的形式运行它。或者,如果 IDE 正在为您运行它,您可以使用 -o main 而不是 -o test
    猜你喜欢
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多