我刚刚重新启动了一个暂停了几个月的项目。上次我编译它它工作得很好,没有任何错误或警告。 然而,当我今天早些时候尝试编译时,我收到了这个警告
attention : ‘template<class _Operation> class std::binder2nd’ is deprecated [-Wdeprecated-declarations]
这个警告字面上出现了数百次,包括我在项目中使用的Eigen / Geometry
In file included from [...]/include/Eigen/src/Core/ArrayBase.h:109:0,
from [...]/include/Eigen/Core:350,
from [...]/include/Eigen/Geometry:4,
from [...]/include/[myproject]/types.hh:8,
from [...]/include/[myproject]/voronoi.hh:8
从那时起,我还没有更新Eigen(使用3.2.4,这仍然是今天的最后一次更新)。 但是,自从我上次编译它以来,GCC已经更新到5.1.0(我使用archlinux)
问题:
我推测std::bind2nd
确实已弃用且a commit has been done to solve that in Eigen。然而,此提交尚未与主分支合并:/(并且由于某些std::bind2nd
仍存在于Eigen的代码中,因此无法解决问题)
底线是:不推荐使用Eigen的最后一个稳定版本
答案 0 :(得分:10)
不,C ++标准说它在C ++ 11中已被弃用,所以如果你在C ++ 11模式下编译,那么它应该被弃用。
是。如果它想要兼容C ++ 17,那么在{C ++ 14之后'根本不存在Sep 29, 2015 8:07:23 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3fa77460: startup date [Tue Sep 29 08:07:23 EDT 2015]; root of context hierarchy
Sep 29, 2015 8:07:23 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Sep 29, 2015 8:07:23 AM org.springframework.context.support.ClassPathXmlApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'user' defined in class path resource [Beans.xml]: Could not resolve placeholder 'user.email' in string value "${user.email}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'user.email' in string value "${user.email}"
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:211)
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:222)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:86)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:166)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:673)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:519)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.my.MainApp.main(MainApp.java:11)
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'user.email' in string value "${user.email}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer$PlaceholderResolvingStringValueResolver.resolveStringValue(PropertyPlaceholderConfigurer.java:258)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveStringValue(BeanDefinitionVisitor.java:282)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:204)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:141)
at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:82)
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:208)
... 9 more
。
取消警告。在命令行上使用std::bind2nd
进行编译,或者在包含Eigen头时在源代码中进行编译:
-Wno-deprecated-declarations
或者,正如另一个答案所说,告诉GCC将Eigen标头视为系统标头,如果它们位于#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <eigen/whatever.h>
#pragma GCC diagnostic pop
中,则会自动发生,或者包含在/usr/include
中,或者包含在另一个标头中标题:
-isystem
答案 1 :(得分:1)
如何在不失去冗长的情况下沉默这些特定警告?
编辑CMakeLists.txt文件。在设置CMAKE_CXX_FLAGS之后的某处添加此行。
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
之前的回答提到将此添加到#pragma或命令行。我对#pragma有偏见,因为我后来发现很难记住我把它放在哪里。因此,作为一般惯例,我尽量避免使用#pragma。添加到命令行意味着每次重新编译时都必须记住输入。
答案 2 :(得分:0)
使用-isystem
来包含Eigen标题,而不是使用-I
标志来包含文件:
g++-5 -isystem/usr/include/eigen3 source_file_here.cpp
此标记适用于不符合C
标准但在生成警告时被视为误报的系统标头。 Eigen标题的使用方式与系统标题非常相似,因此对于大多数用户而言,警告没有帮助,只是一种恼人的误报。
归功于Ilya Popov在原始问题中的评论。