wro*_*ame 1 c++ debugging linker
看起来像我的两个文件,userinterface.h
#ifndef USERINTERFACE_H
#define USERINTERFACE_H
#include <string>
#include "vocabcollection.h"
namespace user_interface
{
//Finds a file
//
//Returns when user selects a file
std::string findFile();
//more comments followed by functions
}
#endif
Run Code Online (Sandbox Code Playgroud)
和用户界面.cpp,
#include "userinterface.h"
using namespace std;
using namespace user_interface;
string findFile()
{
return "./";
}
//more placeholder implementations of such functions; void functions have nothing within
//the brackets
Run Code Online (Sandbox Code Playgroud)
链接器给我带来了一系列错误:
Undefined symbols for architecture x86_64:
make: Leaving directory `longdirectorypath'
"user_interface::showTestResults(int, int)", referenced from:
vocabCollection::test() in vocabcollection.o
"user_interface::get(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
addNewCollection() in mainlogic.o
loadNewCollection() in mainlogic.o
"user_interface::findFile()", referenced from:
loadNewCollection() in mainlogic.o
"user_interface::displayMainMenu(std::vector<vocabCollection, std::allocator<vocabCollection> >)", referenced from:
mainlogic() in mainlogic.o
"user_interface::getUserAction()", referenced from:
mainlogic() in mainlogic.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [cheapassVocab.app/Contents/MacOS/cheapassVocab] Error 1
The process "/usr/bin/make" exited with code 2.
Error while building project cheapassVocab (target: Desktop)
When executing build step 'Make'
Run Code Online (Sandbox Code Playgroud)
这里发生了什么事?
在头文件中,您findFile在名称空间中声明该函数user_interface。在cpp文件中定义了free函数。 findFile是的,你是using namespace user_interface,但编译器不知道findFile那里定义的属于namespace user_interface。所有这一切的结果是您声明user_interface::findFile并定义了::findFile. 当您调用 时user_interface::findFile,链接器找不到它,因为只有 free 函数findFile。
轻松解决-cpp文件:
#include "userinterface.h"
using namespace std;
namespace user_interface
{
string findFile()
{
return "./";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13084 次 |
| 最近记录: |