我是将github中的tensorrt例子加到自己的工程中,下面是运行时报的错误
error: reference to ‘DataType’ is ambiguous
ICudaEngine* createEngine(unsigned int maxBatchSize, IBuilder* builder, IBuilderConfig* config, map<string, Weights>& weightMap, DataType dt);
error: ‘DataType’ has not been declared
ICudaEngine* createEngine(unsigned int maxBatchSize, IBuilder* builder, IBuilderConfig* config, map<string, Weights>& weightMap, DataType dt);
直接运行github下载好的例子是能正常运行,但是加到自己的工程就报错.
参考了【C++错误处理】no matching function for call to transform
发现因为在全局命名空间中有实现的函数(而不是宏),所以我们明确命名空间.
那么,如何明确命名空间的名字呢?
我的做法是
在能正常运行的tensorrt例子中,鼠标放在要知道其命名空间的变量上(例如由于我报错的是DataType,我就把鼠标放在DataType上),会自动显示该变量的命名空间(例如nvinfer1::DataType).
然后,在自己的工程中,将变量改为带有命名空间的变量(DataType改为nvinfer1::DataType).