小弟的电脑是低配surface,跑vs无奈实在是卡,于是试图用sublime解决问题
按照网上配置,安装了gcc,配置了环境变量,单独构造了编译系统
新建了一个.cpp文件,print hello world,ctrl+b出现cmd窗口,成功输出
然后就找了一个自己之前写的小项目测试
这个项目是分开在了6个文件里三个.cpp三个.h
在main.cpp里面可以正常的看到其他文件中各个类和函数的信息
所以可以确认文件之间的链接关系正常
但是问题来了,在main.cpp里面用ctrl+b编译并运行时
只会在sublime的窗口里面提示finish in xxx s,也不会出cmd窗口
换回单独的.cpp文件再次测试hello world ,一切正常
求教这是哪里出了问题?
贴一下显示的错误信息
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x29): undefined reference to CSPoint::CSPoint(double, double)'
CSPoint::CSPoint(double, double)'
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x4d): undefined reference to
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x61): undefined reference to CSPoint::CSPoint(double, double)'
operator>>(std::istream&, CSPoint&)'
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x96): undefined reference to
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0xbb): undefined reference to operator<<(std::ostream&, CSPoint&)'
operator<<(std::ostream&, CSPoint&)'
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0xdd): undefined reference to
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x131): undefined reference to CSline::CSline(double, double, double, double)'
CSline::CSline(CSPoint&, CSPoint&)'
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x148): undefined reference to
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x166): undefined reference to CSline::display()'
operator<<(std::ostream&, CSline&)'
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x188): undefined reference to
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x19b): undefined reference to CSline::ifin(CSPoint&)'
CSline::~CSline()'
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x1f1): undefined reference to
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x1fc): undefined reference to CSline::~CSline()'
CSPoint::~CSPoint()'
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x208): undefined reference to
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x214): undefined reference to CSPoint::~CSPoint()'
CSPoint::~CSPoint()'
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x223): undefined reference to
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x239): undefined reference to CSline::~CSline()'
CSline::~CSline()'
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x249): undefined reference to
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x25a): undefined reference to CSPoint::~CSPoint()'
CSPoint::~CSPoint()'
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x26b): undefined reference to
C:\Users\nmgxlms\AppData\Local\Temp\cc6b5Ils.o:main.cpp:(.text+0x27f): undefined reference to `CSPoint::~CSPoint()'
最好贴出代码,看下.h的路径是否正确,是否存在交叉引用但是没有先申明的变量或者类
可以用排除法,先简化到两个文件的情况,一个cpp,一个h,看有没有问题。
然后递增文件数。直到找到问题为止
1 有可能引用名称出错
2 将该文件改为xxx.cpp 再在main中引用是可以的