[英]eclipse C++ add reference undefined reference to method error
我是C ++和ecplice的新手,他们肯定让我很难受:)
我正在尝试编写简单的应用程序,其中包括主项目以及对其他项目的引用
我在共享项目中编写了以下文件:
#ifndef MANAGEDLOG_H_
#define MANAGEDLOG_H_
#include string
#include iostream
#include fstream
using namespace std;
class ManagedLog
{
ofstream _fileStream;
public :
ManagedLog::ManagedLog(string path);
ManagedLog::~ManagedLog();
void ManagedLog::WriteInfoLog(string message,string stackTrace);
};
#endif /* MANAGEDLOG_H_ */
/*
* ManagedLog.cpp
*
* Created on: 18/06/2010
* Author: Eran
*/
#include "ManagedLog.h"
#include iostream
#include fstream
ManagedLog::ManagedLog(string path)
{
_path=path;
}
ManagedLog::~ManagedLog()
{
}
void ManagedLog:: WriteInfoLog(string message,string stackTrace)
{
ofstream myfile;
myfile.open("Eample.txt",ios::app);
myfile.close();
}
并在简单的hello world项目中运行它:
#include "ManagedLog.h" #include using namespace std; int main() { ManagedLog * log = new ManagedLog("path"); log->WriteInfoLog("test","RunLog/Main"); cout but I'm getting this error:
#include "ManagedLog.h" #include using namespace std; int main() { ManagedLog * log = new ManagedLog("path"); log->WriteInfoLog("test","RunLog/Main"); cout but I'm getting this error:
*** Build of configuration Debug for project RunLog **** **** Internal Builder is used for build **** g++ -ID:\\EclipseWorkSpace\\LogManager -O0 -g3 -Wall -c -fmessage-length=0 -osrc\\RunLog.o ..\\src\\RunLog.cpp g++ -LD:\\EclipseWorkSpace\\LogManager\\Release -oRunLog.exe src\\RunLog.o src\\RunLog.o: In function `main': D:/EclipseWorkSpace/RunLog/Debug/../src/RunLog.cpp:13: undefined reference to `ManagedLog::ManagedLog(std::string)' D:/EclipseWorkSpace/RunLog/Debug/../src/RunLog.cpp:14: undefined reference to `ManagedLog::WriteInfoLog(std::string, std::string)' collect2: ld returned 1 exit status Build error occurred, build is stopped Time consumed: 574 ms.
我添加了#include“ ManagedLog.cpp”,代码工作正常,但是我想这不是正确的方法,我对此进行了很多了解,但没有找到我可以暗示的答案,因为我对这个术语没什么了解答案可以有人在这种环境下以正确的方式指向其他项目或dll的方法吗?
谢谢
伊朗
您不是在构建ManagedLog.cpp
。 您的编译顺序应类似于以下示例(为清楚起见已简化):
RunLog.c
到RunLog.o
ManagedLog.c
到ManagedLog.o
RunLog.o
和ManagedLog.o
链接到RunLog.exe
如果您愿意,步骤1和2可以采用其他顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.