文件目录结构体为: src 和include 分别用来存放.cpp文件和 .hpp文件
其中:src文件夹下有需要的文件 simulator_client.cpp crc32.cpp ; include文件夹下有对应的头文件 simulator_client.hpp、crc32.h及使用的头文件cJSON.h
使用命令编译时遇到如下问题:
g++ simulator_client.cpp -o simulator_client -lm -I../include
/tmp/ccZ5rfZQ.o: In function `packet_data(unsigned char, unsigned char, unsigned short, char*, unsigned int)':
simulator_client.cpp:(.text+0x228): undefined reference to `crc32'
simulator_client.cpp:(.text+0x27e): undefined reference to `crc32'
/tmp/ccZ5rfZQ.o: In function `create_package_json_info(package*, int)':
simulator_client.cpp:(.text+0x4e9): undefined reference to `cJSON_CreateObject'
simulator_client.cpp:(.text+0x512): undefined reference to `cJSON_CreateString'
........
collect2: error: ld returned 1 exit status
原因: 主要是C/C++编译为obj文件的时候并不需要函数的具体实现,只要有函数的原型即可。但是在链接为可执行文件的