//Distance.cpp如下: ************************* ************************* **** #include" Distance.h" #include< iostream> 使用命名空间std; / * ------- ------------------------------------------------ * \\ |成员函数的实现ons | \ * --------------------------------- ---------------------- * / //构造函数 距离::距离(int n,char m):nu(n),me(m){} //访问函数 int距离::数字(无效)const { 返回nu; } char距离::测量(无效)const { 返回给我; } //提供<<<"的重载便于展示 ostream&运营商LT;< (ostream& out,const Distance& d) { out<< d.number()<< " - " << d.measure(); 退出; } / * - -------------------------------------------------- --- * \ |距离类的测试驱动程序| \ * ---------------------------- --------------------------- * / #ifdef TEST_DISTANCE // ....远程班....测试司机 int main(无效) { //创建测试输入 距离a =距离(5,KM); cout<< a<< endl; cin ignore(); 返回0; //正常终止 } #endif 解决方案 Chiller写道: 我正处于开发一个代表公制距离的类的早期阶段数字和单位(即KM,M,CM等)。 我已经开发了一些初始代码作为起点;但是,在使用VC ++进行编译时,它不会链接。 我得到的错误信息是 LIBCD.lib(crt0.obj):错误LNK2019:函数_mainCRTStartup中引用的未解析的外部符号_main 如链接器所示:它无法在您尝试链接的内容中找到主函数。 #ifdef TEST_DISTANCE // ....距离类....测试驱动程序 int main(无效) [...] #endif 我在你发布的内容中看不到TEST_DISTANCE的定义。这是通过一些编译器选项设置 定义吗? - Karl Heinz Buchegger kb ****** @ gascad.at Chiller写道: 我正处于开发一个通过存储数字和单位(即KM,M,CM等)来表示度量距离的类的早期阶段。 我已经开发了一些初始代码作为起点;但是,在使用VC ++进行编译时,它不会链接。 我得到的错误信息是 LIBCD.lib(crt0.obj):错误LNK2019:函数_mainCRTStartup中引用的未解析的外部符号_main 如链接器所示:它无法在您尝试链接的内容中找到主函数。 #ifdef TEST_DISTANCE // ....距离类....测试驱动程序 int main(无效) [...] #endif 我在你发布的内容中看不到TEST_DISTANCE的定义。这是通过一些编译器选项设置 定义吗? - Karl Heinz Buchegger kb ****** @ gascad.at > #ifdef TEST_DISTANCE // ....距离类....测试驱动器 int main(无效) //创建测试输入 距离a =距离(5,KM); cout<< a<< endl; cin ignore(); 返回0; //正常终止 } #endif 明显的问题似乎是你没有'' t定义了TEST_DISTANCE。 你确定你开发了这个代码吗?你认为TEST_DISTANCE对于 怎么样?我会删除它。 john I''m in the early stages of developing a class that will represent a metricdistance by storing both a number and unit (ie KM, M, CM etc). I''ve developed some initial code as a starting point; however, it won''t linkduring a compile using VC++. The error message I get is "LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _mainreferenced in function _mainCRTStartup Debug/Message.exe : fatal error LNK1120: 1 unresolved externals"I''ve included the header and source below. Any help would be appreciated. Thanks//Distance.h as follows:********************************************#ifndef DISTANCE_H #define DISTANCE_H #include <iostream> using namespace std; class Distance { public : Distance ( int, char ) ; // constructor (takes int value and string unit ofmeasure ~Distance ( void ) ; // destructor (its name is ~ then class name) //access member functions int number (void) const; char measure (void) const; private : int nu ; // the value char me ; // the unit of measure } ; // provide an overload of "<<" for easy display ostream& operator<< (ostream&, const Distance&); #endif //Distance.cpp as follows: ************************************************** ****#include "Distance.h" #include <iostream> using namespace std; /*-------------------------------------------------------*\ | implementation of member functions | \*-------------------------------------------------------*/ // constructor Distance :: Distance ( int n, char m ) : nu(n), me(m) {} // access functions int Distance :: number (void) const { return nu; } char Distance :: measure (void) const { return me; } // provide an overload of "<<" for easy display ostream& operator<< (ostream& out, const Distance& d) { out << d.number() << "-" << d.measure(); return out; } /*-------------------------------------------------------*\ | test driver for the Distance class | \*-------------------------------------------------------*/ #ifdef TEST_DISTANCE // .... Distance class .... test driver int main ( void ) { // create test input Distance a = Distance (5, KM); cout << a << endl; cin ignore(); return 0; // normal termination } #endif 解决方案 Chiller wrote: I''m in the early stages of developing a class that will represent a metric distance by storing both a number and unit (ie KM, M, CM etc). I''ve developed some initial code as a starting point; however, it won''t link during a compile using VC++. The error message I get is " LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup as the linker says: it cannot find a main function in what you try to link. #ifdef TEST_DISTANCE // .... Distance class .... test driver int main ( void )[...] #endif I cannot see a definition for TEST_DISTANCE in what you have posted. Is thisdefinement set through some compiler options? --Karl Heinz Buchegger kb******@gascad.atChiller wrote: I''m in the early stages of developing a class that will represent a metric distance by storing both a number and unit (ie KM, M, CM etc). I''ve developed some initial code as a starting point; however, it won''t link during a compile using VC++. The error message I get is " LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup as the linker says: it cannot find a main function in what you try to link. #ifdef TEST_DISTANCE // .... Distance class .... test driver int main ( void )[...] #endif I cannot see a definition for TEST_DISTANCE in what you have posted. Is thisdefinement set through some compiler options? --Karl Heinz Buchegger kb******@gascad.at> #ifdef TEST_DISTANCE // .... Distance class .... test driver int main ( void ) { // create test input Distance a = Distance (5, KM); cout << a << endl; cin ignore(); return 0; // normal termination } #endif The obvious problem seems to be that you haven''t defined TEST_DISTANCE. Areyou sure you developed this code? And what do you think TEST_DISTANCE is foranyway? I would just remove it. john 这篇关于链接问题 - 请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 13:31