我是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();
}
并在简单的hellow 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:
*** 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”并且代码工作得很好,但我想这不是正确的方法,我读了很多关于它,但没有找到答案,我可以恭维,因为我没有低估这个术语是reanswers,任何人都可以帮助我指出在这种环境中指向其他项目或dll的正确方法吗?
感谢
叶兰
答案 0 :(得分:0)
您没有构建ManagedLog.cpp
。您的编译序列应该类似于此示例(为简洁起见而简化):
RunLog.c
编译为RunLog.o
ManagedLog.c
编译为ManagedLog.o
RunLog.o
和ManagedLog.o
关联到RunLog.exe
步骤1&如果你愿意,2可以是其他顺序。