我正在尝试编译一个包含多个源文件的程序 - 两个CPP文件和一个头文件,代码为:: blocks.作为一个例子,我创建了以下三个文件(由另一个论坛上的其他人创建的示例程序):
main.cpp中:
#include <stdio.h>
#include "other.h"
int main (void)
{
printf("%d\n", getfavoritenumber());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
other.cpp
#include "other.h"
int getfavoritenumber(void)
{
return 3;
}
Run Code Online (Sandbox Code Playgroud)
other.h
#ifndef _OTHER_H_
#define _OTHER_H_
int getfavoritenumber(void);
#endif
Run Code Online (Sandbox Code Playgroud)
尽管这三个文件应该相互链接,但是当我尝试构建项目时,我收到错误"跳过链接阶段(构建目标没有要链接的目标文件)".
我究竟做错了什么?尝试编译单个文件会显示错误"该文件未分配给任何目标".