CodeRunner——不能编译多个源c++程序
CodeRunner-- cannot compile multiple source c++ program
我对c++编程和一般编程都是新手。最近我们一直在课堂上为我们的程序添加头文件和其他源文件(实现)。我试过写最简单的程序,以确保我理解包括多个文件到一个程序的基础知识,但它们不会编译,给我链接器错误。
即:
Undefined symbols for architecture x86_64:
"FooBar::printSomething()", referenced from:
_main in main-d52d70.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
当我在终端中编译"g++ main.cpp implementation.cpp"时,一切正常。
我代码:main.cpp
#include "header.h"
int main()
{
FooBar object;
object.printSomething();
return 0;
}
header.h
#ifndef _Header_h_
#define _Header_h_
#include <iostream>
using namespace std;
class FooBar{
public:
void printSomething();
private:
string helloWorld;
};
#endif
implementation.cpp
#include "header.h"
void FooBar::printSomething(){
helloWorld = "Hello World!n";
cout << helloWorld;
}
我喜欢coderrunner,但这真的让我很沮丧。
谢谢!
对于任何有类似问题的人我已经找到了解决方案:
我错误地使头文件中的类的头文件和实现文件在名称上不同。
header.h应该叫 foobar.h
implementation.cpp应该命名为foobar.cpp
当我将文件名称改为foobar.h和foobar.cpp时,程序在coderrunner中编译并运行良好。
我的教授告诉我,一个类的头文件和它的实现文件应该有相同的名字,不同的文件类型,即x.p和x.h。
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- C++,系统无法执行指定的程序
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 重载操作程序时出错>>用于类中的字符串 memebr
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 试图在visual studio上用C++创建一个桌面应用程序
- 模板元程序查找相似的连续类型名称
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 如何通过cpp程序运行shell脚本
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- IPC使用多个管道和分支进程来运行Python程序
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 基于boost的程序的静态链接——zlib问题
- 程序崩溃并显示"std::out_of_range"错误
- 在C应用程序中运行C++(带有STL)函数
- 使用mongocxx驱动程序时包含头文件问题
- 如何在c++程序中找到函数的地址