我如何在没有项目的情况下 link CodeBlocks 中的 2 个文件?
How can I link 2 files in CodeBlocks without having a project?
我想使用头文件(header.h
和 header.cpp
),但我没有使用项目。有没有什么办法可以 link 这些文件在一起,或者让一个项目成为唯一的解决方案?
我目前遇到的问题:
main.cpp
#include "class.h"
int main()
{
MyClass test;
}
class.h
class MyClass
{
public:
int x;
MyClass();
};
class.cpp
#include "class.h"
MyClass::MyClass() : x(0) {}
错误:对“MyClass::MyClass()”的未定义引用
如果您没有使用项目,则无法使用 CodeBlocks 对其进行编译。您可以手动编译代码,使用 g++,例如,将是这样的:g++ -o myprog main.cpp class.cpp
。如果您使用的是其他编译器,那么您将不得不寻找它的命令。
我想使用头文件(header.h
和 header.cpp
),但我没有使用项目。有没有什么办法可以 link 这些文件在一起,或者让一个项目成为唯一的解决方案?
我目前遇到的问题:
main.cpp
#include "class.h"
int main()
{
MyClass test;
}
class.h
class MyClass
{
public:
int x;
MyClass();
};
class.cpp
#include "class.h"
MyClass::MyClass() : x(0) {}
错误:对“MyClass::MyClass()”的未定义引用
如果您没有使用项目,则无法使用 CodeBlocks 对其进行编译。您可以手动编译代码,使用 g++,例如,将是这样的:g++ -o myprog main.cpp class.cpp
。如果您使用的是其他编译器,那么您将不得不寻找它的命令。