未定义的引用ld链接器.(C++)



我编写了一个代码,将其拆分为几个.h、.cpp文件两个函数采用字符串类型的参数(下面的代码片段(我得到这个错误:

/usr/bin/ld: /tmp/cclLgueo.o: in function `main':
main.cpp:(.text+0x1dc): undefined reference to `doloop(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: main.cpp:(.text+0x238): undefined reference to 
`detect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status

这是什么意思?代码:

//File: main.cpp (fragment)
string loop;
doloop(loop);

标题:

#ifndef func_h
#define func_h
#include <string>
using namespace std;
void detect(string cmd);
... void
void doloop(string con);
... void
#endif

func.cpp:

void doloop(string con)
{
short y; // Fragment
}
//detect function is similar

##编译器命令:";g++main.cpp";

您需要编译所有的翻译单元:

g++ func.cpp main.cpp

最新更新