cpp模板编译踩坑记
今天给我的东西写了个可变长模板log类,然后编译的时候踩了大坑.😤
出现很多很多错误...
我开始的时候想将#include
放到namespace
的定义中去,然后直接炸....
出现很多类似的错误: In file included from /opt/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.3/string:52:0,
from /opt/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.3/bits/locale_classes.h:40,
from /opt/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.3/bits/ios_base.h:41,
from /opt/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.3/ios:42,
from /opt/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.3/ostream:38,
from /opt/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.3/iostream:39,
from /home/zqh/Documents/raspi_blue/utils/inc/loger.h:13,
from /home/zqh/Documents/raspi_blue/utils/src/record.cpp:2:
/opt/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.3/bits/basic_string.h: In function 'long int Loger::std::stol(const string&, Loger::std::size_t*, int)':
猜测:
我怀疑是将#include <iostream>
放在namespace
中,就会导致std
和别一些东西冲突..
出现多重定义的错误
我把定义放到外面之后编译出现 CMakeFiles/myrecord.dir/utils/src/sock.cpp.o: In function `Loger::show_list()':
sock.cpp:(.text+0x0): multiple definition of `Loger::show_list()'
CMakeFiles/myrecord.dir/utils/src/record.cpp.o:record.cpp:(.text+0x0): first defined here
CMakeFiles/myrecord.dir/xfly/src/quickasr.cpp.o: In function `Loger::show_list()':
quickasr.cpp:(.text+0x0): multiple definition of `Loger::show_list()'
CMakeFiles/myrecord.dir/utils/src/record.cpp.o:record.cpp:(.text+0x0): first defined here
CMakeFiles/myrecord.dir/usr/src/main.cpp.o: In function `Loger::show_list()':
main.cpp:(.text+0x1cc): multiple definition of `Loger::show_list()'
CMakeFiles/myrecord.dir/utils/src/record.cpp.o:record.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
CMakeFiles/myrecord.dir/build.make:172: recipe for target '../bin/myrecord' failed
make[2]: *** [../bin/myrecord] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/myrecord.dir/all' failed
make[1]: *** [CMakeFiles/myrecord.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
猜测
这个我找了半天没找到相关描述..但是我在那个函数前面加了inline
就莫名的好了
😂
最终代码:
/* |