代码::块-如何编译多个源文件 [英] Code::Blocks - how to compile multiple source files

查看:86
本文介绍了代码::块-如何编译多个源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用多个源文件(两个CPP文件和一个头文件,使用code :: blocks)编译程序。例如,我创建了以下三个文件(一个示例程序,该程序由其他论坛上的其他人创建):

I'm trying to compile a program with multiple source files - two CPP files and a header file, with code::blocks. As an example, I have created the following three files (an example program created by someone else on another forum):

main.cpp:

#include <stdio.h>
#include "other.h"

int main (void)
{
    printf("%d\n", getfavoritenumber());

    return 0;
}

other.cpp

other.cpp

#include "other.h"

int getfavoritenumber(void)
{
    return 3;
}

other.h

#ifndef _OTHER_H_
#define _OTHER_H_

int getfavoritenumber(void);

#endif

尽管事实上这三个文件应该相互链接,尝试构建项目时收到错误消息跳过链接阶段(构建目标没有要链接的目标文件)。

Despite the fact that these three files should link to each other, I receive the error "Linking stage skipped (build target has no object files to link)" when I try to build the project.

我在做什么错?尝试编译单个文件会出现错误该文件未分配给任何目标。

What am I doing wrong? Trying to compile the individual files presents the error "That file isn't assigned to any target".

推荐答案

对我来说:

转到显示项目的左侧面板,然后右键单击.cpp文件。选择属性,然后进行构建。选中属于目标标题下的框:调试和发布

Go to the left panel that says projects, and right-click on .cpp file. Select properties, then go to build. Check the boxes under the heading Belongs in Targets: "Debug" and "Release"

这篇关于代码::块-如何编译多个源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆