C ++错误:未定义的函数引用

时间:2013-12-25 17:02:54

标签: c++ g++

我有三个文件:

两个.cpp文件(Reader.cpp和algo.cpp)和一个头文件(algo.h)。

在Reader.cpp文件中,其函数PacketHandler调用algo.cpp中的函数。

Reader.cpp

void PacketHandler(Packet* sniff_packet, void* user) {
    std::string payload;
    RawLayer* raw_payload = sniff_packet->GetLayer<RawLayer>();
    if (raw_payload) {
        /* Summarize some data */

        cout << "[+] ------- [+]" << endl;
        TCP* tcp_layer = sniff_packet->GetLayer<TCP>();
        cout << "[#] TCP packet from source port: " << dec << tcp_layer->GetSrcPort() << endl;

        cout << "[#] With Payload: " << endl;

                    payload = raw_payload->GetStringPayload();

        SPPM(payload); // Function present in algo.cpp
    }

 }

 void main() { // }

algo.h

#ifndef algo_H_
#define algo_H_
#include <string>
using namespace std;

void SPPM (std::string input);

#endif

algo.cpp

#include "algo.h"

#define byte uint8_t
using namespace std;
void SPPM(std::string input){  //definition }

当我使用g ++编译代码时,我收到此错误:

In function `PacketHandler(Crafter::Packet*, void*)':
/home/maleeha/libcrafter_latest/libcrafter-master/libcrafter/pcap_reader.cpp:32:     undefined reference to `SPPM(std::basic_string<char, std::char_traits<char>,  std::allocator<char> >)'collect2: ld returned 1 exit status

我正在以这种方式执行我的代码:

g++ -c  Reader.cpp -o Reader.o -g -lcrafter
g++   -c  algo.cpp -o algo.o

g++  -o program Reader.o algo.o -lcrafter

./program Packets.pcap

为什么会出现这个错误?

0 个答案:

没有答案