use*_*089 5 c++ gcc compiler-optimization
我使用的是 Ubuntu 14.04 和 gcc 4.9.3。我遇到一个奇怪的问题,当我启用 O3 优化时,会弹出一些“调用不太可能,代码大小会增长 [-Werror=inline]”错误。我的代码中没有 inline 关键字。为什么 gcc 内联优化代码以至于触发它自己的警告?
\n\n显然禁用 -Winline 会编译,但是有更好的方法来解决这个问题吗?
\n\n我正在使用的库是点云库,为了完整性,代码如下所示。
\n\n我的 CMakeLists
\n\ncmake_minimum_required(VERSION 2.8)\nproject(Test)\n\nset(PROJECT_SRCS\n${PROJECT_SOURCE_DIR}/Test.cpp\n)\n\nset(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Werror -Winline")\n\n# causes error\nset(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")\n\nfind_package( PCL 1.7 REQUIRED )\n\ninclude_directories(${PCL_INCLUDE_DIRS})\n\nadd_executable(${PROJECT_NAME} ${PROJECT_SRCS})\n\ntarget_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES})\nRun Code Online (Sandbox Code Playgroud)\n\n测试.cpp
\n\n#include <string>\n#include <vector>\n\n#include "pcl/common/common_headers.h"\n#include "pcl/io/obj_io.h"\n#include "pcl/io/ply_io.h"\n#include "pcl/io/vtk_lib_io.h"\n#include "pcl/visualization/pcl_visualizer.h"\n\nint main(){\n pcl::TextureMesh mesh;\n pcl::PointCloud<pcl::PointNormal> xyz;\n\n pcl::PointNormal point1;\n pcl::PointNormal point2;\n pcl::PointNormal point3;\n point1.x = 0;\n point2.x = 1;\n point3.x = 0;\n point1.y = 0;\n point2.y = 0;\n point3.y = 1;\n point1.z = 2;\n point2.z = 2;\n point3.z = 2;\n xyz.push_back(point1);\n xyz.push_back(point2);\n xyz.push_back(point3);\n pcl::toPCLPointCloud2(xyz, mesh.cloud);\n\n std::vector<pcl::Vertices> mesh_poly;\n std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > mesh_tex;\n pcl::TexMaterial mesh_material;\n\n pcl::Vertices v;\n v.vertices.push_back(0);\n v.vertices.push_back(1);\n v.vertices.push_back(2);\n mesh_poly.push_back(v);\n\n Eigen::Vector2f tex1;\n Eigen::Vector2f tex2;\n Eigen::Vector2f tex3;\n tex1(0) = -1.0;\n tex1(1) = 0.0;\n tex2(0) = -1.0;\n tex2(1) = 1.0;\n tex3(0) = 2.0;\n tex3(1) = 0.0;\n\n mesh_tex.push_back(tex1);\n mesh_tex.push_back(tex2);\n mesh_tex.push_back(tex3);\n\n mesh_material.tex_file = "lena.png";\n mesh_material.tex_name = "material_0";\n\n mesh.tex_polygons.push_back(mesh_poly);\n mesh.tex_coordinates.push_back(mesh_tex);\n mesh.tex_materials.push_back(mesh_material);\n\n pcl::io::saveOBJFile("out.obj", mesh);\n\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n编辑:更新错误消息
\n\nIn file included from /usr/local/include/pcl-1.8/pcl/io/obj_io.h:40:0,\n from /home/david/test/Test.cpp:5:\n/usr/local/include/pcl-1.8/pcl/TextureMesh.h: In function \xe2\x80\x98int main()\xe2\x80\x99:\n/usr/local/include/pcl-1.8/pcl/TextureMesh.h:50:10: error: inlining failed in call to \xe2\x80\x98pcl::TexMaterial::~TexMaterial()\xe2\x80\x99: call is unlikely and code size would grow [-Werror=inline]\n struct TexMaterial\n ^\n/home/david/test/Test.cpp:37:20: error: called from here [-Werror=inline]\n pcl::TexMaterial mesh_material;\n ^\nIn file included from /usr/local/include/pcl-1.8/pcl/io/obj_io.h:40:0,\n from /home/david/test/Test.cpp:5:\n/usr/local/include/pcl-1.8/pcl/TextureMesh.h:91:10: error: inlining failed in call to \xe2\x80\x98pcl::TextureMesh::~TextureMesh()\xe2\x80\x99: call is unlikely and code size would grow [-Werror=inline]\n struct TextureMesh\n ^\n/home/david/test/Test.cpp:14:20: error: called from here [-Werror=inline]\n pcl::TextureMesh mesh;\n ^\nIn file included from /usr/local/include/pcl-1.8/pcl/io/obj_io.h:40:0,\n from /home/david/test/Test.cpp:5:\n/usr/local/include/pcl-1.8/pcl/TextureMesh.h:50:10: error: inlining failed in call to \xe2\x80\x98pcl::TexMaterial::~TexMaterial()\xe2\x80\x99: call is unlikely and code size would grow [-Werror=inline]\n struct TexMaterial\n ^\n/home/david/test/Test.cpp:37:20: error: called from here [-Werror=inline]\n pcl::TexMaterial mesh_material;\n ^\nIn file included from /usr/local/include/pcl-1.8/pcl/io/obj_io.h:40:0,\n from /home/david/test/Test.cpp:5:\n/usr/local/include/pcl-1.8/pcl/TextureMesh.h:91:10: error: inlining failed in call to \xe2\x80\x98pcl::TextureMesh::~TextureMesh()\xe2\x80\x99: call is unlikely and code size would grow [-Werror=inline]\n struct TextureMesh\n ^\n/home/david/test/Test.cpp:14:20: error: called from here [-Werror=inline]\n pcl::TextureMesh mesh;\n ^\ncc1plus: all warnings being treated as errors\nmake[2]: *** [CMakeFiles/Test.dir/Test.cpp.o] Error 1\nmake[1]: *** [CMakeFiles/Test.dir/all] Error 2\nmake: *** [all] Error 2\nRun Code Online (Sandbox Code Playgroud)\n
类/结构的使用可能具有内联成员,即使代码中没有明确指出。
例如,pcl::TextureMesh结构体将有一个隐式析构函数,根据 C++ 标准:
隐式声明的析构函数是其类的内联公共成员。
| 归档时间: |
|
| 查看次数: |
2893 次 |
| 最近记录: |