简体   繁体   English

程序不在 Visual Studio 上构建

[英]Program not building on Visual studio

The above shows the error I am getting when I build main.cpp from Microsoft Visual Studio以上显示了我从 Microsoft Visual Studio 构建 main.cpp 时遇到的错误
main.cpp file main.cpp 文件

       #include <iostream>
    #include "catalan.h"
    using namespace std;
    int main()
    {
        int selection;
        int number;
       
        }
        return 0;
}

This is the catalan.h file:这是 catalan.h 文件:

#include "implementation.cpp"
int catalan(int n);
int fibonacci(int x);
void menu();

This is the implementation.cpp file这是 implementation.cpp 文件

int catalan(int n)
{
    if (n <= 1)
        return 1;
    int result = 0;
   

    return result;
}
int fibonacci(int x)
{
    return 0;
}
void menu()
{
    std::cout << "1. Do Catalan numbers" << std::endl;
 
}

I have removed some code from it for ease in readability. 为了便于阅读,我从中删除了一些代码。 This same program is compiling 同样的程序正在编译
and running fine with g++ But when I put it on Microsoft Visual Studio it doesnt compile. 并且在 g++ 上运行良好但是当我把它放在 Microsoft Visual Studio 上时它不会编译。
What could be the reason for it and how do it correct it? 可能是什么原因以及如何纠正它? The image of error screenshot can be seen at - 错误截图的图像可以在 -

错误快照:-(

Don't include .cpp files like you do in #include "implementation.cpp" .不要像在#include "implementation.cpp"中那样包含.cpp文件。 Include header files and compile .cpp files.包含 header 文件并编译.cpp文件。

When you've removed #include "implementation.cpp you may be required to add missing #include s to the .cpp file if it currently relies on that you've done #include <iostream> for example.例如,当您删除#include "implementation.cpp时,如果当前依赖于您已完成的#include <iostream>文件,则可能需要将缺少的#include添加到.cpp文件中。

Compiling:编译:

In g++ , it would mean compiling this this:g++中,这意味着编译这个:

g++ main.cpp implementation.cpp -o program_name

In Visual Studio it would mean adding the missing .cpp file to the project.在 Visual Studio 中,这意味着将缺少的.cpp文件添加到项目中。 It should be either main.cpp or implementation.cpp .它应该是main.cppimplementation.cpp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM