编译
Executing task in folder good_coder-lihailin:
g++ -g src/base_convert.cpp src/conv_int.cpp src/conv_float.cpp src/conv_string.cpp demo/main.cpp -lstdc++ -o main
报错
Undefined symbols for architecture x86_64:
“DictData::DictData()”, referenced from:
_main in main-4de14f.o
“DictData::~DictData()”, referenced from:
_main in main-4de14f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
终端进程已终止,退出代码: 1
分析
没找到符号引用Undefined symbols, DictData。再看编译项里,没有dict_data.cpp,因此在编译过程中需要加上dict_data.cpp。这种错误是自身编译的时候少加了编译文件产生。
解决问题
加上dict_data.cpp编译项
g++ -g src/base_convert.cpp src/dict_data.cpp src/conv_int.cpp src/conv_float.cpp src/conv_string.cpp demo/main.cpp -lstdc++ -o main
注意如果出现Undefined symbols,又不属于自己代码里的结构,那么很大部分原因是库函数引用出错,编译项里加-lstdc++