Sublime Text不能在C ++中编译多文件项目 [英] Sublime Text not compiling multi-file projects in C++

查看:1095
本文介绍了Sublime Text不能在C ++中编译多文件项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编译多文件C ++程序,并有以下错误:

I am to compile a multi-file C++ program, and have the following error;

Undefined symbols for architecture i386:
  "included::printMSG()", referenced from:
      _main in ccQwMj1l.o
ld: symbol(s) not[Finished in 0.3s with exit code 1] found for architecture i386
collect2: ld returned 1 exit status

我的代码:
main.cpp : https://gist.github.com/3845822

included.cpp: https://gist.github.com/3845825

included.cpp: https://gist.github.com/3845825

included.h: https://gist.github.com/3845827

included.h: https://gist.github.com/3845827

(已确认可使用 g ++

编辑:我不是把这些文件放在一个项目,他们只是在同一个文件夹,我正在编译 main.cpp

I am not putting these files in a project, they are just all in the same folder, and I'm compiling main.cpp

推荐答案

您不能只编译一个文件,希望所有其他文件自动链接到它,以创建最终的程序。

You can't just compile a single file and hope all other files are automatically linked to it to create the final program.

一种方法是使用一个名为 make ,它读取一个 Makefile ,其规则为 code>跟随`。

One way to make that happen is to use a program called make, which reads a Makefile that has rules that make follows`.

一个简单的 Makefile 可以是这样:

A simple Makefile can look like this:

CXXFLAGS = -Wall -g

my_pogram: main.o other_file.o third_file.o
    g++ main.o other_file.o third_file.o -o my_program

main.o: main.cpp
    g++ $(CXXFLAGS) -c -o main.o main.cpp

other_file.o: other_file.cpp
    g++ $(CXXFLAGS) -c -o other_file.o other_file.cpp

third_file.o: third_file.cpp
    g++ $(CXXFLAGS) -c -o third_file.o third_file.cpp

还有其他类似的程序来处理。受欢迎的是 CMake

There are other similar programs to handle this. One that is popular is CMake.

这篇关于Sublime Text不能在C ++中编译多文件项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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